Distance between numbers
Let the numbers (a) and (b) be expressed in the decimal numeral system. The distance between them is defined as:
[ (a_1 - b_1)^2 + (a_2 - b_2)^2 + (a_3 - b_3)^2 + ...]
where (a_i) represents the (i)-th digit of the number (a), and (b_i) represents the (i)-th digit of the number (b). The digits are numbered starting from the least significant digit, which is indexed as number (1). If (i) exceeds the length of the number, the (i)-th digit is considered to be zero.
Write a program that, given three non-negative integers (A), (B), and (C), finds numbers (X) and (Y) such that the following conditions are satisfied:
(A X B) and (A Y B)
(X) is the smallest number for which the distance to (C) is minimized.
(Y) is the largest number for which the distance to (C) is maximized.
Input
The input consists of three lines, each containing one integer: (A), (B), and (C) respectively ((0 A B 10^18), (0 C 10^18)).
Output
Output two lines, each containing one integer: the first line should contain (X) and the second line should contain (Y).