#P6723. Digit Sum Range Search

    ID: 19931 Type: Default 1000ms 256MiB

Digit Sum Range Search

Given three integers \(L\), \(D\), and \(X\), you need to find two integers \(N\) and \(M\) such that:

  • \(N\) is the smallest integer in the range \([L, D]\) whose digits sum up to \(X\).
  • \(M\) is the largest integer in the range \([L, D]\) whose digits sum up to \(X\).

It is guaranteed that such \(N\) and \(M\) exist.

inputFormat

A single line containing three space-separated integers (L), (D), and (X).

outputFormat

Output two lines: the first line should contain (N), and the second line should contain (M).

sample

100 500 7
106

430

</p>