A2363 「ROIR 2021 Day 2」好数

暂无评定 传统题 ROIR(俄罗斯) 上传者
时间限制1000ms
内存限制512MiB
通过 / 提交0/0

A2363「ROIR 2021 Day 2」好数

暂无评定 传统题 ROIR(俄罗斯) 上传者
时间限制1000ms
内存限制512MiB
通过 / 提交0/0

Description

Translated from Chinese version of ROIR 2021 Day2 T2 Числа on this website.

We call those numbers satisfying that numbers on all digits are the same as Beautiful Numbers of type 11.

Additionally, we define Beautiful Numbers of type 22 as those satisfying any of the following conditions:

  • Is a beautiful number of type I.
  • Assume this is a number with tt digits and no prefix zeros, then the numbers on t−1t-1 digits are the same.

Now you are given a value xx and your task is to find the first Beautiful Number of type k+1k+1 which satisfies ≥x\geq x.

Input Format

The first line consists of a single integer xx.

The next line consists of a single integer kk.

Output Format

Output a single integer representing your answer.

700
0
777
700
1
700

Constraints

For all test data, it is guaranteed that 1≤x≤10171\le x\le 10^{17},k∈{0,1}k\in\{0,1\}。

Subtask # Additional Constraints Score
11 1≤x≤1051\le x\le 10^5,k=0k=0 1515
22 k=0k=0 2020
33 1≤x≤1051\le x\le 10^5 2121
44 No Additional Constraints 4444