P9766 [ROIR 2021] Good Numbers (Day 2)

Background

**Translated from [ROIR 2021](http://neerc.ifmo.ru/school/archive/2020-2021.html) Day 2 T2 [Числа](http://neerc.ifmo.ru/school/archive/2020-2021/ru-olymp-regional-2021-day2.pdf)**。

Description

A type 1 good number is a number in which all digits are the same. A type 2 good number is a number that satisfies any one of the following conditions: - It is a type 1 good number. - Let $t$ be the number of digits of the number. Then the digits are the same on $t-1$ positions, and there are no leading zeros. Now given an $x$, find the first type $k+1$ good number $y$ such that $y \ge x$。

Input Format

The first line contains an integer $x$。 The second line contains an integer $k$。

Output Format

Output one integer $y$ in one line。

Explanation/Hint

For all subtasks, $1 \le x \le 10^{17}$, $k \in \{0,1\}$。 ## Constraints | Subtask ID | Special Constraints | Points | | :--------: | :-----------------: | :----: | | $1$ | $1 \le x \le 10^5$, $k=0$ | $15$ | | $2$ | $k=0$ | $20$ | | $3$ | $1 \le x \le 10^5$ | $21$ | | $4$ | No special constraints | $44$ | Translated by ChatGPT 5