Problem list
Log in
#coci00386 · COCI 2015/2016 Contest 5

Zamka

Bronze III 1.0 s 64 MB

The impossible has happened. Bear G. has fallen into his own trap. Lured by a delicious box of Domaćica, without even thinking, he rushed and fell into his trap. In order to get out of the trap, he must solve the following task with your help. You are given three integers $L$, $D$ i $X$.

  • determine the minimal integer $N$ such that $L$ ⩽$N$ ⩽$D$ and the sum of its digits is $X$
  • determine the maximal integer $M$ such that $L$ ⩽$M$ ⩽$D$ and the sum of its digits is $X$ Bear will be able to escape from the trap if he correctly determines numbers $N$ and $M$. The numbers $N$ and $M$ will always exist.

Input

The first line of input contains the integer $L$ (1 ⩽$L$ ⩽10 000), the number from the task. The second line of input contains the integer $D$ (1 ⩽$D$ ⩽10 000, L ⩽$D$), the number from the task. The third line of input contains the integer $X$ (1 ⩽$X$ ⩽36), the number from the task.

Output

The first line of output must contain the integer $N$ from the task. The second line of output must contain the integer $M$ from the task.

Example 1

Input
1
100
4
100
500
12
1
10000
1
Output
output
output
4
40
129
480
1
10000
Source
COCI 2015/2016 Contest 5
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code