#P6723. [COCI 2015/2016 #5] ZAMKA

[COCI 2015/2016 #5] ZAMKA

Description

Given three integers L,D,XL, D, X, you need to find two integers N,MN, M such that:

  • NN is the smallest integer that satisfies LNDL \le N \le D and the sum of the digits of NN is XX.
  • MM is the largest integer that satisfies LMDL \le M \le D and the sum of the digits of MM is XX.

It is guaranteed that NN and MM exist.

Input Format

The input has three lines.

The first line contains an integer LL, the second line contains an integer DD, and the third line contains an integer XX.

Output Format

Output two lines.

The first line contains an integer NN, and the second line contains an integer MM.

1
100
4
4
40
100
500
12
129
480
1
10000
1
1
10000

Hint

Constraints

For 100%100\% of the testdata, 1LD1041 \le L \le D \le 10^4, 1X361 \le X \le 36.

Notes

This problem is translated from COCI2015-2016 CONTEST #5 T1 ZAMKA

Translated by ChatGPT 5