atcoder#ARC130C. [ARC130C] Digit Sum Minimization

[ARC130C] Digit Sum Minimization

Score : 500500 points

Problem Statement

Given are positive integers a,ba, b, where none of the digits is 00.

Permute the digits of each of aa and bb so that the sum of the digits in a+ba+b is minimized.

Constraints

  • 1a,b<101000001\leq a, b< 10^{100000}
  • None of the digits of aa and bb is 00.

Input

Input is given from Standard Input in the following format:

aa

bb

Output

After permuting the digits of each of aa and bb so that the sum of the digits in a+ba+b is minimized, print aa in the first line and bb in the second line.

If multiple solutions exist, printing any of them will be accepted.

253
286
532
268

We have 532+268=800532 + 268 = 800, whole digits sum to 8+0+0=88+0+0=8.

Other solutions will also be accepted, such as (a,b)=(325,682)(a, b) = (325, 682).

345
556
435
565

We have 435+565=1000435+565=1000, whole digits sum to 1+0+0+0=11+0+0+0=1.

123
987987
312
799788

We have 312+799788=800100312 + 799788 = 800100, whole digits sum to 8+0+0+1+0+0=98+0+0+1+0+0=9.

11111111111111111111
111111111111111111111111111111
11111111111111111111
111111111111111111111111111111