C - Digit Sum Minimization Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

正の整数 a, b が与えられます。ただし、a, b のどの桁も 0 ではありません。

a+b の各桁の和が最小になるように、a, b のそれぞれの桁を並べ替えてください。

制約

  • 1\leq a, b< 10^{100000}
  • a, b のどの桁も 0 ではない

入力

入力は以下の形式で標準入力から与えられます。

a
b

出力

a+b の各桁の和が最小になるように a, b のそれぞれの桁を並べ替えて、1 行目に a を、2 行目に b を出力してください。

答が複数考えられる場合には、そのどれを出力しても正解となります。


入力例 1

253
286

出力例 1

532
268

532 + 268 = 800 で、その各桁の和は 8+0+0=8 となります。

他にも、(a, b) = (325, 682) を出力しても正解となります。


入力例 2

345
556

出力例 2

435
565

435+565=1000 で、その各桁の和は 1+0+0+0=1 となります。


入力例 3

123
987987

出力例 3

312
799788

312 + 799788 = 800100 で、その各桁の和は 8+0+0+1+0+0=9 となります。


入力例 4

11111111111111111111
111111111111111111111111111111

出力例 4

11111111111111111111
111111111111111111111111111111

Score : 500 points

Problem Statement

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

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

Constraints

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

Input

Input is given from Standard Input in the following format:

a
b

Output

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

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


Sample Input 1

253
286

Sample Output 1

532
268

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

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


Sample Input 2

345
556

Sample Output 2

435
565

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


Sample Input 3

123
987987

Sample Output 3

312
799788

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


Sample Input 4

11111111111111111111
111111111111111111111111111111

Sample Output 4

11111111111111111111
111111111111111111111111111111