Andrey's favourite number is n. Andrey's friends gave him two identical numbers n as a New Year present. He hung them on a wall and watched them adoringly.Then Andrey got bored from looking at the same number and he started to swap digits first in one, then in the other number, then again in the first number and so on (arbitrary number of changes could be made in each number). At some point it turned out that if we sum the resulting numbers, then the number of zeroes with which the sum will end would be maximum among the possible variants of digit permutations in those numbers.Given number n, can you find the two digit permutations that have this property?

The first line contains a positive integer n — the original number. The number of digits in this number does not exceed 105. The number is written without any leading zeroes.

Print two permutations of digits of number n, such that the sum of these numbers ends with the maximum number of zeroes. The permutations can have leading zeroes (if they are present, they all should be printed). The permutations do not have to be different. If there are several answers, print any of them.

program task4;

{$APPTYPE CONSOLE}

uses
  SysUtils, Math;
type dd=array [0..9] of longint;
var
A,A1,A2:dd;
B1,B2:array [1..100010] of longint;
s:string;
i,c,k1,k2,j,k,x,y,z,q,p00:longint;

procedure print;
var
i:longint;
begin
for i:=k1 downto 1 do
 begin
  write(B1[i]);
 end;
 for i:=1 to p00 do write(0);
 writeln;
for i:=k2 downto 1 do
 begin
  write(b2[i]);
 end;
 for i:=1 to p00 do write(0);
writeln;
end;

function kp:longint;
var
i:longint;
begin
result:=0;
for i:=0 to 9 do
 begin
  inc(result,min(A1[i],A2[9-i]));
 end;
end;

begin          {
assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);}
readln(s);
for i:=0 to 9 do
 begin
  A[i]:=0;
 end;
for i:=1 to length(s) do
 begin
  c:=ord(s[i])-48;
  inc(A[c]);
 end;
k:=0;
{while A[0]>0 do
 begin
  dec(A[0]);
  inc(k);
  B1[k]:=0;
  B2[k]:=0;
 end; }
A1:=A;
A2:=A;
z:=-1;
x:=-1;
y:=-1;
if (A[1]>0) and (A[9]>0) then
 begin
  dec(A1[1]);
  dec(A2[9]);
  q:=kp;
  inc(A1[1]);
  inc(A2[9]);
  if q>z then
   begin
    z:=q;
    x:=1;
    y:=9;
   end;
 end;
if (A[2]>0) and (A[8]>0) then
 begin
  dec(A1[2]);
  dec(A2[8]);
  q:=kp;
  inc(A1[2]);
  inc(A2[8]);
    if q>z then
   begin
    z:=q;
    x:=2;
    y:=8;
   end;
 end ;
if (A[3]>0) and (A[7]>0) then
 begin
  dec(A1[3]);
  dec(A2[7]);
  q:=kp;
  inc(A1[3]);
  inc(A2[7]);
    if q>z then
   begin
    z:=q;
    x:=3;
    y:=7;
   end;
 end;
if (A[4]>0) and (A[6]>0) then
 begin
  dec(A1[4]);
  dec(A2[6]);
  q:=kp;
  inc(A1[4]);
  inc(A2[6]);
    if q>z then
   begin
    z:=q;
    x:=4;
    y:=6;
   end;
 end ;
if (A[5]>0) and (A[5]>0) then
 begin
  dec(A1[5]);
  dec(A2[5]);
  q:=kp;
  inc(A1[5]);
  inc(A2[5]);
    if q>z then
   begin
    z:=q;
    x:=5;
    y:=5;
   end;
 end;
if x<>-1 then
 begin
  inc(k);
  dec(A1[x]);
  dec(A2[y]);
  B1[k]:=x;
  B2[k]:=y;
 end;
for i:=0 to 9 do
 begin
  while (A1[i]>0) and (A2[9-i]>0) do
   begin
    dec(A1[i]);
    dec(A2[9-i]);
    inc(k);
    B1[k]:=i;
    B2[k]:=9-i;
   end;
 end;
 k1:=k;
 k2:=k;
 p00:=0;
while (A1[0]>0) and (A2[0]>0) do
 begin
  inc(p00);
  dec(A1[0]);
  dec(A2[0]);
 end;
for i:=0 to 9 do
 begin
   for j:=1 to A1[i] do
    begin
     inc(k1);
     B1[k1]:=i;
    end;
      for j:=1 to A2[i] do
    begin
     inc(k2);
     B2[k2]:=i;
    end;
 end;
print;

  { TODO -oUser -cConsole Main : Insert code here }
end.

program pr1;

{$APPTYPE CONSOLE}

const eps=0.000000001; nnn=200000;
label 1,2,3;
type  int64=longint;
mas=array[0..20000] of longint; mmas=^mas;
var maxkol,s,kk,kp,num,mmax,n1,h,t,imin,mmin,p,step,jmax,n,k,pmax:longint;
  flag,flag1:boolean;   pl,mm,aaa,kolraz,otmax,ot,m,j2:int64;
  i,j:longint;   ch:char;
   ss:string;
pp,ppp :mas;
 ugol,vp,sot,vr,vb:double;
a,b,c,ot1,ot2:array[-10..500000] of longint;
opt,aa:array[0..1000,0..1000] of longint;
 new1,new2, ss1,ss2:string;
 otv:array[-10..800,-10..800] of int64 ;
 l,r,spost:array [0..1000] of longint;
  function min(a,b:int64):int64;
begin min:=a;if b<a then min:=b; end;

  function min1(a,b:int64):int64;
begin min1:=a;if b<a then min1:=b; if (a<0)or (b<0) then min1:=0; end;

function max(a,b:int64):int64;
begin max:=a;if b>a then max:=b; end;

{  function per(num:longint): mmas; var i,j:longint;
  pp,ppp:array[0..10] of longint;
begin  dec(num);
  for i:=1 to n-1 do begin pp[i]:=num div fac[n-i]; num:=num mod fac[n-i];end;
  for i:=1 to n do write(pp[i],' ');   writeln;

end; }
 function prr(p:longint):boolean; var i,j:longint; flag:boolean;
  begin
    flag:=true;
     for i:=2 to trunc(sqrt(p)+eps) do if p mod i=0 then flag:=false;
   prr:=flag;  if (p=1)or(p=0) then prr:=false;
  end;

 begin {assign(input,'input.txt');reset(input);
assign(output,'output.txt');rewrite(output);
    }
while not eof do begin  read(ch); inc(a[ord(ch)-48]);      end;

{for i:=0 to 9 do write(a[i],' ');  writeln; }
for i:=0 to 10 do begin b[i]:=a[i]; c[i]:=a[i];   end;
for i:=0 to 9 do n:=n+a[i];
 for p:=0 to c[0] do {p - kol 0 na konze}
  begin  for i:=0 to 9 do  begin a[i]:=c[i];b[i]:=c[i];  end;
       a[0]:=c[0]-p; b[0]:=c[0]-p;
      for j:=1 to 9 do {j - poslednyaya zifra pered 0 }
        if (a[j]>0)and(b[10-j]>0) then

        begin
            for i:=0 to 9 do  begin a[i]:=c[i];b[i]:=c[i];  end;
            a[0]:=c[0]-p; b[0]:=c[0]-p;
            dec(a[j]); dec(b[10-j]);
            t:=p+1;
            {writeln;writeln;
            for i:=0 to 9 do write(a[i],' '); writeln;
            for i:=0 to 9 do write(b[i],' '); writeln;  }
            for i:=0 to 9 do t:=t+min(a[i],b[9-i]);
            {writeln(p,'  nuley ',j,'+',10-j,' and ',t-p-1,'  devyatok');  }
            if t>maxkol then begin maxkol:=t; jmax:=j;pmax:=p; end;
        end;

  end;

{ writeln(maxkol,' ',jmax,' ',pmax); writeln;
}
if maxkol>0 then
  begin
     for i:=0 to 9 do begin  a[i]:=c[i];b[i]:=c[i];       end;
         a[0]:=a[0]-pmax;b[0]:=b[0]-pmax;
         for i:=1 to pmax do begin ot1[i]:=0;ot2[i]:=0; end;
         ot1[pmax+1]:=jmax; ot2[pmax+1]:=10-jmax;
         dec(a[jmax]);dec(b[10-jmax]); pl:=pmax+1;

            begin
                for j:=0 to 9 do for i:=1 to min(a[j],b[9-j]) do
                   begin inc(pl);ot1[pl]:=j;ot2[pl]:=9-j;     end;
            end;
             for j:=0 to 9 do
               for i:=1 to a[j]-min(a[j],b[9-j]) do
               begin inc(pl); ot1[pl]:=j; end; pl:=maxkol;
              for j:=0 to 9 do
                for i:=1 to b[9-j]-min(a[j],b[9-j]) do
               begin inc(pl); ot2[pl]:=9-j; end;
      for i:=n downto 1 do write(ot1[i],''); writeln;
      for i:=n downto 1 do write(ot2[i],''); writeln;
  end else
     begin for i:=9 downto 0 do for j:=1 to c[i] do write(i); writeln;
       for i:=9 downto 0 do for j:=1 to c[i] do write(i); writeln;
     end;

     1: close (output);
end.

var mn,q,i,l,k,m,j,h:longint;
    a,b:array[0..9] of longint;
    s,c:string;
function posh:longint;
var w,i:longint;
begin
w:=0;
for i:=0 to 9 do
begin
k:=b[i];
if k>a[9-i] then k:=a[9-i];
w:=w+k;
end;
k:=b[9];
if k>a[0] then k:=a[0];
w:=w+k;
posh:=w;
end;
begin
readln(s);
for i:=1 to length(s) do
inc(a[ord(s[i])-48]);
for i:=0 to 9 do b[i]:=a[i];

for i:=1 to 5 do
if (a[i]>0) and (b[10-i]>0) then
begin
dec(a[i]);
dec(b[10-i]);
m:=posh+1;
if m>mn then
begin
mn:=m;
q:=i;
end;
inc(a[i],1);
inc(b[10-i],1);
end;

if q=0 then
begin
for i:=1 to 9 do
for l:=1 to a[i] do write(i);
for l:=1 to a[0] do write(0);
writeln;
for i:=1 to 9 do
for l:=1 to b[i] do write(i);
for l:=1 to b[0] do write(0);
writeln;
end else
begin
dec(mn);
dec(a[q]);
dec(b[10-q]);
s:='';
c:='';

for i:=0 to 9 do
begin
k:=b[i];
if k>a[9-i] then k:=a[9-i];
for l:=1 to k do
begin
s:=s+chr(i+48);
dec(b[i]);
dec(a[9-i]);
c:=c+chr(9-i+48);
end;
end;
k:=b[9];
if k>a[0] then k:=a[0];
for l:=1 to k do
begin
s:=s+chr(9+48);
dec(b[9]);
dec(a[0]);
c:=c+chr(48);
end;
for i:=1 to a[0]-b[0] do begin dec(a[0]); c:='0'+c; end;
for i:=1 to b[0]-a[0] do begin dec(b[0]); s:='0'+s; end;
c:=c+chr(q+48);
s:=s+chr(10-q+48);
for i:=1 to 9 do
for l:=1 to b[i] do write(i);
write(s);
for l:=1 to b[0] do write(0);
writeln;
for i:=1 to 9 do
for l:=1 to a[i] do write(i);
write(c);
for l:=1 to a[0] do write(0);
writeln;
end;
end.

program D;

{$APPTYPE CONSOLE}
uses Math, SysUtils;
var s,s1,s2: string;
    a,b,cnt: array[0..9]of integer;
    i,j,n,ta: integer;

procedure check(x,y: integer);
var tt,i,j: integer;
    aa,bb: array[0..9]of integer;
begin
  if (a[x]<1)or(b[y]<1)then exit;
  for i:=0 to 9 do begin
    aa[i]:=a[i];
    bb[i]:=b[i];
  end;
  tt:=1;
  dec(aa[x]);dec(bb[y]);
  for i:=0 to 9 do begin
    j:=min(aa[i],bb[9-i]);
    inc(tt,j);
    dec(aa[i],j);dec(bb[9-i],j);
  end;
  j:=min(aa[0],bb[0]);
  inc(tt,j);
  if (tt>ta)then begin
    s1:=inttostr(x);
    s2:=inttostr(y);
    ta:=tt;
  end;
end;
begin
  s1:='';s2:='';
  readln(s);
  n:=length(s);
  for i:=0 to 9 do begin
    a[i]:=0;
    b[i]:=0;
  end;
  for i:=1 to n do begin
    inc(a[ord(s[i])-ord('0')]);
    inc(b[ord(s[i])-ord('0')]);
  end;
  ta:=0;
  check(2,8);
  check(3,7);
  check(4,6);
  check(5,5);
  check(9,1);
  if (s1<>'')then begin
    dec(a[ord(s1[1])-ord('0')]);
    dec(b[ord(s2[1])-ord('0')]);
  end;
  for i:=0 to 9 do begin
    cnt[i]:=min(a[i],b[9-i]);
    a[i]:=a[i]-cnt[i];
    b[9-i]:=b[9-i]-cnt[i];
  end;
  ta:=min(a[0],b[0]);
  a[0]:=a[0]-ta;b[0]:=b[0]-ta;
  for i:=0 to 9 do
    for j:=1 to a[i]do
      write(i);
  for i:=0 to 9 do
    for j:=1 to cnt[i]do
      write(i);
  write(s1);
  for i:=1 to ta do write(0);
  writeln;
  for i:=0 to 9 do
    for j:=1 to b[i]do
      write(i);
  for i:=9 downto 0 do
    for j:=1 to cnt[9-i]do
      write(i);
  write(s2);
  for i:=1 to ta do write(0);
end.

{$APPTYPE CONSOLE}
{$R+,S+,Q+,I+,M+,C+,H+,O-}
{R-,S-,Q-,I-,M-,C-,H-,O+}

uses
    SysUtils, Math;

var
    i, ls, mx, l, r, cur, x, y, kk, j, zz : longint;
    a, b, c : array[0..10] of longint;
    p, q : array[0..100010] of longint;
    s : string;

function count(x, y : longint) : longint;

var
    i : longint;

begin
    dec(b[x]);
    dec(c[y]);
    result := 0;
    for i := 0 to 9 do
        inc(result, min(b[i], c[9 - i]));
    inc(b[x]);
    inc(c[y]);
end;

begin
{$IFNDEF ONLINE_JUDGE}
    reset(input, 'input.txt');
    rewrite(output, 'output.txt');
{$ENDIF}
    readln(s);
    fillchar(a, sizeof(a), 0);
    ls := length(s);
    for i := 1 to ls do
        inc(a[ord(s[i]) - 48]);
    b := a;
    c := a;
    l := -1;
    r := -1;
    mx := -1;
    for i := 1 to 5 do
        if (a[i] > 0) and (a[10 - i] > 0) then begin
            cur := count(i, 10 - i);
            if cur > mx then begin
                mx := cur;
                l := i;
                r := 10 - i;
            end;
        end;
    x := 1;
    if l > -1 then begin
        dec(b[l]);
        dec(c[r]);
        p[x] := l;
        q[x] := r;
        inc(x);
    end;
    for i := 0 to 9 do begin
        kk := min(b[i], c[9 - i]);
        for j := 1 to kk do begin
            p[x] := i;
            q[x] := 9 - i;
            inc(x);
        end;
        dec(b[i], kk);
        dec(c[9 - i], kk);
    end;
    zz := min(b[0], c[0]);
    y := x;
    for i := 1 to 9 do begin
        for j := 1 to b[i] do begin
            p[x] := i;
            inc(x);
        end;
        for j := 1 to c[i] do begin
            q[y] := i;
            inc(y);
        end;
    end;
    for i := ls - zz downto 1 do
        write(p[i]);
    for i := 1 to zz do
        write(0);
    writeln;
    for i := ls - zz downto 1 do
        write(q[i]);
    for i := 1 to zz do
        write(0);
end.

    const   MAX_N = 100010;

    var fi,fo:text;
        s,t:ansiString;
        n,i,j,rp,rf,r0:longint;
        c,c2:array[0..9] of longint;

    function    min(x,y:longint):longint;   begin   if x < y then exit(x)   else exit(y);   end;

    procedure   update(x,y:longint);
    begin
        s:=chr(x+ord('0'))+s;   dec(c[x]);
        t:=chr(y+ord('0'))+t;   dec(c2[y]);
    end;

    procedure   solve(x,y,z:longint);
    var i,f:longint;
    begin
        if (c[x] < 1) or (c2[y] < 1) then exit;
        dec(c[x]);  dec(c2[y]);
        dec(c[0],z);    dec(c2[0],z);
        f:=z;
        for i:=0 to 9 do f:=f+min(c[i],c2[9-i]);
        f:=f+min(c[0]-min(c[0],c2[9]),c2[0]-min(c2[0],c[9]));
        if f > rf then begin
            rf:=f;
            rp:=x;
            r0:=z;
        end;
        inc(c[0],z);    inc(c2[0],z);
        inc(c[x]);  inc(c2[y]);
    end;

    begin
        assign(fi,'');   reset(fi);
        assign(fo,'');  rewrite(fo);
        readln(fi,s);
        n:=length(s);
        for i:=0 to 9 do c[i]:=0;
        for i:=1 to n do inc(c[ord(s[i])-ord('0')]);
        c2:=c;
        rf:=0; rp:=-1; r0:=0;
        for j:=0 to c[0] do
            for i:=1 to 5 do
                solve(i,10-i,j);
        s:='';  t:='';
        for i:=1 to r0 do update(0,0);
        if rp > 0 then begin
            update(rp,10-rp);
            for i:=0 to 9 do
                while (c[i] > 0) and (c2[9-i] > 0) do update(i,9-i);
        end;
        while (c[0] > 0) and (c2[0] > 0) do begin
            s:=s+'0'; dec(c[0]);
            t:=t+'0'; dec(c2[0]);
        end;
        for i:=1 to 9 do
            while (c[i] > 0) and (c2[10-i] > 0) do update(i,10-i);
        for i:=0 to 9 do begin
            while c[i] > 0 do begin s:=chr(i+ord('0'))+s;   dec(c[i]);  end;
            while c2[i] > 0 do begin t:=chr(i+ord('0'))+t;   dec(c2[i]);  end;
        end;
        writeln(fo,s);
        writeln(fo,t);
        close(fo);
        close(fi);
    end.

program fda;
type
        arr=array[0..10] of longint;
var
        s:ansistring;
        i,j,k,e,t,n,m:longint;
        a:arr;
        b:arr;
        ans:arr;//ans:array[0..10] of longint;
        ans1,ans2:longint;
        s1,s2,ss:ansistring;
function min(x,y:longint):longint;
begin
        if x<y then exit(x) else exit(y);
end;
procedure work(a,b:arr);
var
        c:arr;//array[0..10] of longint;
        i,j,k:longint;
begin
        k:=0;
        for i:=0 to 9 do begin
                j:=min(a[i],b[9-i]);
                c[i]:=j;
                k:=k+c[i];
                a[i]:=a[i]-j;
                b[9-i]:=b[9-i]-j;
        end;
        j:=min(a[0],b[0]);
        c[10]:=j;
        k:=k+j;
        if k>ans1 then begin
                ans1:=k;
                ans:=c;
                ans2:=m;
        end;
end;
begin
        readln(s);
        for i:=1 to length(s) do begin
                val(s[i],j);
                inc(a[j]);
                inc(b[j]);
        end;
        ans[10]:=min(a[0],b[0])-1;
        ans1:=ans[10]-1;
        ans2:=0;
        for i:=1 to 9 do begin
                if (a[i]>0) and (b[10-i]>0) then begin
                        dec(a[i]);
                        dec(b[10-i]);
                        m:=i;
                        work(a,b);
                        inc(a[i]);
                        inc(b[10-i]);
                end;
        end;
        s1:='';s2:='';
        if a[ans2]<>0 then begin
                str(ans2,s1);
                str((10-ans2) mod 10,s2);
                dec(a[ans2]);
                dec(b[(10-ans2) mod 10]);
        end;
        for i:=1 to ans[10] do begin
                s1:=s1+'0';
                s2:=s2+'0';
                dec(a[0]);
                dec(b[0]);
        end;
        for i:=9 downto 0 do begin
                for j:=1 to ans[i] do begin
                        str(i,ss);s1:=ss+s1;
                        str(9-i,ss);s2:=ss+s2;
                        dec(a[i]);
                        dec(b[9-i]);
                end;
        end;
        for i:=0 to 9 do begin
                for j:=1 to a[i] do begin
                        str(i,ss);s1:=ss+s1;
                end;
                for j:=1 to b[i] do begin
                        str(i,ss);s2:=ss+s2;
                end;
        end;
        writeln(s1);
        writeln(s2);
end.

program digits_permut;

uses math;
const
  fi='';
  fo='';
  tt = ord('0');
  oo = trunc(1e9);
type
  stri = ansistring;
var
  n:stri;
  a1,a2,b1,b2:array[0..9] of longint;
  s1,s2:stri;
procedure openfile;
var
  i:longint;
begin
  assign(input,fi);reset(input);
  assign(output,fo);rewrite(output);
  readln(n);
  fillchar(a1,sizeof(a1),0);
  for i:=1 to length(n) do
    begin
      inc(a1[ord(n[i])-tt]);
    end;
  a2:=a1;
end;
//-------------------
procedure process;
var
  i,j:longint;
  s,p:longint;
  kq,jm:longint;
begin
  kq:=-oo;
  for i:=1 to 9 do
  if (a1[i]>0)and(a2[10-i]>0) then
    begin
      b1:=a1;
      b2:=a2;
      s:=1;
      dec(b1[i]);dec(b2[10-i]);
      for j:=0 to 9 do
        begin
          p:=min(b1[j],b2[9-j]);
          dec(b1[j],p);dec(b2[9-j],p);
          s:=s+p;
        end;
      inc(s,min(b1[0],b2[0]));
      if s>kq then
        begin
          kq:=s;
          jm:=i;
        end;
    end;
  if kq=-oo then
    begin
      s1:='';
      for i:=9 downto 0 do
        for j:=1 to a1[i] do s1:=s1+chr(i+tt);
      writeln(s1);
      writeln(s1);
      exit;
    end;
  s1:='';s2:='';
  dec(a1[jm]);
  dec(a2[10-jm]);
  for i:=1 to 1 do
    begin
      s1:=chr(jm+tt)+s1;
      s2:=chr(10-jm+tt)+s2;
    end;
  for i:=0 to 9 do
    begin
      p:=min(a1[i],a2[9-i]);
      dec(a1[i],p);dec(a2[9-i],p);
      for j:=1 to p do
        begin
          s1:=chr(i+tt)+s1;
          s2:=chr(9-i+tt)+s2;
        end;
    end;
  p:=min(a1[0],a2[0]);
  dec(a1[0],p);dec(a2[0],p);
    for i:=1 to p do
      begin
        s1:=s1+'0';
        s2:=s2+'0';
      end;
  for i:=0 to 9 do
    begin
      if a1[i]>0 then
        for j:=1 to a1[i] do s1:=chr(i+tt)+s1;
      if a2[i]>0 then
        for j:=1 to a2[i] do s2:=chr(i+tt)+s2;
    end;
  writeln(s1);
  writeln(s2);
end;
//--------------------
BEGIN
  openfile;
  process;
END.

uses math;
var
        i,n,count,j,t,res,ires,mres,tmp: longint;
        s: ansistring;
        r1,r2: array[0..9,0..100000] of longint;
        c,d,e: array[0..9] of longint;
        ck: boolean;
begin
        readln(s);
        for i:=1 to length(s) do
        begin
                inc(d[ord(s[i])-48]);
        end;
        n:=length(s);

        for i:=1 to 9 do
        begin
                c:=d;
                e:=d;

                count:=0;

                if ((c[i]<1) or (e[10-i]<1)) then continue;
                dec(c[i]); dec(e[10-i]);
                r1[i,1]:=i; r2[i,1]:=10-i;
                ck:=true;
                if res=0 then
                begin
                        res:=1;
                        ires:=i;
                end;
                for j:=2 to n do
                begin
                        if ck=true then
                        begin
                        ck:=false;
                        for t:=0 to 9 do
                        begin
                                if (c[t]>0) and (e[9-t]>0) then
                                begin
                                        inc(count);
                                        cK:=true;
                                        dec(c[t]); dec(e[9-t]);
                                        r1[i,j]:=t; r2[i,j]:=9-t;
                                        if count>res then
                                        begin
                                                res:=count;
                                                ires:=i;
                                                mres:=0;
                                        end;
                                        break;
                                end;
                        end;
                        end;
                        if not ck then
                        begin
                                tmp:=math.min(c[0],e[0]);
                                c[0]:=c[0]-tmp;
                                e[0]:=e[0]-tmp;
                                if count+tmp>res then
                                begin
                                        res:=count+tmp;
                                        ires:=i;
                                        mres:=tmp;
                                end;
                                for t:=0 to 9 do
                                begin
                                        if (c[t]>0)and(r1[i,j]=0) then
                                        begin
                                                r1[i,j]:=t;
                                                dec(c[t]);
                                        end;
                                        if (e[t]>0)and(r2[i,j]=0) then
                                        begin
                                                r2[i,j]:=t;
                                                dec(e[t]);
                                        end;
                                end;
                        end;
                end;
        end;
        if res<>0 then
        begin
                tmp:=mres;

                for i:=n-tmp downto 1 do write(r1[ires,i]);
                for i:=tmp downto 1 do write(0);

                writeln;

                for i:=n-tmp downto 1 do write(r2[ires,i]);
                for i:=tmp downto 1 do write(0);

                writeln;
        end
        else
        begin

        c:=d; e:=d;
        tmp:=math.min(c[0],e[0]);
        c[0]:=c[0]-tmp;
        e[0]:=e[0]-tmp;
        for j:=1 to n do
        for t:=0 to 9 do
                                begin
                                        if (c[t]>0)and(r1[1,j]=0) then
                                        begin
                                                r1[1,j]:=t;
                                                dec(c[t]);
                                        end;
                                        if (e[t]>0)and(r2[1,j]=0) then
                                        begin
                                                r2[1,j]:=t;
                                                dec(e[t]);
                                        end;
                                end;

        for i:=n-tmp downto 1 do write(r1[1,i]);
        for i:=tmp downto 1 do write(0);

        writeln;

        for i:=n-tmp downto 1do write(r2[1,i]);
        for i:=tmp downto 1 do write(0);

        writeln;

        end;
end.

var
        a:array[1..100000]of longint;
        b,c,d,e:array[0..9]of longint;
        s:ansistring;
        pk:boolean;
        n,i,j,k,l,o:longint;
        ansa,ansb:array[0..100000]of longint;
        ans:array[1..9]of longint;
function min(x,y:longint):longint;
begin
        if x<y then exit(x) else exit(y);
end;
begin
        readln(s);
        for i:=1 to length(s) do begin
                val(s[i],j);
                inc(b[j]);
        end;
        d:=b;
        e:=b;
        o:=1;
        for i:=1 to 9 do begin
                b:=d;
                c:=e;
                l:=0;
                if (b[i]>0)and(c[10-i]>0) then begin
                        dec(b[i]);
                        dec(c[10-i]);
                        l:=1;
                        for j:=0 to 9 do begin
                                b[j]:=min(b[j],c[9-j]);
                                l:=l+b[j];
                        end;
                end;
                ans[i]:=l+min(c[0]-b[9],c[0]-b[0]);
                if ans[i]>ans[o] then o:=i;
        end;
        b:=d; c:=e;
        pk:=false;
        if (d[o]>0)and(c[10-o]>0) then begin
        dec(b[o]);
        pk:=true;
        dec(d[o]);
        dec(c[10-o]);
        end;
        for j:=0 to 9 do begin
                b[j]:=min(b[j],c[9-j]);
        end;
        ansa[0]:=min(c[0]-b[0],c[0]-b[9]);
        ansb[0]:=ansa[0];
        d[0]:=d[0]-ansa[0];
        c[0]:=c[0]-ansb[0];
        if pk then begin
        inc(ansa[0]);
        ansa[ansa[0]]:=o;
        inc(ansb[0]);
        ansb[ansb[0]]:=10-o;
        end;
        for i:=0 to 9 do begin
                for j:=1 to b[i] do begin
                        inc(ansa[0]);
                        ansa[ansa[0]]:=i;
                        dec(d[i]);
                        inc(ansb[0]);
                        ansb[ansb[0]]:=9-i;
                        dec(c[9-i]);
                end;
        end;
        for i:=0 to 9 do begin
                for j:=1 to d[i] do begin
                        inc(ansa[0]);
                        ansa[ansa[0]]:=i;
                end;
                for j:=1 to c[i] do begin
                        inc(ansb[0]);
                        ansb[ansb[0]]:=i;
                end;
        end;
        for i:=ansa[0] downto 1 do write(ansa[i]);
        writeln;
        for i:=ansb[0] downto 1 do write(ansb[i]);
        writeln;
end.

uses math;
const
        fi='';
var
        f:text;
        s,r1,r2:ansistring;
        n,kq,max,x,dis,l1,l2:longint;
        a,b,c,d:array [0..9] of longint;
procedure nhap;
var
        i:longint;
begin
        assign(f,fi);
        reset(f);
        readln(f,s);
        n:=length(s);
        for i:=1 to n do inc(a[ord(s[i])-48]);
        for i:=0 to 9 do b[i]:=a[i];
        dis:=1;
        kq:=-1;
        close(f);
end;
procedure cc;
var
        i,j,u,v,queo:longint;
begin
        c:=a; d:=b;
        v:=math.min(a[0],b[0]);
        if v=0 then exit;
        queo:=v;
        c[0]:=c[0]-v; d[0]:=d[0]-v;
        if queo>max then
        begin
                dis:=0;
                kq:=0;
                max:=queo;
                l1:=-1;
        end;
        for i:=1 to 9 do
        if c[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if d[u]<=0 then continue;
                dec(c[i]); dec(d[u]);
                x:=queo+1;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(c[j],d[v]);
                end;
                if x>max then
                begin
                        max:=x;
                        kq:=i;
                        dis:=0;
                        l1:=i; l2:=u;
                end;
                inc(c[i]); inc(d[u]);
        end;
end;
procedure xuly;
var
        i,j,u,v,cl1,cl2:longint;
begin
        for i:=1 to 9 do
        if a[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if b[u]<=0 then continue;
                dec(a[i]); dec(b[u]);
                x:=1;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(a[j],b[v]);
                        if j=0 then cl1:=math.min(a[j],b[v]);
                        if j=9 then cl2:=math.min(a[j],b[v]);
                end;
                x:=x+math.min(a[0]-cl1,b[0]-cl2);
                if x>max then
                begin
                        max:=x;
                        kq:=i;
                end;
                inc(a[i]); inc(b[u]);
        end;
end;
procedure lam;
var
        i,j,u,v:longint;
begin
        if kq=-1 then
        begin
                writeln(s);
                writeln(s);
                halt;
        end;
        if dis=0 then
        begin
                v:=math.min(a[0],b[0]);
                for i:=1 to v do r1:='0'+r1;
                for i:=1 to v do r2:='0'+r2;
                a[0]:=a[0]-v; b[0]:=b[0]-v;
                if l1<>-1 then
                begin
                dec(a[l1]); dec(b[l2]);
                r1:=chr(l1+48)+r1;
                r2:=chr(l2+48)+r2;
                end;
                for i:=0 to 9 do
                if a[i]>0 then
                begin
                        u:=9-i;
                        if b[u]<=0 then continue;
                        v:=math.min(a[i],b[u]);
                        a[i]:=a[i]-v; b[u]:=b[u]-v;
                        for j:=1 to v do r1:=chr(i+48)+r1;
                        for j:=1 to v do r2:=chr(u+48)+r2;
                end;
                v:=math.min(a[0],b[0]);
               for i:=1 to v do r1:=r1+'0';
                for i:=1 to v do r2:=r2+'0';
                a[0]:=a[0]-v; b[0]:=b[0]-v;
        for i:=0 to 9 do
        for j:=1 to a[i] do r1:=chr(i+48)+r1;
        for i:=0 to 9 do
        for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end
        else
        begin
        r1:=chr(kq+48);
        dec(a[kq]);
        v:=10-kq;
        r2:=chr(v+48);
        dec(b[v]);
        for i:=0 to 9 do
        if a[i]>0 then
        begin
                u:=9-i;
                if b[u]<=0 then continue;
                v:=math.min(a[i],b[u]);
                a[i]:=a[i]-v; b[u]:=b[u]-v;
                for j:=1 to v do r1:=chr(i+48)+r1;
                for j:=1 to v do r2:=chr(u+48)+r2;
        end;
        v:=math.min(a[0],b[0]);
         for i:=1 to v do r1:=r1+'0';
                for i:=1 to v do r2:=r2+'0';
                a[0]:=a[0]-v; b[0]:=b[0]-v;
        for i:=0 to 9 do
        for j:=1 to a[i] do r1:=chr(i+48)+r1;
        for i:=0 to 9 do
        for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end;
        writeln(r1);
        writeln(r2);
end;
begin
        nhap;
        xuly;
        cc;
        lam;
end.

{$APPTYPE CONSOLE}
{$R+,S+,Q+,I+,M+,C+,H+,O-}
{R-,S-,Q-,I-,M-,C-,H-,O+}

uses
	SysUtils, Math;

var
	i, ls, mx, l, r, cur, x, y, kk, j, zz : longint;
	a, b, c : array[0..10] of longint;
	p, q : array[0..100010] of longint;
	s : string;

function count(x, y : longint) : longint;

var
	i : longint;

begin
	dec(b[x]);
	dec(c[y]);
	result := 0;
	for i := 0 to 9 do
		inc(result, min(b[i], c[9 - i]));
	inc(b[x]);
	inc(c[y]);
end;

begin
{$IFNDEF ONLINE_JUDGE}
	reset(input, 'input.txt');
	rewrite(output, 'output.txt');
{$ENDIF}
	readln(s);
	fillchar(a, sizeof(a), 0);
	ls := length(s);
	for i := 1 to ls do
		inc(a[ord(s[i]) - 48]);
	b := a;
	c := a;
	l := -1;
	r := -1;
	mx := -1;
	for i := 1 to 5 do
		if (a[i] > 0) and (a[10 - i] > 0) then begin
			cur := count(i, 10 - i);
			if cur > mx then begin
				mx := cur;
				l := i;
				r := 10 - i;
			end;
		end;
	x := 1;
	if l > -1 then begin
		dec(b[l]);
		dec(c[r]);
		p[x] := l;
		q[x] := r;
		inc(x);
	end;
	for i := 0 to 9 do begin
		kk := min(b[i], c[9 - i]);
		for j := 1 to kk do begin
			p[x] := i;
			q[x] := 9 - i;
			inc(x);
		end;
		dec(b[i], kk);
		dec(c[9 - i], kk);
	end;
	zz := min(b[0], c[0]);
	y := x;
	for i := 1 to 9 do begin
		for j := 1 to b[i] do begin
			p[x] := i;
			inc(x);
		end;
		for j := 1 to c[i] do begin
			q[y] := i;
			inc(y);
		end;
	end;
	for i := ls - zz downto 1 do
		write(p[i]);
	for i := 1 to zz do
		write(0);
	writeln;
	for i := ls - zz downto 1 do
		write(q[i]);
	for i := 1 to zz do
		write(0);
end.

{$A8,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O-,P+,Q+,R+,S+,T-,U-,V+,W-,X+,Y+,Z1}
//{$A8,B-,C+,D-,E-,F-,G+,H+,I-,J-,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}

program ProblemB;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Math;

const
  inname = 'input.txt';
  outname = 'output.txt';
  maxn = 100010;
  maxm = 0;
  inf = maxlongint div 2;
  eps = 0;

type
  int = longint;
  bool = boolean;
  real = extended;

var
  n, m, ansz, ansf, ansk: int;
  ansa, ansb: array[0..maxn] of int;
  c, b, a: array[0..11] of int;

procedure run;
var
  i, j, k, t, d: int;
  ch: char;
begin
  fillchar(c, sizeof(c), 0);
  while not seekeoln do begin
    read(ch);
    inc(c[ord(ch) - ord('0')]);
  end;

  ansk := -1;
  ansz := 0;
  ansf := 0;

  for i := 1 to 9 do
    for j := 0 to c[0] do begin
      t := j + 1;

      a := c;
      b := c;
      dec(a[0], j);
      dec(b[0], j);

      if a[i] = 0 then
        continue;
      dec(a[i]);

      if b[10 - i] = 0 then
        continue;
      dec(b[10 - i]);

      for k := 0 to 9 do begin
        d := min(a[k], b[9 - k]);

        inc(t, d);

        dec(a[k], d);
        dec(b[9 - k], d);
      end;

      if (ansk < t) then begin
        ansk := t;
        ansz := j;
        ansf := i;
      end;
    end;

  if (ansk = -1) then begin
    for i := 9 downto 0 do
      for j := 1 to c[i] do
        write(i);
    writeln;
    for i := 9 downto 0 do
      for j := 1 to c[i] do
        write(i);
    writeln;
    exit;
  end;

  n := ansz;
  m := ansz;

  a := c;
  b := c;

  dec(a[0], ansz);
  dec(b[0], ansz);

  for i := 1 to ansz do begin
    ansa[i] := 0;
    ansb[i] := 0;
  end;

  inc(n);
  ansa[n] := ansf;
  dec(a[ansf]);
  inc(m);
  ansb[m] := 10 - ansf;
  dec(b[10 - ansf]);

  for k := 0 to 9 do begin
    d := min(a[k], b[9 - k]);

    dec(a[k], d);
    dec(b[9 - k], d);

    for i := 1 to d do begin
      inc(n);
      ansa[n] := k;
    end;
    for i := 1 to d do begin
      inc(m);
      ansb[m] := 9 - k;
    end;
  end;

  for i := 0 to 9 do
    for j := 1 to a[i] do begin
      inc(n);
      ansa[n] := i;
    end;

  for i := 0 to 9 do
    for j := 1 to b[i] do begin
      inc(m);
      ansb[m] := i;
    end;

  for i := n downto 1 do
    write(ansa[i]);
  writeln;
  for i := m downto 1 do
    write(ansb[i]);
  writeln;
end;

procedure openfiles;
begin
  assign(input, inname);
  assign(output, outname);
  reset(input);
  rewrite(output);
end;

procedure closefiles;
begin
  close(input);
  close(output);
end;

Begin
  //openfiles;
  run;
  //closefiles;
End.

Program cf99b;
const ch:array[0..9] of char='0123456789';
var t,a,b,c:array[0..9] of longint;
    n,i,j,k,l,pre,best,cur,cp,d:longint;
    cc:char;
function min(a,b:longint):longint;
begin
  if a<b then exit(a) else exit(b);
end;
function calc:longint;
var p:longint; aa:longint;
begin
  aa:=0;
  for p:=0 to 9 do aa:=aa+min(a[p],b[9-p]);
  exit(aa);
end;
begin
  //assign(input,'input.txt');reset(input);
  while not eoln do
    begin
      read(cc);
      inc(t[ord(cc)-ord('0')]);
    end;
  best:=0;
  for i:=1 to 5 do
    if ((i=5) and (t[5]>=1))
    or ((i<>5) and (t[i]>=1) and (t[10-i]>=1))
  then
    begin
      for j:=0 to 9 do begin a[j]:=t[j];b[j]:=t[j];end;
      a[i]:=a[i]-1;
      b[10-i]:=b[10-i]-1;
      cur:=calc()+min(a[0]-min(a[0],b[9]),b[0]-min(b[0],a[9]))+1;
      if cur>best then
        begin
          best:=cur;
          cp:=i;
        end;
    end;
  if best=0 then
    begin
      for i:=1 to 10 do
        for j:=1 to t[i mod 10] do
          write(i mod 10);
      writeln;
      for i:=1 to 10 do
        for j:=1 to t[i mod 10] do
          write(i mod 10);
    end
  else
    begin
      //writeln(best);
      a:=t;b:=t;
      a[cp]:=a[cp]-1;
      b[10-cp]:=b[10-cp]-1;
      pre:=min(a[0]-min(a[0],b[9]),b[0]-min(b[0],a[9]));
      a[0]:=a[0]-pre;b[0]:=b[0]-pre;
      for i:=0 to 9 do c[i]:=min(a[i],b[9-i]);
      for i:=0 to 9 do a[i]:=a[i]-c[i];
      for i:=0 to 9 do b[9-i]:=b[9-i]-c[i];
      for i:=0 to 9 do
        if a[i]>0 then
          for j:=1 to a[i] do write(ch[i]);
      for i:=0 to 9 do
        if c[i]>0 then
          for j:=1 to c[i] do write(ch[i]);
      write(ch[cp]);
      for i:=1 to pre do write('0');
      writeln;
      for i:=0 to 9 do
        if b[i]>0 then
          for j:=1 to b[i] do write(ch[i]);
      for i:=0 to 9 do
        if c[i]>0 then
          for j:=1 to c[i] do write(ch[9-i]);
      write(ch[10-cp]);
      for i:=1 to pre do write('0');
    end;
  close(input);
end.

uses math;
Var a,b:array[0..123]of longint;
ans,anss:array[0..100333,1..2]of longint;
i,j,k,kk,q,ii,x,cnt,o,p,kkk,oo:longint;
ok:boolean;
s:ansistring;
  begin
   { assign(input,'input.txt');
    reset(input);
    assign(output,'output.txt');
    rewrite(output);
    }
    readln(s);
    kkk:=-1;
    fillchar(b,sizeof(b),0);
    fillchar(a,sizeof(a),0);
    for i:=1 to length(s) do
      inc(a[ord(s[i])-48]);
    for i:=0 to 9 do
      b[i]:=a[i];
    ok:=false;
    for i:=1 to 9 do
      if (a[i]*a[10-i]>0) then ok:=true;
    if not ok then begin
                     // Writeln(a[0]);
                     for i:=9 downto 0 do
                      for j:=1 to a[i] do
                       Write(i);
                      Writeln;
                     for i:=9 downto 0 do
                      for j:=1 to a[i] do
                       Write(i);
                      Writeln;
halt(0);
                   end;

    for ii:=1 to 9 do
    begin
    fillchar(b,sizeof(b),0);
    fillchar(a,sizeof(a),0);
    for i:=1 to length(s) do
      inc(a[ord(s[i])-48]);
    for i:=0 to 9 do
      b[i]:=a[i];

    if a[(10-ii)mod 10]=0 then continue;
    if a[ii]=0 then continue;
    k:=1;
    ans[k,1]:=ii;
    ans[k,2]:=(10-ii)mod 10;
    dec(a[ii]);
    dec(b[(10-ii)mod 10]);  x:=1;
    j:=1;
    while (j=1)or(k<>kk) do
    begin
    kk:=k;
    for i:=9 downto 1 do
      begin
        while (a[i]>0)and(b[(10-i-x)mod 10]>0)and((10-i-x)mod 10<>0) do
          begin
            inc(k);
            ans[k,1]:=i;
            ans[k,2]:=(10-i-x)mod 10;
            dec(a[i]);
            dec(b[(10-i-x)mod 10]);
            if (i<>0)or((10-i-x)mod 10<>0) then x:=1
            else x:=0;
          end;
      end;
      inc(j);
     end;
    for i:=1 to min(a[0],b[9]) do
      begin
        inc(k);
        ans[k,1]:=0;
        ans[k,2]:=9;
        dec(a[0]);
        dec(b[9]);
      end;
    for i:=1 to min(b[0],a[9]) do
      begin
        inc(k);
        ans[k,1]:=9;
        ans[k,2]:=0;
        dec(b[0]);
        dec(a[9]);
      end;

    o:=0;
    for i:=1 to min(a[0],b[0]) do
      begin
        inc(o);
        dec(a[0]);
        dec(b[0]);
      end;
    if k+o<kkk+oo then continue;
    kkk:=k;
    oo:=o;
    kk:=k;
    for i:=0 to 9 do
     for j:=1 to a[i] do
      begin
        inc(k);
        ans[k,1]:=i;
      end;
    for i:=0 to 9 do
     for j:=1 to b[i] do
      begin
        inc(kk);
        ans[kk,2]:=i;
      end;
      for i:=1 to k do
        begin
          anss[i,1]:=ans[i,1];
          anss[i,2]:=ans[i,2];
        end;
       cnt:=k;
     end;
  //   Writeln(kkk+oo);
     for i:=cnt downto 1 do
       Write(anss[i,1]);
     for i:=1 to oo do
       Write('0');
     Writeln;
     for i:=cnt downto 1 do
       Write(anss[i,2]);
     for i:=1 to oo do
       Write('0');
     Writeln;
     close(input);
     close(output);
  end.

program shablon;

{$MODE OBJFPC}{$H+}
{$O+ R-  Q-}
{$COperators ON}

uses
   SysUtils,
   Math;

const inf = 1 / 0;
      nmax = 100 * 1000 + 100;

var n : longint;
    s : string;
    a, b : array[1 .. nmax] of longint;
    c1, c2 : array[0 .. 9] of longint;

procedure pout;
var i : longint;
begin
    for i := 1 to n do begin
        write(a[i]);
    end;
    writeln;
    for i := 1 to n do begin
        write(b[i]);
    end;
    {$IFNDEF ONLINE_JUDGE}
    close(input);
    close(output);
    {$ENDIF}
    halt(0);
end;

procedure pinit;
begin
    {$IFNDEF ONLINE_JUDGE}
    assign(input, 'input.txt');
    assign(output, 'output.txt');
    reset(input);
    rewrite(output);
    {$ENDIF}
    readln(s);
end;

function get(x : longint) : longint;
var i : longint;
begin
    result := 0;
    if c1[x] = 0 then exit;
    if c2[10 - x] = 0 then exit;
    dec(c1[x]);
    dec(c2[10 - x]);
    result := 1;
    for i := 0 to 9 do begin
        inc(result, min(c1[i], c2[9 - i]));
    end;
    inc(c1[x]);
    inc(c2[10 - x]);
end;

procedure solve;
var i, ans, ind, an, r, t1, t2, j, c10, nul0 : longint;
begin
    n := length(s);
    fillchar(c1, sizeof(c1), 0);
    fillchar(a, sizeof(a), 0);
    fillchar(b, sizeof(b), 0);
    for i := 1 to n do begin
        inc(c1[strtoint(s[i])]);
    end;
    c2 := c1;
    ans := -1;
    ind := 0;
    r := 0;
    c10 := c1[0];
    for nul0 := 0 to c10 do begin
        for i := 9 downto 1 do begin
            an := get(i);
            if an  + nul0 > ans + r then begin
                ans := an;
                ind := i;
                r := nul0;
            end;
        end;
        dec(c1[0]);
        dec(c2[0]);
    end;
    c1[0] := c10 - r;
    c2[0] := c10 - r;
    if ans <> 0 then begin
        a[n - r] := ind;
        b[n - r] := 10 - ind;
        dec(c1[ind]);
        dec(c2[10 - ind]);
        j := 9;
        t1 := 0;
        t2 := 0;
        inc(r);
    end
    else begin
        j := -1;
        t1 := 0;
        t2 := 0;
    end;
    for i := n - r downto 1 do begin
        while (j > -1) and (min(c1[j], c2[9 - j]) = 0) do begin
            dec(j);
        end;
        if j > -1 then begin
            a[i] := j;
            b[i] := 9 - j;
            dec(c1[j]);
            dec(c2[9 - j]);
        end
        else begin
            while (t1 < 10) and (c1[t1] = 0) do begin
                inc(t1);
            end;
            if t1 < 10 then begin
                a[i] := t1;
                dec(c1[t1]);
            end
            else begin
                writeln('WTF?!1');
                halt(3);
            end;
            while (t2 < 10) and (c2[t2] = 0) do begin
                inc(t2);
            end;
            if t2 < 10 then begin
                b[i] := t2;
                dec(c2[t2]);
            end
            else begin
                writeln('WTF?!2');
                halt(3);
            end;
        end;
    end;
end;

begin
    pinit;
    solve;
    pout;
end.

{$H+}
var
a1:string;
num,pre,prepre,vxod,max,alter:longint;
function min(a1,a2:longint):longint;
begin
     if a1<a2 then min:=a1 else min:=a2;
end;
procedure poisk(a:string;b,dozv:byte);
var
c,s:array[0..9]of longint;
verx,nizz:array[1..100000]of byte;
a1:string;
d,i,p,nach,mini,vt,j,k:longint;
begin
for i:=0 to 9 do begin c[i]:=0;s[i]:=0;end;
d:=length(a);
for i:=1 to d do begin
p:=ord(a[i])-ord('0');
inc(c[p]);inc(s[p]);
end;
nach:=1;
if b=1 then
if (c[9]<>0)and(s[1]<>0)then begin
    verx[1]:=9;nizz[1]:=1;
    dec(c[9]);dec(s[1]);inc(nach);
    end;
if b=2 then
    if (c[5]<>0)and(s[5]<>0)then begin
    verx[1]:=5;nizz[1]:=5;
    dec(c[5]);dec(s[5]);inc(nach);
    end;
if b=3 then
        if (c[8]<>0)and(s[2]<>0)then begin
        verx[1]:=8;nizz[1]:=2;
        dec(c[8]);dec(s[2]);inc(nach);
        end;
if b=4 then
            if (c[7]<>0)and(s[3]<>0)then begin
            verx[1]:=7;nizz[1]:=3;
            dec(c[7]);dec(s[3]);inc(nach);
            end;
if b=5 then
                if (c[6]<>0)and(s[4]<>0)then begin
                verx[1]:=6;nizz[1]:=4;
                dec(c[6]);dec(s[4]);inc(nach);
                end;
mini:=min(c[0],s[9]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=0;nizz[i]:=9;
    end;
    c[0]:=c[0]-mini;s[9]:=s[9]-mini;
nach:=nach+mini;
mini:=min(c[1],s[8]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=1;nizz[i]:=8;
    end;
    c[1]:=c[1]-mini;s[8]:=s[8]-mini;
nach:=nach+mini;
mini:=min(c[2],s[7]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=2;nizz[i]:=7;
    end;
    c[2]:=c[2]-mini;s[7]:=s[7]-mini;
nach:=nach+mini;
mini:=min(c[3],s[6]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=3;nizz[i]:=6;
    end;
    c[3]:=c[3]-mini;s[6]:=s[6]-mini;
nach:=nach+mini;
mini:=min(c[4],s[5]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=4;nizz[i]:=5;
    end;
    c[4]:=c[4]-mini;s[5]:=s[5]-mini;
nach:=nach+mini;
mini:=min(c[5],s[4]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=5;nizz[i]:=4;
    end;
    c[5]:=c[5]-mini;s[4]:=s[4]-mini;
nach:=nach+mini;
mini:=min(c[6],s[3]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=6;nizz[i]:=3;
    end;
    c[6]:=c[6]-mini;s[3]:=s[3]-mini;
nach:=nach+mini;
mini:=min(c[7],s[2]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=7;nizz[i]:=2;
    end;
    c[7]:=c[7]-mini;s[2]:=s[2]-mini;
nach:=nach+mini;
mini:=min(c[8],s[1]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=8;nizz[i]:=1;
    end;
    c[8]:=c[8]-mini;s[1]:=s[1]-mini;
nach:=nach+mini;
mini:=min(c[9],s[0]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=9;nizz[i]:=0;
    end;
    c[9]:=c[9]-mini;s[0]:=s[0]-mini;
nach:=nach+mini;vt:=nach;
k:=min(c[0],s[0]);
c[0]:=c[0]-k;s[0]:=s[0]-k;
for j:=0 to 9 do begin
    if c[j]<>0 then
    for i:=nach to nach+c[j]-1 do begin
        verx[i]:=j;
        end;
nach:=nach+c[j];
end;
nach:=vt;
for j:=0 to 9 do begin
    if s[j]<>0 then
    for i:=nach to nach+s[j]-1 do begin
        nizz[i]:=j;
        end;
nach:=nach+s[j];
end;
{k:=0;
for i:=d downto 1 do
    if (verx[i]=0)and(nizz[i]=0)then inc(k) else break;}
d:=i;
if dozv=1 then begin
if verx[d]=0 then d:=d-1;
for i:=d downto 1 do write(verx[i]);for i:=1 to k do write(0);
writeln;
for i:=d downto 1 do write(nizz[i]);for i:=1 to k do write(0);
writeln;
end;
pre:=0;prepre:=0;
for i:=d downto 1 do
    if(verx[i]+nizz[i]=9)then inc(pre);
if(verx[1]+nizz[1]=10)then inc(prepre);
end;
begin
read(a1);
max:=0;
for num:=1 to 5 do begin
poisk(a1,num,0);
if (max<pre)and(prepre>=1)then begin
                                    max:=pre;
                                    vxod:=num;
                                    end;
if (prepre>=1)then alter:=num;
end;
if vxod>0 then
poisk(a1,vxod,1)else poisk(a1,alter,1);
end.

uses  math;
var
  n,i,j,p,res,t,c: longint;
  ch: char;
  r1,r2: ansistring;
  s,a,b,d: array[0..9] of longint;
function kt(a: longint): char;
  begin
    exit(char(a+ord('0')));
  end;
begin
//  assign(input,'aaa.inp');reset(input);
//  assign(output,'aaa.out');rewrite(output);

  n := 0;
  while not eoln do begin
    inc(n);
    read(ch);
    inc(s[ord(ch)-ord('0')]);
  end;

  res := s[0];
  p := 0;
  for i:=1 to 5 do if (s[i]>0) and (s[10-i]>0) then begin
    for j:=0 to 9 do begin
      a[j] := s[j];
      b[j] := s[j];
    end;
    dec(a[i]);
    dec(b[10-i]);
    t := 1;
    for j:=0 to 9 do begin
      c := min(a[j], b[9-j]);
      inc(t, c);
      dec(a[j],c);
      dec(b[9-j],c);
    end;
    t := t + min(a[0],b[0]);

    if t>res then begin
      res := t;
      p := i;
    end;
  end;

    i := p;
    for j:=0 to 9 do begin
      a[j] := s[j];
      b[j] := s[j];
    end;
  if p>0 then begin
    dec(a[i]);
    dec(b[10-i]);
    for j:=0 to 9 do begin
      c := min(a[j], b[9-j]);
      dec(a[j],c);
      dec(b[9-j],c);
      d[j] := c;
    end;

    r1 := kt(p);
    r2 := kt(10-p);
    for i:=0 to 9 do for j:=1 to d[i] do begin
      r1 := kt(i) + r1;
      r2 := kt(9-i) + r2;
    end;
  end;

  c := min(a[0],b[0]);
  dec(a[0],c);
  dec(b[0],c);
  for i:=1 to c do begin
    r1 := r1 + '0';
    r2 := r2 + '0';
  end;
  for i:=0 to 9 do begin
    for j:=1 to a[i] do r1 := kt(i)+r1;
    for j:=1 to b[i] do r2 := kt(i)+r2;
  end;
  writeln(r1);
  writeln(r2);
end.

uses math;

var mm,t1,t2,j,last,max,tmp,i1,t,m,n,i:longint;
ok:boolean;
s:ansistring;
a1,a2,f1,f2,c,a:array[0..200000]of longint;

 begin
  readln(s);
  t:=0;
  n:=length(s);
  for i:=1 to n do
   if s[i]='0' then t:=t+1 else
    begin
     m:=m+1;
     a[m]:=ord(s[i])-48;
     inc(c[a[m]]);
    end;

  max:=-1;
  last:=1;

  for i1:=1 to 9 do
   if c[i1]>0 then
     if c[10-i1]>0 then
      begin
       for i:=1 to 9 do
         begin
          f1[i]:=c[i];
          f2[i]:=c[i];
         end;

       f1[i1]:=f1[i1]-1;
       f2[10-i1]:=f2[10-i1]-1;

       tmp:=1;

       for i:=1 to 8 do
         begin
          tmp:=tmp+min(f1[i],f2[9-i]);
         end;

       tmp:=tmp+min(f1[9],t)+min(f2[9],t);
       t1:=t-f1[9];
       if t1<0 then t1:=0;

       t2:=t-f2[9];
       if t2<0 then t2:=0;

       tmp:=tmp+min(t1,t2);

       if tmp>max then
         begin
          max:=tmp;
          last:=i1;
         end;
      end;

  if t>max then
    begin
     for i:=1 to m do write(a[i]);
     for i:=1 to t do write(0);
     writeln;

     for i:=1 to m do write(a[i]);
     for i:=1 to t do write(0);
     writeln;
     halt(0);
    end;

  i1:=last;

       for i:=1 to 9 do
         begin
          f1[i]:=c[i];
          f2[i]:=c[i];
         end;

       f1[i1]:=f1[i1]-1;
       f2[10-i1]:=f2[10-i1]-1;
       a1[1]:=i1;
       a2[1]:=10-i1;
       mm:=1;

       for i:=1 to 8 do
         begin
          tmp:=min(f1[i],f2[9-i]);
          for j:=1 to tmp do
            begin
             mm:=mm+1;
             a1[mm]:=i;
             a2[mm]:=9-i;
             dec(f1[i]);
             dec(f2[9-i]);
            end;
         end;

       tmp:=min(f1[9],t);
       for j:=1 to tmp do
         begin
          mm:=mm+1;
          a1[mm]:=9;
          a2[mm]:=0;
         end;

       tmp:=min(f2[9],t);
       for j:=1 to tmp do
         begin
          mm:=mm+1;
          a2[mm]:=9;
          a1[mm]:=0;
         end;

       t1:=t-f2[9];
       if t1<0 then t1:=0;

       t2:=t-f1[9];
       if t2<0 then t2:=0;

       if f1[9]<t then f1[9]:=0 else f1[9]:=f1[9]-t;
       if f2[9]<t then f2[9]:=0 else f2[9]:=f2[9]-t;

       tmp:=min(t1,t2);
       inc(f1[0],t1-tmp);
       inc(f2[0],t2-tmp);

  while true do
         begin
          ok:=true;
          for j:=0 to 9 do
            if f1[j]>0 then
              begin
               mm:=mm+1;
               a1[mm]:=j;
               ok:=false;
               dec(f1[j]);
               break;
              end;

          if ok then break;

          for j:=0 to 9 do
            if f2[j]>0 then
              begin
               a2[mm]:=j;
               ok:=false;
               dec(f2[j]);
               break;
              end;
         end;

  for i:=mm downto 1 do write(a1[i]);
  for i:=1 to tmp do write(0);
  writeln;

  for i:=mm downto 1 do write(a2[i]);
  for i:=1 to tmp do write(0);
  writeln;

 end.

var st:ansistring;
    a,b,c:array[0..10] of longint;
    max,maxk,c1,i,e,j,o:longint;
    x,y:array[0..1000000] of longint;

function min(a,b:longint):longint;
  begin
    if a<b then exit(a) else exit(b);
  end;

begin
  readln(st);
  fillchar(a,sizeof(a),0);
  for i:=1 to length(st) do
    inc(a[ord(st[i])-48]);
  max:=0;
  maxk:=0;
  for i:=1 to 5 do
    begin
      b:=a;
      c:=a;
      dec(b[i]);
      dec(c[10-i]);
      if (b[i]>=0) and (c[10-i]>=0) then
        begin
          e:=1;
          for j:=0 to 9 do
            e:=e+min(b[j],c[9-j]);
          if e>max then
            begin
              max:=e;
              maxk:=i;
            end;
        end;
    end;
  if (max=0) and (a[0]=0) then
    begin
      writeln(st);
      writeln(st);
    end
  else
    if max=0 then
      begin
        for i:=1 to length(st) do if st[i]<>'0' then write(st[i]);
        for i:=1 to a[0] do write('0');writeln;
        for i:=1 to length(st) do if st[i]<>'0' then write(st[i]);
        for i:=1 to a[0] do write('0');writeln;
      end
    else
    begin
      inc(o);
      x[o]:=maxk;
      y[o]:=10-maxk;
      b:=a;
      dec(a[maxk]);
      dec(b[10-maxk]);
      for i:=0 to 9 do
        begin
          c1:=min(a[i],b[9-i]);
          a[i]:=a[i]-c1;
          b[9-i]:=b[9-i]-c1;
          for j:=1 to c1 do
            begin
              inc(o);
              x[o]:=i;
              y[o]:=9-i;
            end;
        end;
      c1:=min(a[0],b[0]);
      a[0]:=a[0]-c1;
      b[0]:=b[0]-c1;
      for i:=0 to 9 do
        for j:=1 to a[i] do
          write(i);
      for i:=o downto 1 do write(x[i]);
      for i:=1 to c1 do write(0);writeln;
      for i:=0 to 9 do
        for j:=1 to b[i] do
          write(i);
      for i:=o downto 1 do write(y[i]);
      for i:=1 to c1 do write(0);writeln;
    end;
end.

uses
  math;

var
  u1,u2,a:array[0..500500]of longint;
  kc1,kc2,kc:array[0..100]of longint;
  tt,z,m1,m2,cr,m,c,i,n,pc1,pc2,c1,c2,max,qq:longint;
  s:ansistring;

begin
  readln(s);
  n:=length(s);
  fillchar(kc,sizeof(kc),$0);
  for i:=1 to n do a[i]:=ord(s[i])-48;
  for i:=1 to n do inc(kc[a[i]]);
  m:=n;
  pc1:=-1;pc2:=-1;
  max:=-1;
  tt:=kc[0];
  for i:=0 to tt do begin
    dec(kc[0],i);
    for c1:=0 to 9 do begin
      c2:=10-c1;
      if (kc[c1]=0)or(kc[c2]=0)then continue;
      dec(kc[c1]);dec(kc[c2]);  cr:=i+1;
      for c:=0 to 4 do begin
        qq:=min(kc[c],kc[9-c]);
        inc(cr,qq);
      end;
      if (cr>max)then begin max:=cr;pc1:=c1;pc2:=c2;z:=i; end;
      inc(kc[c1]);inc(kc[c2]);
    end;
    inc(kc[0],i);
  end;
  for i:=1 to z do begin
    dec(kc[0]);
    u1[m]:=0;
    u2[m]:=0;
    dec(m);
  end;
  if (pc1<>-1)then begin
    u1[m]:=pc1;
    u2[m]:=pc2;
    dec(m);
    c1:=pc1;c2:=pc2;
    for c:=0 to 9 do begin kc1[c]:=kc[c];kc2[c]:=kc[c]; end;
    dec(kc1[c1]);
    dec(kc2[c2]);
    for c:=0 to 9 do begin
      qq:=min(kc1[c],kc2[9-c]);
      for i:=1 to qq do begin
        u1[m]:=c;
        u2[m]:=9-c;
        dec(m);
      end;
      dec(kc1[c],qq);dec(kc2[9-c],qq);
    end;
  end else for c:=0 to 9 do begin kc1[c]:=kc[c];kc2[c]:=kc[c]; end;
  m1:=m;m2:=m;
  for i:=0 to 9 do begin
    while (kc1[i]>0)do begin
      u1[m1]:=i;
      dec(m1);
      dec(kc1[i]);
    end;
    while (kc2[i]>0)do begin
      u2[m2]:=i;
      dec(m2);
      dec(kc2[i]);
    end;
  end;
  for i:=1 to n do write(u1[i]);
  writeln;
  for i:=1 to n do write(u2[i]);
end.

var f1,f2:text;
A:array[1..100011] of longint;
D1,D2,kq1,kq2:array[1..100011] of longint;
s1,s2,ss1,ss2:array[0..10] of longint;
i,n,j,x:longint;
Found:boolean;
ch:char;
st:ansistring;
rem:longint;
res:longint;

Procedure try (vt,gt:longint);
var count:longint;
ok:boolean;
i,j:longint;
Begin
        ok:=false;
        i:=vt;
        count:=n-vt;
        if (s1[gt]>0) and (s2[10-gt]>0) then
        begin
          d1[vt]:=gt;
          d2[vt]:=10-gt;
          dec(s1[gt]);
          dec(s2[10-gt]);
          ok:=true;
          i:=vt-1;
        end;

        if ok then
        begin
          count:=count+1;
          for i:=vt-1 downto 1 do
          begin
            found:=false;
            for j:=0 to 9 do
            if (s1[j]>0) and (s2[9-j]>0) then
            begin
              found:=true;
              dec(s1[j]);
              dec(s2[9-j]);
              D1[i]:=j;
              D2[i]:=9-j;
              inc(count);
              break;
            end;
            if found=false then break;
          End;
        end;
        if found=false then
        for j:=i downto 1 do
        begin
          for x:=0 to 9 do
          if s1[x]>0 then begin D1[j]:=x;dec(s1[x]); break; end;
          for x:=0 to 9 do
          if s2[x]>0 then begin d2[j]:=x;dec(s2[x]); break; end;
        end;
        if count>res then
        begin
          res:=count;
          kq1:=d1;
          kq2:=d2;
        end;
End;

begin
        assign(f1,'');reset(f1);
        assign(f2,'');rewrite(F2);
        readln(f1,st);
        n:=length(st);
        for i:=1 to n do
        begin
          a[i]:=ord(st[i])-48;
          inc(s1[a[i]]);
          inc(s2[a[i]]);
        End;
        res:=-1;

          ss1:=s1;
          ss2:=s2;
          for j:=1 to 9 do
          Begin
          s1:=ss1;
          s2:=ss2;
          try(n,j);
          end;
        j:=0;
        for i:=1 to n do
        if (kq1[i]=0) and (kq2[i]=0) then inc(j);

        for i:=1 to n do
        if Not((Kq1[i]=0) and (kq2[i]=0)) then
          write(f2,kq1[i]);
        for i:=1 to j do write(f2,0);

          writeln(f2);
        for i:=1 to n do
        if Not((kq1[i]=0) and (kq2[i]=0)) then
          write(f2,kq2[i]);
        for i:=1 to j do write(f2,0);
        close(f1);
        close(f2);
end.

uses math;
var i,j,x,y,n,m,max,p,r,rez,ii,rp,rii: longint;
    b1,b2,o,rb1,rb2: array[0..10] of longint;
    c: char;
    s1,s2,r1,r2: ansistring;
    sve: boolean;
begin
     while not eoln do
      begin
       read(c);
       inc(b1[ord(c)-48]);
      end;
     o:=b1;
     b2:=b1;
     for ii:=0 to o[0] do
      begin
          b1:=o;
          b2:=o;
          dec(b1[0],ii);dec(b2[0],ii);
          if ii>0 then
           begin
            s1:='0'+s1;
            s2:='0'+s2;
           end;
          max:=ii;
          for i:=1 to 9 do
           begin
            if (b1[i]=0) or (b2[10-i]=0) then continue;
            dec(b1[i]);dec(b2[10-i]);
            x:=ii+1;
            for j:=0 to 9 do
             begin
              y:=min(b1[j],b2[9-j]);
              x:=x+y;
             end;
            if x>max then
             begin
              max:=x;
              p:=i;
             end;
            inc(b1[i]);inc(b2[10-i]);
           end;
          if max=ii then
           begin
            rez:=max;
            sve:=true;
            continue;
           end;
          if max<=rez then continue;
          sve:=false;
          rez:=max;
          rp:=p;
          rii:=ii;
          rb1:=b1;
          rb2:=b2;
          b1:=o;
          b2:=o;
      end;
     if sve then
      begin
       r1:='';r2:='';
       s1:='';
       for i:=1 to rii do s1:='0'+s1;
       s2:=s1;
       b1:=o;b2:=o;dec(b1[0],rii);dec(b2[0],rii);
       for i:=9 downto 0 do
          for j:=1 to b1[i] do r1:=r1+chr(i+48);
       r1:=r1+s1;
       for i:=9 downto 0 do
          for j:=1 to b2[i] do r2:=r2+chr(i+48);
       r2:=r2+s2;
       writeln(r1);
       writeln(r2);
       exit;
      end;
     s1:='';
     s2:='';
     for i:=1 to rii do s1:='0'+s1;
     s2:=s1;
     b1:=rb1;
     b2:=rb2;
     p:=rp;
     r1:=chr(p+48) + s1;
     r2:=chr(10-p+48) + s2;
     dec(b1[p]);dec(b2[10-p]);
     for i:=0 to 9 do
      begin
       y:=min(b1[i],b2[9-i]);
       for j:=1 to y do
        begin
         r1:=chr(i+48) + r1;
         r2:=chr(9-i+48) + r2;
        end;
       dec(b1[i],y);
       dec(b2[9-i],y);
      end;
     for i:=0 to 9 do
       for j:=1 to b1[i] do r1:=chr(i+48)+r1;
     for i:=0 to 9 do
       for j:=1 to b2[i] do r2:=chr(i+48)+r2;
     writeln(r1);
     writeln(r2);
end.

{$H+}

var a, b: array [0..100] of Int64;
    s: String;
    i, max, best, n: Longint;

procedure w(o: Longint);
var s1, s2: String;
    i, j, x: Longint;
Begin
    if o <> -1 then begin
    if (o = 5) then begin
        dec(a[o]);
        dec(b[o]);
        s1 := chr(o + 48);
        s2 := chr(o + 48);
    end
    else begin
        dec(a[o]);
        dec(b[10 - o]);
        s1 := chr(o + 48);
        s2 := chr(10 - o + 48);
    end;

    for i := 0 to 9 do begin
        x := a[i];
        if b[9 - i] < x then
            x := b[9 - i];
        a[i] := a[i] - x;
        b[9 - i] := b[9 - i] - x;
        for j := 1 to x do begin
            s1 := chr(i + 48) + s1;
            s2 := chr(9 - i + 48) + s2;
        end;
    end;
    end;

    x := a[0];
    if b[0] < x then
        x := b[0];
    a[0] := a[0] - x;
    b[0] := b[0] - x;
    for i := 1 to x do begin
        s1 := s1 + chr(48);
        s2 := s2 + chr(48);
    end;

    for i := 0 to 9 do
        for j := 1 to a[i] do
            s1 := chr(i + 48) + s1;
    for i := 0 to 9 do
        for j := 1 to b[i] do
            s2 := chr(i + 48) + s2;
    writeln(s1);
    writeln(s2);
End;

procedure src;
var x, sum, j, x1, x2: Longint;
    q: Boolean;
Begin
    sum := 1;
    x1 := a[0];
    x2 := b[0];
    for j := 0 to 9 do begin
        x := a[j];
        if b[9 - j] < x then
            x := b[9 - j];
        if j = 0 then
            x1 := x1 - x;
        if j = 9 then
            x2 := x2 - x;
        sum := sum + x;
    end;
    x := x1;
    if x2 < x then
        x := x2;
    sum := sum + x;

    if sum > max then begin
        best := i;
        max := sum;
    end;
End;

Begin
    readln(s);
    n := length(s);
    max := 0;
    for i := 1 to n do begin
        inc(a[ord(s[i]) - 48]);
        inc(b[ord(s[i]) - 48]);
    end;
    best := -1;
    for i := 1 to 9 do begin
        if (i = 5) then begin
            if (a[i] >= 1) and (b[i] >= 1) then begin
                b[i] := b[i] - 1;
                a[i] := a[i] - 1;
                src;
                a[i] := a[i] + 1;
                b[i] := b[i] + 1;
            end;
        end else begin
            if (a[i] >= 1) and (b[10 - i] >= 1) then begin
                dec(a[i]);
                dec(b[10 - i]);
                src;
                inc(a[i]);
                inc(b[10 - i]);
            end;
        end;
    end;
    w(best);
End.

{$apptype console}
uses SysUtils;

var s : string;
    c,c2 : array[0..9] of integer;

function min(a,b : integer) : integer;
begin
   result := a;
   if b < a then result := b;
end;

function GetCnt : integer;
var i: integer;
begin
  result := 0;
  for i := 0 to 9 do begin
     inc(result, min(c[i], c2[9-i]) );
  end;
end;

var i,j,max, imax, t,zc : integer;
    good: array[1..100001] of integer;
    gl : integer;
begin
{  reset( input, 'in.txt' );}
  {}
  readln( s );
  fillchar( c,sizeof(c), 0 );
  for i := 1 to length(s) do
     if s[i] in ['0'..'9'] then inc( c[ ord(s[i])-ord('0') ] );
  move(c,c2,sizeof(c));
{}
  max := -1; imax:= -1;
  for i := 1 to 5 do begin
     if (c[i] > 0) and (c2[10-i]>0) then begin
       dec(c[i]); dec(c2[10-i]);
       t := GetCnt();
       if t > max then begin imax := i; max :=t; end;
       inc(c[i]); inc(c2[10-i]);
     end;
  end;
{}
  if imax = -1 then begin
    for i := 1 to 9 do for j := 1 to c[i] do write(i);
    for i := 1 to c[0] do write(0);
{}
    writeln;
    for i := 1 to 9 do for j := 1 to c[i] do write(i);
    for i := 1 to c[0] do write(0);
  end else begin
     dec(c[imax]); dec(c2[10-imax]);
     gl := 0;
     for i := 0 to 9 do begin
        t := min(c[i], c2[9-i]);
        for j := 1 to t do begin
           inc(gl);
           good[gl] := i;
           dec(c[i]);
           dec(c2[9-i]);
        end;
     end;
{}
    zc := min(c[0], c2[0] );
    dec(c[0],zc); dec(c2[0],zc);
    for i := 0 to 9 do for j := 1 to c[i] do write(i);
    for i := 1 to gl do write( good[i] );
    write(imax);
    for i := 1 to zc do write(0);
    writeln;
{}
    for i := 0 to 9 do for j := 1 to c2[i] do write(i);
    for i := 1 to gl do write( 9-good[i] );
    write(10-imax);
    for i := 1 to zc do write(0);
  end;
end.

{$APPTYPE CONSOLE}
uses math;
var
  s:string;
  a,b1,b2,cr1,cr2:array[0..100001] of integer;
  c1,d1,c2,d2:array[0..9] of integer;
  nlm,z,sm,nl,mx,f,j,l,k,error,i,n:integer;

begin
 {reset(input,'Input.txt');
 rewrite(output,'Output.txt');}

 readln(s);

 n:=length(s);
 a[0]:=n;

 Fillchar(c1,sizeof(c1),0);
 Fillchar(c2,sizeof(c2),0);

 For i:=1 to n do
 begin
  val(s[i],a[i],error);
  inc(c1[a[i]]);
  inc(c2[a[i]]);
 end;

  mx:=-1;
  nlm:=0;

 For i:=1 to c1[0] do
 begin
  inc(cr1[0]);
  cr1[cr1[0]]:=0;
  cr2[cr1[0]]:=0;
 end;

 For i:=1 to 9 do
  For j:=1 to 9 do
  begin
   cr1[0]:=c1[0];
   d1:=c1;
   d2:=c2;
   nl:=c2[0];
   d1[0]:=0;
   d2[0]:=0;
  If (i+j=10) and (c1[i]>0) and (c2[j]>0) then
  begin
   inc(cr1[0]);
   dec(d1[i]);
   dec(d2[j]);
   cr1[cr1[0]]:=i;
   cr2[cr1[0]]:=j;
   inc(nl);

   For k:=0 to 9 do
    For l:=0 to 9 do
     If (k+l=9) then
     begin
      For f:=1 to min(d1[k],d2[l]) do
      begin
       inc(cr1[0]);
       cr1[cr1[0]]:=k;
       cr2[cr1[0]]:=l;
       inc(nl);
      end;
      z:=min(d1[k],d2[l]);
      d1[k]:=d1[k]-z;
      d2[l]:=d2[l]-z;
     end;
  end;
     z:=min(d1[0],d2[0]);
     d1[0]:=d1[0]-z;
     d2[0]:=d2[0]-z;
     nl:=nl+z;
   If nl>mx then
   begin
     nlm:=z;
     mx:=nl;
     cr2[0]:=cr1[0];

     For l:=0 to 9 do
      For k:=1 to d1[l] do
      begin
       inc(cr1[0]);
       cr1[cr1[0]]:=l;
      end;

     For l:=0 to 9 do
      For k:=1 to d2[l] do
      begin
       inc(cr2[0]);
       cr2[cr2[0]]:=l;
      end;

     b1:=cr1;
     b2:=cr2;
   end;
  end;

  For i:=1 to 9 do
  For j:=1 to 9 do
  begin
    cr1[0]:=0;
    d1:=c1;
    d2:=c2;
    nl:=0;
   If (i+j=10) and (c1[i]>0) and (c2[j]>0) then
   begin
    dec(d1[i]);
    dec(d2[j]);
    inc(cr1[0]);
    cr1[cr1[0]]:=i;
    cr2[cr1[0]]:=j;
    inc(nl);

    For k:=0 to 9 do
     For l:=0 to 9 do
      If (k+l=9) then
      begin
       For f:=1 to min(d1[k],d2[l]) do
       begin
        inc(cr1[0]);
        cr1[cr1[0]]:=k;
        cr2[cr1[0]]:=l;
        inc(nl);
       end;
       z:=min(d1[k],d2[l]);
       d1[k]:=d1[k]-z;
       d2[l]:=d2[l]-z;
      end;
   end;
     z:=min(d1[0],d2[0]);
     d1[0]:=d1[0]-z;
     d2[0]:=d2[0]-z;
     nl:=nl+z;
   If nl>mx then
    begin
      nlm:=z;
      mx:=nl;
      cr2[0]:=cr1[0];

      For l:=0 to 9 do
       For k:=1 to d1[l] do
       begin
        inc(cr1[0]);
        cr1[cr1[0]]:=l;
       end;

      For l:=0 to 9 do
       For k:=1 to d2[l] do
       begin
        inc(cr2[0]);
        cr2[cr2[0]]:=l;
       end;

      b1:=cr1;
      b2:=cr2;
    end;
  end;
 For i:=b1[0] downto 1 do write(b1[i]);
 For i:=1 to nlm do write(0);
 writeln;

 For i:=b2[0] downto 1 do write(b2[i]);
  For i:=1 to nlm do write(0);
 writeln;

end.

{$R+,Q+,I+}
{$apptype console}
Uses SysUtils;
Const
   Source='input.txt';
   Target='output.txt';
Function Min(a,b:Integer):Integer;
Begin
   If a<=b Then Min:=a
           Else Min:=b;
End;
Var
   a,p,r,x1,x2:Array[0..9] of Integer;
   i,j,f,n:Integer;
   c,t:Char;
   s1,s2:String;
Begin
   For i:=0 To 9 Do a[i]:=0;
   While not SeekEof Do Begin
      Read(c);
      i:=strtoint(c);
      a[i]:=a[i]+1;
   End;
   For i:=0 To 9 Do Begin
      x1[i]:=a[i];
      x2[i]:=a[i];
   End;
   For i:=0 To 9 Do p[i]:=Min(a[i],a[9-i]);
   For i:=0 To 9 Do r[i]:=a[i]-p[i];
   s1:='';
   s2:='';
   While r[0]>0 Do Begin
      s1:=s1+'0';
      s2:=s2+'0';
      r[0]:=r[0]-1;
      a[0]:=a[0]-1;
      x1[0]:=x1[0]-1;
      x2[0]:=x2[0]-1;
   End;
   f:=0;
   For i:=1 To 5 Do
      If (r[i]>0) and (r[10-i]>0) Then Begin
         f:=1;
         s1:=s1+inttostr(i);
         s2:=s2+inttostr(10-i);
         x1[i]:=x1[i]-1;
         x2[10-i]:=x2[10-i]-1;
         Break;
      End;
   If f=0 Then Begin
      For i:=1 To 5 Do
         If (a[i]>0) and (a[10-i]>0) Then Begin
            s1:=s1+inttostr(i);
            s2:=s2+inttostr(10-i);
            x1[i]:=x1[i]-1;
            x2[10-i]:=x2[10-i]-1;
            Break;
         End;
   End;
   For i:=0 To 9 Do
      While (x1[i]>0) and (x2[9-i]>0) Do Begin
         s1:=s1+inttostr(i);
         s2:=s2+inttostr(9-i);
         x1[i]:=x1[i]-1;
         x2[9-i]:=x2[9-i]-1;
      End;
   For i:=0 To 9 Do
      For j:=1 To x1[i] Do s1:=s1+inttostr(i);
   For i:=0 To 9 Do
      For j:=1 To x2[i] Do s2:=s2+inttostr(i);
   n:=length(s1);
   For i:=1 To n div 2 Do Begin
      t:=s1[i];
      s1[i]:=s1[n+1-i];
      s1[n+1-i]:=t;
      t:=s2[i];
      s2[i]:=s2[n+1-i];
      s2[n+1-i]:=t;
   End;
   WriteLn(s1);
   Write(s2);
End.

uses
    SysUtils, Math;

var
    i, ls, mx, l, r, cur, x, y, kk, j, zz : longint;
    a, b, c : array[0..10] of longint;
    p, q : array[0..100010] of longint;
    s : string;

function count(x, y : longint) : longint;

var
    i : longint;

begin
    dec(b[x]);
    dec(c[y]);
    result := 0;
    for i := 0 to 9 do
        inc(result, min(b[i], c[9 - i]));
    inc(b[x]);
    inc(c[y]);
end;

begin
    readln(s);
    fillchar(a, sizeof(a), 0);
    ls := length(s);
    for i := 1 to ls do
        inc(a[ord(s[i]) - 48]);
    b := a;
    c := a;
    l := -1;
    r := -1;
    mx := -1;
    for i := 1 to 5 do
        if (a[i] > 0) and (a[10 - i] > 0) then begin
            cur := count(i, 10 - i);
            if cur > mx then begin
                mx := cur;
                l := i;
                r := 10 - i;
            end;
        end;
    x := 1;
    if l > -1 then begin
        dec(b[l]);
        dec(c[r]);
        p[x] := l;
        q[x] := r;
        inc(x);
    end;
    for i := 0 to 9 do begin
        kk := min(b[i], c[9 - i]);
        for j := 1 to kk do begin
            p[x] := i;
            q[x] := 9 - i;
            inc(x);
        end;
        dec(b[i], kk);
        dec(c[9 - i], kk);
    end;
    zz := min(b[0], c[0]);
    y := x;
    for i := 1 to 9 do begin
        for j := 1 to b[i] do begin
            p[x] := i;
            inc(x);
        end;
        for j := 1 to c[i] do begin
            q[y] := i;
            inc(y);
        end;
    end;
    for i := ls - zz downto 1 do
        write(p[i]);
    for i := 1 to zz do
        write(0);
    writeln;
    for i := ls - zz downto 1 do
        write(q[i]);
    for i := 1 to zz do
        write(0);
end.

program task4;

{$APPTYPE CONSOLE}

uses
  SysUtils, Math;
type dd=array [0..9] of longint;
var
A,A1,A2:dd;
B1,B2:array [1..100010] of longint;
s:string;
i,c,k1,k2,j,k:longint;

procedure print;
var
i:longint;
begin
for i:=k1 downto 1 do
 begin
  write(B1[i]);
 end;
 writeln;
for i:=k2 downto 1 do
 begin
  write(b2[i]);
 end;
writeln;
end;

begin      {
assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);  }
readln(s);
for i:=0 to 9 do
 begin
  A[i]:=0;
 end;
for i:=1 to length(s) do
 begin
  c:=ord(s[i])-48;
  inc(A[c]);
 end;
k:=0;
while A[0]>0 do
 begin
  dec(A[0]);
  inc(k);
  B1[k]:=0;
  B2[k]:=0;
 end;
A1:=A;
A2:=A;
if (A[1]>0) and (A[9]>0) then
 begin
  dec(A1[1]);
  dec(A2[9]);
  inc(k);
  B1[k]:=1;
  B2[k]:=9;
 end;
for i:=1 to 8 do
 begin
  if (A1[i]>0) and (A2[9-i]>0) then
   begin
    dec(A1[i]);
    dec(A2[9-i]);
    inc(k);
    B1[k]:=i;
    B2[k]:=9-i;
   end;
 end;
 k1:=k;
 k2:=k;
for i:=0 to 9 do
 begin
   for j:=1 to A1[i] do
    begin
     inc(k1);
     B1[k1]:=i;
    end;
      for j:=1 to A2[i] do
    begin
     inc(k2);
     B2[k2]:=i;
    end;
 end;
print;

  { TODO -oUser -cConsole Main : Insert code here }
end.

program task4;

{$APPTYPE CONSOLE}

uses
  SysUtils, Math;
type dd=array [0..9] of longint;
var
A,A1,A2:dd;
B1,B2:array [1..100010] of longint;
s:string;
i,c,k1,k2,j,k:longint;

procedure print;
var
i:longint;
begin
for i:=k1 downto 1 do
 begin
  write(B1[i]);
 end;
 writeln;
for i:=k2 downto 1 do
 begin
  write(b2[i]);
 end;
writeln;
end;

begin       {
assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);}
readln(s);
for i:=0 to 9 do
 begin
  A[i]:=0;
 end;
for i:=1 to length(s) do
 begin
  c:=ord(s[i])-48;
  inc(A[c]);
 end;
k:=0;
while A[0]>0 do
 begin
  dec(A[0]);
  inc(k);
  B1[k]:=0;
  B2[k]:=0;
 end;
A1:=A;
A2:=A;
if (A[1]>0) and (A[9]>0) then
 begin
  dec(A1[1]);
  dec(A2[9]);
  inc(k);
  B1[k]:=1;
  B2[k]:=9;
 end else
if (A[2]>0) and (A[8]>0) then
 begin
  dec(A1[2]);
  dec(A2[8]);
  inc(k);
  B1[k]:=2;
  B2[k]:=8;
 end else
if (A[3]>0) and (A[7]>0) then
 begin
  dec(A1[3]);
  dec(A2[7]);
  inc(k);
  B1[k]:=3;
  B2[k]:=7;
 end else
if (A[4]>0) and (A[6]>0) then
 begin
  dec(A1[4]);
  dec(A2[6]);
  inc(k);
  B1[k]:=4;
  B2[k]:=6;
 end else
if (A[5]>0) and (A[5]>0) then
 begin
  dec(A1[5]);
  dec(A2[5]);
  inc(k);
  B1[k]:=5;
  B2[k]:=5;
 end;
for i:=1 to 8 do
 begin
  while (A1[i]>0) and (A2[9-i]>0) do
   begin
    dec(A1[i]);
    dec(A2[9-i]);
    inc(k);
    B1[k]:=i;
    B2[k]:=9-i;
   end;
 end;
 k1:=k;
 k2:=k;
for i:=0 to 9 do
 begin
   for j:=1 to A1[i] do
    begin
     inc(k1);
     B1[k1]:=i;
    end;
      for j:=1 to A2[i] do
    begin
     inc(k2);
     B2[k2]:=i;
    end;
 end;
print;

  { TODO -oUser -cConsole Main : Insert code here }
end.

program task4;

{$APPTYPE CONSOLE}

uses
  SysUtils, Math;
type dd=array [0..9] of longint;
var
A,A1,A2:dd;
B1,B2:array [1..100010] of longint;
s:string;
i,c,k1,k2,j,k,x,y,z,q:longint;

procedure print;
var
i:longint;
begin
for i:=k1 downto 1 do
 begin
  write(B1[i]);
 end;
 writeln;
for i:=k2 downto 1 do
 begin
  write(b2[i]);
 end;
writeln;
end;

function kp:longint;
var
i:longint;
begin
result:=0;
for i:=0 to 9 do
 begin
  inc(result,min(A1[i],A2[9-i]));
 end;
end;

begin          {
assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output); }
readln(s);
for i:=0 to 9 do
 begin
  A[i]:=0;
 end;
for i:=1 to length(s) do
 begin
  c:=ord(s[i])-48;
  inc(A[c]);
 end;
k:=0;
while A[0]>0 do
 begin
  dec(A[0]);
  inc(k);
  B1[k]:=0;
  B2[k]:=0;
 end;
A1:=A;
A2:=A;
z:=-1;
x:=-1;
y:=-1;
if (A[1]>0) and (A[9]>0) then
 begin
  dec(A1[1]);
  dec(A2[9]);
  q:=kp;
  inc(A1[1]);
  inc(A2[9]);
  if q>z then
   begin
    z:=q;
    x:=1;
    y:=9;
   end;
 end;
if (A[2]>0) and (A[8]>0) then
 begin
  dec(A1[2]);
  dec(A2[8]);
  q:=kp;
  inc(A1[2]);
  inc(A2[8]);
    if q>z then
   begin
    z:=q;
    x:=2;
    y:=8;
   end;
 end ;
if (A[3]>0) and (A[7]>0) then
 begin
  dec(A1[3]);
  dec(A2[7]);
  q:=kp;
  inc(A1[3]);
  inc(A2[7]);
    if q>z then
   begin
    z:=q;
    x:=3;
    y:=7;
   end;
 end;
if (A[4]>0) and (A[6]>0) then
 begin
  dec(A1[4]);
  dec(A2[6]);
  q:=kp;
  inc(A1[4]);
  inc(A2[6]);
    if q>z then
   begin
    z:=q;
    x:=4;
    y:=6;
   end;
 end ;
if (A[5]>0) and (A[5]>0) then
 begin
  dec(A1[5]);
  dec(A2[5]);
  q:=kp;
  inc(A1[5]);
  inc(A2[5]);
    if q>z then
   begin
    z:=q;
    x:=5;
    y:=5;
   end;
 end;
if x<>-1 then
 begin
  inc(k);
  dec(A1[x]);
  dec(A2[y]);
  B1[k]:=x;
  B2[k]:=y;
 end;
for i:=1 to 8 do
 begin
  while (A1[i]>0) and (A2[9-i]>0) do
   begin
    dec(A1[i]);
    dec(A2[9-i]);
    inc(k);
    B1[k]:=i;
    B2[k]:=9-i;
   end;
 end;
 k1:=k;
 k2:=k;
for i:=0 to 9 do
 begin
   for j:=1 to A1[i] do
    begin
     inc(k1);
     B1[k1]:=i;
    end;
      for j:=1 to A2[i] do
    begin
     inc(k2);
     B2[k2]:=i;
    end;
 end;
print;

  { TODO -oUser -cConsole Main : Insert code here }
end.

var mn,q,i,l,k,m,j,h:longint;
    a,b:array[0..9] of longint;
    s,c:string;
function posh:longint;
var w,i:longint;
begin
w:=0;
for i:=0 to 4 do
begin
k:=b[i];
if k>a[9-i] then k:=a[9-i];
w:=w+k;
end;
k:=b[9];
if k>a[0] then k:=a[0];
w:=w+k;
posh:=w;
end;
begin
readln(s);
for i:=1 to length(s) do
inc(a[ord(s[i])-48]);
for i:=0 to 9 do b[i]:=a[i];

for i:=1 to 5 do
if (a[i]>0) and (b[10-i]>0) then
begin
dec(a[i]);
dec(b[10-i]);
m:=posh+1;
if m>mn then
begin
mn:=m;
q:=i;
end;
inc(a[i],1);
inc(b[10-i],1);
end;

if q=0 then
begin
for i:=1 to 9 do
for l:=1 to a[i] do write(i);
for l:=1 to a[0] do write(0);
writeln;
for i:=1 to 9 do
for l:=1 to b[i] do write(i);
for l:=1 to b[0] do write(0);
writeln;
end else
begin
dec(mn);
dec(a[q]);
dec(b[10-q]);
s:='';
c:='';

for i:=0 to 4 do
begin
k:=b[i];
if k>a[9-i] then k:=a[9-i];
for l:=1 to k do
begin
s:=s+chr(i+48);
dec(b[i]);
dec(a[9-i]);
c:=c+chr(9-i+48);
end;
end;
k:=b[9];
if k>a[0] then k:=a[0];
for l:=1 to k do
begin
s:=s+chr(9+48);
dec(b[9]);
dec(a[0]);
c:=c+chr(48);
end;
for i:=1 to a[0]-b[0] do begin dec(a[0]); c:='0'+c; end;
for i:=1 to b[0]-a[0] do begin dec(b[0]); s:='0'+s; end;
c:=c+chr(q+48);
s:=s+chr(10-q+48);
for i:=1 to 9 do
for l:=1 to b[i] do write(i);
write(s);
for l:=1 to b[0] do write(0);
writeln;
for i:=1 to 9 do
for l:=1 to a[i] do write(i);
write(c);
for l:=1 to a[0] do write(0);
writeln;
end;
end.

var mn,q,i,l,k,m,j,h:longint;
    a,b:array[0..9] of longint;
    s,c:string;
function posh:longint;
var w,i:longint;
begin
w:=0;
for i:=1 to 4 do
begin
k:=b[i];
if k>a[9-i] then k:=a[9-i];
w:=w+k;
end;
posh:=w;
end;
begin
readln(s);
for i:=1 to length(s) do
inc(a[ord(s[i])-48]);
for i:=0 to 9 do b[i]:=a[i];

for i:=1 to 9 do
if (a[i]>0) and (b[10-i]>0) then
begin
dec(a[i],1);
dec(b[10-i],1);
m:=posh;
if m>mn then
begin
mn:=m;
q:=i;
end;
inc(a[i],1);
inc(b[10-i],1);
end;

if q=0 then
begin
for i:=1 to 9 do
for l:=1 to a[i] do write(i);
for l:=1 to a[0] do write(0);
writeln;
for i:=1 to 9 do
for l:=1 to b[i] do write(i);
for l:=1 to b[0] do write(0);
writeln;
end else
begin
dec(a[q]);
dec(b[10-q]);
s:='';
c:='';

for i:=1 to 4 do
begin
k:=b[i];
if k>a[9-i] then k:=a[9-i];
for l:=1 to k do
begin
s:=s+chr(i+48);
dec(b[i]);
dec(a[9-i]);
c:=c+chr(9-i+48);
end;
end;
c:=c+chr(q+48);
s:=s+chr(10-q+48);
for i:=1 to 9 do
for l:=1 to b[i] do write(i);
write(s);
for l:=1 to b[0] do write(0);
writeln;
for i:=1 to 9 do
for l:=1 to a[i] do write(i);
write(c);
for l:=1 to a[0] do write(0);
writeln;
end;
end.

var mn,q,i,l,k,m,j,h:longint;
    a,b:array[0..9] of longint;
    s,c:string;
function posh:longint;
var w,i:longint;
begin
w:=0;
for i:=1 to 4 do
begin
k:=b[i];
if k>a[9-i] then k:=a[9-i];
w:=w+k;
end;
posh:=w;
end;
begin
readln(s);
for i:=1 to length(s) do
inc(a[ord(s[i])-48]);
for i:=0 to 9 do b[i]:=a[i];

for i:=1 to 5 do
if (a[i]>0) and (b[10-i]>0) then
begin
dec(a[i]);
dec(b[10-i]);
m:=posh+1;
if m>mn then
begin
mn:=m;
q:=i;
end;
inc(a[i],1);
inc(b[10-i],1);
end;

if q=0 then
begin
for i:=1 to 9 do
for l:=1 to a[i] do write(i);
for l:=1 to a[0] do write(0);
writeln;
for i:=1 to 9 do
for l:=1 to b[i] do write(i);
for l:=1 to b[0] do write(0);
writeln;
end else
begin
dec(mn);
dec(a[q]);
dec(b[10-q]);
s:='';
c:='';

for i:=1 to 4 do
begin
k:=b[i];
if k>a[9-i] then k:=a[9-i];
for l:=1 to k do
begin
s:=s+chr(i+48);
dec(b[i]);
dec(a[9-i]);
c:=c+chr(9-i+48);
end;
end;
c:=c+chr(q+48);
s:=s+chr(10-q+48);
for i:=1 to 9 do
for l:=1 to b[i] do write(i);
write(s);
for l:=1 to b[0] do write(0);
writeln;
for i:=1 to 9 do
for l:=1 to a[i] do write(i);
write(c);
for l:=1 to a[0] do write(0);
writeln;
end;
end.

var mn,q,i,l,k,m,j,h:longint;
    a,b:array[0..9] of longint;
    s,c:string;
function posh:longint;
var w,i:longint;
begin
w:=0;
for i:=0 to 4 do
begin
k:=b[i];
if k>a[9-i] then k:=a[9-i];
w:=w+k;
end;
posh:=w;
end;
begin
readln(s);
for i:=1 to length(s) do
inc(a[ord(s[i])-48]);
for i:=0 to 9 do b[i]:=a[i];

for i:=1 to 5 do
if (a[i]>0) and (b[10-i]>0) then
begin
dec(a[i]);
dec(b[10-i]);
m:=posh+1;
if m>mn then
begin
mn:=m;
q:=i;
end;
inc(a[i],1);
inc(b[10-i],1);
end;

if q=0 then
begin
for i:=1 to 9 do
for l:=1 to a[i] do write(i);
for l:=1 to a[0] do write(0);
writeln;
for i:=1 to 9 do
for l:=1 to b[i] do write(i);
for l:=1 to b[0] do write(0);
writeln;
end else
begin
dec(mn);
dec(a[q]);
dec(b[10-q]);
s:='';
c:='';

for i:=0 to 4 do
begin
k:=b[i];
if k>a[9-i] then k:=a[9-i];
for l:=1 to k do
begin
s:=s+chr(i+48);
dec(b[i]);
dec(a[9-i]);
c:=c+chr(9-i+48);
end;
end;
c:=c+chr(q+48);
s:=s+chr(10-q+48);
for i:=1 to 9 do
for l:=1 to b[i] do write(i);
write(s);
for l:=1 to b[0] do write(0);
writeln;
for i:=1 to 9 do
for l:=1 to a[i] do write(i);
write(c);
for l:=1 to a[0] do write(0);
writeln;
end;
end.

{$APPTYPE CONSOLE}

uses
  Math;
var
  tc1,tc2:array[0..9]of integer;
  ans1,ans2:array[1..100000]of byte;
  ch:char;
  i,j,k,tmp,c1,c2:integer;

function pod:integer;
var
  l,i:integer;
begin
  l:=0;
  for i:=0 to 9 do
    l:=l+min(tc1[i],tc2[9-i]);
  pod:=l;
end;

begin
  for j:=0 to 9 do
      tc1[j]:=0;
  read(ch);
  while (ch in ['0'..'9'])do
  begin
    inc(tc1[ord(ch)-ord('0')]);
    read(ch);
  end;
  k:=-maxint;
  i:=0;
  while i<=5 do
  begin
    dec(tc1[i]);
    dec(tc2[(10-i)mod 10]);
    tmp:=pod;
    inc(tc1[i]);
    inc(tc2[(10-i)mod 10]);
    if tmp>k then
    begin
      c1:=i;
      c2:=(10-i)mod 10;
      k:=tmp;
    end;
    inc(i);
  end;

  ans1[1]:=c1;
  ans2[1]:=c2;
  k:=1;
  for i:=0 to 9 do
    tc2[i]:=tc1[i];
  dec(tc1[c1]);
  dec(tc2[c2]);

  for i:=0 to 9 do
    while (tc1[i]>0)and(tc2[9-i]>0)do
    begin
      inc(k);
      dec(tc1[i]);
      dec(tc2[9-i]);
      ans1[k]:=i;
      ans2[k]:=9-i;
    end;
  c1:=k;
  c2:=k;
  for i:=0 to 9 do
    while tc1[i]>0 do
    begin
      inc(c1);
      ans1[c1]:=i;
      dec(tc1[i]);
    end;
  for i:=0 to 9 do
    while tc2[i]>0 do
    begin
      inc(c2);
      ans2[c2]:=i;
      dec(tc2[i]);
    end;

  for i:=c1 downto 1 do
    write(ans1[i]);
  writeln;
  for i:=c2 downto 1 do
    write(ans2[i]);
end.

{$APPTYPE CONSOLE}

uses
  Math;
var
  tc1,tc2:array[0..9]of integer;
  ans1,ans2:array[1..100000]of byte;
  ch:char;
  i,j,k,tmp,c1,c2:integer;

function pod:integer;
var
  l,i:integer;
begin
  l:=0;
  for i:=0 to 9 do
    l:=l+min(tc1[i],tc2[9-i]);
  pod:=l;
end;

begin
  for j:=0 to 9 do
      tc1[j]:=0;
  read(ch);
  while (ch in ['0'..'9'])do
  begin
    inc(tc1[ord(ch)-ord('0')]);
    read(ch);
  end;
  for i:=0 to 9 do
    tc2[i]:=tc1[i];
  k:=-maxint;
  i:=0;
  c1:=-1;
  while i<=5 do
  begin
    if (tc1[i]>0)and(tc2[(10-i)mod 10]>0)then
    begin
      dec(tc1[i]);
      dec(tc2[(10-i)mod 10]);
      tmp:=pod;
      inc(tc1[i]);
      inc(tc2[(10-i)mod 10]);
      if tmp>k then
      begin
        c1:=i;
        c2:=(10-i)mod 10;
        k:=tmp;
      end;
    end;
    inc(i);
  end;
  k:=0;
  if c1<>-1 then begin
  ans1[1]:=c1;
  ans2[1]:=c2;
  k:=1;
  dec(tc1[c1]);
  dec(tc2[c2]);

  for i:=0 to 9 do
    while (tc1[i]>0)and(tc2[9-i]>0)do
    begin
      inc(k);
      dec(tc1[i]);
      dec(tc2[9-i]);
      ans1[k]:=i;
      ans2[k]:=9-i;
    end;
  end;
  c1:=k;
  c2:=k;
  for i:=0 to 9 do
    while tc1[i]>0 do
    begin
      inc(c1);
      ans1[c1]:=i;
      dec(tc1[i]);
    end;
  for i:=0 to 9 do
    while tc2[i]>0 do
    begin
      inc(c2);
      ans2[c2]:=i;
      dec(tc2[i]);
    end;

  for i:=c1 downto 1 do
    write(ans1[i]);
  writeln;
  for i:=c2 downto 1 do
    write(ans2[i]);
end.

program D;

{$APPTYPE CONSOLE}
uses Math, SysUtils;
var s,s1,s2: string;
    a,b: array[0..9]of integer;
    i,j,n: integer;
    ok: boolean;

procedure check(x,y: integer);
begin
  if (a[x]>0)and(b[y]>0)then begin
    dec(a[x]);
    s1:=inttostr(x)+s1;
    s2:=inttostr(y)+s2;
    dec(b[y]);
    ok:=true;
  end;
end;
begin
  s1:='';s2:='';
  readln(s);
  n:=length(s);
  for i:=0 to 9 do begin
    a[i]:=0;
    b[i]:=0;
  end;
  for i:=1 to n do begin
    inc(a[ord(s[i])-ord('0')]);
    inc(b[ord(s[i])-ord('0')]);
  end;
  ok:=false;
  check(2,8);
  if (not ok)then check(3,7);
  if (not ok)then check(4,6);
  if (not ok)then check(5,5);
  if (not ok)then check(9,1);
  for i:=0 to 9 do
    while (a[i]>0)and(b[9-i]>0)do begin
      s1:=inttostr(i)+s1;
      s2:=inttostr(9-i)+s2;
      dec(a[i]);dec(b[9-i]);
    end;
  while (a[0]>0)and(b[0]>0)do begin
    s1:=s1+'0';
    s2:=s2+'0';
    dec(a[0]);dec(b[0]);
  end;
  for i:=0 to 9 do begin
    while (a[i]>0)do begin
      s1:=inttostr(i)+s1;
      dec(a[i]);
    end;
    while (b[i]>0)do begin
      s2:=inttostr(i)+s2;
      dec(b[i]);
    end;
  end;
  writeln(s1);
  writeln(s2);
end.

const   MAX_N = 100010;

var fi,fo:text;
    s,t:ansiString;
    n,i,j,rp,rf,r0:longint;
    c,c2:array[0..9] of longint;

function    min(x,y:longint):longint;   begin   if x < y then exit(x)   else exit(y);   end;

procedure   update(x,y:longint);
begin
    s:=chr(x+ord('0'))+s;   dec(c[x]);
    t:=chr(y+ord('0'))+t;   dec(c2[y]);
end;

procedure   solve(x,y,z:longint);
var i,f:longint;
begin
    if (c[x] < 1) or (c2[y] < 1) then exit;
    dec(c[x]);  dec(c2[y]);
    dec(c[0],z);    dec(c2[0],z);
    f:=z;
    for i:=0 to 9 do f:=f+min(c[i],c2[9-i]);
    f:=f+c[0]-min(c[0],c2[9]);
    if f > 0 then begin
        rf:=f;
        rp:=x;
        r0:=z;
    end;
    inc(c[0],z);    inc(c2[0],z);
    inc(c[x]);  inc(c2[y]);
end;

begin
    assign(fi,'');   reset(fi);
    assign(fo,'');  rewrite(fo);
    readln(fi,s);
    n:=length(s);
    for i:=0 to 9 do c[i]:=0;
    for i:=1 to n do inc(c[ord(s[i])-ord('0')]);
    c2:=c;
    rf:=0; rp:=-1; r0:=0;
    for j:=0 to c[0] do
        for i:=1 to 5 do
            solve(i,10-i,j);
    s:='';  t:='';
    for i:=1 to r0 do update(0,0);
    if rp > 0 then begin
        update(rp,10-rp);
        for i:=0 to 9 do
            while (c[i] > 0) and (c2[9-i] > 0) do update(i,9-i);
    end;
    while (c[0] > 0) and (c2[0] > 0) do begin
        s:=s+'0'; dec(c[0]);
        t:=t+'0'; dec(c2[0]);
    end;
    for i:=1 to 9 do
        while (c[i] > 0) and (c2[10-i] > 0) do update(i,10-i);
    for i:=0 to 9 do begin
        while c[i] > 0 do begin s:=chr(i+ord('0'))+s;   dec(c[i]);  end;
        while c2[i] > 0 do begin t:=chr(i+ord('0'))+t;   dec(c2[i]);  end;
    end;
    writeln(fo,s);
    writeln(fo,t);
    close(fo);
    close(fi);
end.

const   MAX_N = 100010;

var fi,fo:text;
    s,t:ansiString;
    n,i,j,rp,rf,r0:longint;
    c,c2:array[0..9] of longint;

function    min(x,y:longint):longint;   begin   if x < y then exit(x)   else exit(y);   end;

procedure   update(x,y:longint);
begin
    s:=chr(x+ord('0'))+s;   dec(c[x]);
    t:=chr(y+ord('0'))+t;   dec(c2[y]);
end;

procedure   solve(x,y,z:longint);
var i,f:longint;
begin
    if (c[x] < 1) or (c2[y] < 1) then exit;
    dec(c[x]);  dec(c2[y]);
    dec(c[0],z);    dec(c2[0],z);
    f:=z;
    for i:=0 to 9 do f:=f+min(c[i],c2[9-i]);
    f:=f+c[0]-min(c[0],c2[9]);
    if f > rf then begin
        rf:=f;
        rp:=x;
        r0:=z;
    end;
    inc(c[0],z);    inc(c2[0],z);
    inc(c[x]);  inc(c2[y]);
end;

begin
    assign(fi,'');   reset(fi);
    assign(fo,'');  rewrite(fo);
    readln(fi,s);
    n:=length(s);
    for i:=0 to 9 do c[i]:=0;
    for i:=1 to n do inc(c[ord(s[i])-ord('0')]);
    c2:=c;
    rf:=0; rp:=-1; r0:=0;
    for j:=0 to c[0] do
        for i:=1 to 5 do
            solve(i,10-i,j);
    s:='';  t:='';
    for i:=1 to r0 do update(0,0);
    if rp > 0 then begin
        update(rp,10-rp);
        for i:=0 to 9 do
            while (c[i] > 0) and (c2[9-i] > 0) do update(i,9-i);
    end;
    while (c[0] > 0) and (c2[0] > 0) do begin
        s:=s+'0'; dec(c[0]);
        t:=t+'0'; dec(c2[0]);
    end;
    for i:=1 to 9 do
        while (c[i] > 0) and (c2[10-i] > 0) do update(i,10-i);
    for i:=0 to 9 do begin
        while c[i] > 0 do begin s:=chr(i+ord('0'))+s;   dec(c[i]);  end;
        while c2[i] > 0 do begin t:=chr(i+ord('0'))+t;   dec(c2[i]);  end;
    end;
    writeln(fo,s);
    writeln(fo,t);
    close(fo);
    close(fi);
end.

const   MAX_N = 100010;

var fi,fo:text;
    s,t:ansiString;
    n,i,j,rp,rf:longint;
    c,c2:array[0..9] of longint;

function    min(x,y:longint):longint;   begin   if x < y then exit(x)   else exit(y);   end;

procedure   update(x,y:longint);
begin
    s:=chr(x+ord('0'))+s;   dec(c[x]);
    t:=chr(y+ord('0'))+t;   dec(c2[y]);
end;

procedure   solve(x,y:longint);
var i,f:longint;
begin
    if (c[x] < 1) or (c2[y] < 1) then exit;
    dec(c[x]);  dec(c2[y]);
    f:=0;
    for i:=0 to 9 do f:=f+min(c[i],c2[9-i]);
    if f > 0 then begin
        rf:=f;
        rp:=x;
    end;
    inc(c[x]);  inc(c2[y]);
end;

begin
    assign(fi,'');   reset(fi);
    assign(fo,'');  rewrite(fo);
    readln(fi,s);
    n:=length(s);
    for i:=0 to 9 do c[i]:=0;
    for i:=1 to n do inc(c[ord(s[i])-ord('0')]);
    c2:=c;
    rf:=0; rp:=-1;
    for i:=1 to 5 do solve(i,10-i);
    s:='';  t:='';
    if rp > 0 then begin
        update(rp,10-rp);
        for i:=0 to 9 do
            while (c[i] > 0) and (c2[9-i] > 0) do update(i,9-i);
    end;
    for i:=1 to 9 do
        while (c[i] > 0) and (c2[10-i] > 0) do update(i,10-i);
    for i:=1 to 9 do begin
        while c[i] > 0 do begin s:=chr(i+ord('0'))+s;   dec(c[i]);  end;
        while c2[i] > 0 do begin t:=chr(i+ord('0'))+t;   dec(c2[i]);  end;
    end;
    while c[0] > 0 do begin s:=s+'0';   dec(c[0]);  end;
    while c2[0] > 0 do begin    t:=t+'0';   dec(c2[0]); end;
    writeln(fo,s);
    writeln(fo,t);
    close(fo);
    close(fi);
end.

const   MAX_N = 100010;

var fi,fo:text;
    s,t:ansiString;
    n,i,j,rp,rf:longint;
    c,c2:array[0..9] of longint;

function    min(x,y:longint):longint;   begin   if x < y then exit(x)   else exit(y);   end;

procedure   update(x,y:longint);
begin
    s:=chr(x+ord('0'))+s;   dec(c[x]);
    t:=chr(y+ord('0'))+t;   dec(c2[y]);
end;

procedure   solve(x,y:longint);
var i,f:longint;
begin
    if (c[x] < 1) or (c2[y] < 1) then exit;
    dec(c[x]);  dec(c2[y]);
    f:=0;
    for i:=0 to 9 do f:=f+min(c[i],c2[9-i]);
    f:=f+c[0]-min(c[0],c2[9]);
    if f > 0 then begin
        rf:=f;
        rp:=x;
    end;
    inc(c[x]);  inc(c2[y]);
end;

begin
    assign(fi,'');   reset(fi);
    assign(fo,'');  rewrite(fo);
    readln(fi,s);
    n:=length(s);
    for i:=0 to 9 do c[i]:=0;
    for i:=1 to n do inc(c[ord(s[i])-ord('0')]);
    c2:=c;
    rf:=0; rp:=-1;
    for i:=1 to 5 do solve(i,10-i);
    s:='';  t:='';
    if rp > 0 then begin
        update(rp,10-rp);
        for i:=0 to 9 do
            while (c[i] > 0) and (c2[9-i] > 0) do update(i,9-i);
    end;
    for i:=1 to 9 do
        while (c[i] > 0) and (c2[10-i] > 0) do update(i,10-i);
    while (c[0] > 0) and (c2[0] > 0) do begin
        s:=s+'0'; dec(c[0]);
        t:=t+'0'; dec(c2[0]);
    end;
    for i:=0 to 9 do begin
        while c[i] > 0 do begin s:=chr(i+ord('0'))+s;   dec(c[i]);  end;
        while c2[i] > 0 do begin t:=chr(i+ord('0'))+t;   dec(c2[i]);  end;
    end;
    writeln(fo,s);
    writeln(fo,t);
    close(fo);
    close(fi);
end.

program digits_permut;

uses math;
const
  fi='';
  fo='';
  tt = ord('0');
  oo = trunc(1e9);
type
  stri = ansistring;
var
  n:stri;
  a1,a2,b1,b2:array[0..9] of longint;
  s1,s2:stri;
procedure openfile;
var
  i:longint;
begin
  assign(input,fi);reset(input);
  assign(output,fo);rewrite(output);
  readln(n);
  fillchar(a1,sizeof(a1),0);
  for i:=1 to length(n) do
    begin
      inc(a1[ord(n[i])-tt]);
    end;
  a2:=a1;
end;
//-------------------
procedure process;
var
  i,j:longint;
  s,p:longint;
  kq,jm:longint;
begin
  kq:=-oo;
  for i:=1 to 9 do
  if (a1[i]>0)and(a2[10-i]>0) then
    begin
      b1:=a1;
      b2:=a2;
      s:=1;
      dec(b1[i]);dec(b2[10-i]);
      for j:=0 to 9 do
        begin
          p:=min(b1[j],b2[9-j]);
          dec(b1[j],p);dec(b2[9-j],p);
          s:=s+p;
        end;
      inc(s,min(b1[0],b2[0]));
      if s>kq then
        begin
          kq:=s;
          jm:=i;
        end;
    end;
  if kq=-oo then
    begin
      writeln(n);
      writeln(n);
      exit;
    end;
  s1:='';s2:='';
  dec(a1[jm]);
  dec(a2[10-jm]);
  for i:=1 to 1 do
    begin
      s1:=chr(jm+tt)+s1;
      s2:=chr(10-jm+tt)+s2;
    end;
  for i:=0 to 9 do
    begin
      p:=min(a1[i],a2[9-i]);
      dec(a1[i],p);dec(a2[9-i],p);
      for j:=1 to p do
        begin
          s1:=chr(i+tt)+s1;
          s2:=chr(9-i+tt)+s2;
        end;
    end;
  p:=min(a1[0],a2[0]);
  dec(a1[0],p);dec(a2[0],p);
    for i:=1 to p do
      begin
        s1:=s1+'0';
        s2:=s2+'0';
      end;
  for i:=0 to 9 do
    begin
      if a1[i]>0 then
        for j:=1 to a1[i] do s1:=chr(i+tt)+s1;
      if a2[i]>0 then
        for j:=1 to a2[i] do s2:=chr(i+tt)+s2;
    end;
  writeln(s1);
  writeln(s2);
end;
//--------------------
BEGIN
  openfile;
  process;
END.

uses math;
var
        i,n,count,j,t,res,ires,mres,tmp: longint;
        s: ansistring;
        r1,r2: array[0..9,0..100000] of longint;
        c,d,e: array[0..9] of longint;
        ck: boolean;
begin
        readln(s);
        for i:=1 to length(s) do
        begin
                inc(d[ord(s[i])-48]);
        end;
        n:=length(s);

        for i:=1 to 9 do
        begin
                c:=d;
                e:=d;

                count:=0;

                if ((c[i]<1) or (e[10-i]<1)) then continue;
                dec(c[i]); dec(e[10-i]);
                r1[i,1]:=i; r2[i,1]:=10-i;
                ck:=true;
                for j:=2 to n do
                begin
                        if ck=true then
                        begin
                        ck:=false;
                        for t:=0 to 9 do
                        begin
                                if (c[t]>0) and (e[9-t]>0) then
                                begin
                                        inc(count);
                                        cK:=true;
                                        dec(c[t]); dec(e[9-t]);
                                        r1[i,j]:=t; r2[i,j]:=9-t;
                                        if count>res then
                                        begin
                                                res:=count;
                                                ires:=i;
                                                mres:=0;
                                        end;
                                        break;
                                end;
                        end;
                        end;
                        if not ck then
                        begin
                                tmp:=math.min(c[0],e[0]);
                                c[0]:=c[0]-tmp;
                                e[0]:=e[0]-tmp;
                                if count+tmp>res then
                                begin
                                        res:=count+tmp;
                                        ires:=i;
                                        mres:=tmp;
                                end;
                                for t:=0 to 9 do
                                begin
                                        if (c[t]>0)and(r1[i,j]=0) then
                                        begin
                                                r1[i,j]:=t;
                                                dec(c[t]);
                                        end;
                                        if (e[t]>0)and(r2[i,j]=0) then
                                        begin
                                                r2[i,j]:=t;
                                                dec(e[t]);
                                        end;
                                end;
                        end;
                end;
        end;
        if res<>0 then
        begin
                tmp:=mres;

                for i:=n-tmp downto 1 do write(r1[ires,i]);
                for i:=tmp downto 1 do write(0);

                writeln;

                for i:=n-tmp downto 1 do write(r2[ires,i]);
                for i:=tmp downto 1 do write(0);

                writeln;
        end
        else
        begin

        c:=d; e:=d;
        tmp:=math.min(c[0],e[0]);
        c[0]:=c[0]-tmp;
        e[0]:=e[0]-tmp;
        for j:=1 to n do
        for t:=0 to 9 do
        begin
                if c[t]>0 then
                begin
                        r1[1,j]:=t;
                        dec(c[t]);
                end;
                if e[t]>0 then
                begin
                        r2[1,j]:=t;
                        dec(e[t]);
                end;
        end;

        for i:=n-tmp downto 1 do write(r1[1,i]);
        for i:=tmp downto 1 do write(0);

        writeln;

        for i:=n-tmp downto 1do write(r2[1,i]);
        for i:=tmp downto 1 do write(0);

        writeln;

        end;
end.

uses math;
var
        i,n,count,j,t,res,ires,mres,tmp: longint;
        s: ansistring;
        r1,r2: array[0..9,0..100000] of longint;
        c,d,e: array[0..9] of longint;
        ck: boolean;
begin
        readln(s);
        for i:=1 to length(s) do
        begin
                inc(d[ord(s[i])-48]);
        end;
        n:=length(s);

        for i:=1 to 9 do
        begin
                c:=d;
                e:=d;

                count:=0;

                if ((c[i]<1) or (e[10-i]<1)) then continue;
                dec(c[i]); dec(e[10-i]);
                r1[i,1]:=i; r2[i,1]:=10-i;
                ck:=true;
                for j:=2 to n do
                begin
                        if ck=true then
                        begin
                        ck:=false;
                        for t:=0 to 9 do
                        begin
                                if (c[t]>0) and (e[9-t]>0) then
                                begin
                                        inc(count);
                                        cK:=true;
                                        dec(c[t]); dec(e[9-t]);
                                        r1[i,j]:=t; r2[i,j]:=9-t;
                                        if count>res then
                                        begin
                                                res:=count;
                                                ires:=i;
                                                mres:=0;
                                        end;
                                        break;
                                end;
                        end;
                        end;
                        if not ck then
                        begin
                                tmp:=math.min(c[0],e[0]);
                                c[0]:=c[0]-tmp;
                                e[0]:=e[0]-tmp;
                                if count+tmp>res then
                                begin
                                        res:=count+tmp;
                                        ires:=i;
                                        mres:=tmp;
                                end;
                                for t:=0 to 9 do
                                begin
                                        if (c[t]>0)and(r1[i,j]=0) then
                                        begin
                                                r1[i,j]:=t;
                                                dec(c[t]);
                                        end;
                                        if (e[t]>0)and(r2[i,j]=0) then
                                        begin
                                                r2[i,j]:=t;
                                                dec(e[t]);
                                        end;
                                end;
                        end;
                end;
        end;
        if res<>0 then
        begin
                tmp:=mres;

                for i:=n-tmp downto 1 do write(r1[ires,i]);
                for i:=tmp downto 1 do write(0);

                writeln;

                for i:=n-tmp downto 1 do write(r2[ires,i]);
                for i:=tmp downto 1 do write(0);

                writeln;
        end
        else
        begin

        c:=d; e:=d;
        tmp:=math.min(c[0],e[0]);
        c[0]:=c[0]-tmp;
        e[0]:=e[0]-tmp;
        for j:=1 to n do
        for t:=0 to 9 do
                                begin
                                        if (c[t]>0)and(r1[1,j]=0) then
                                        begin
                                                r1[1,j]:=t;
                                                dec(c[t]);
                                        end;
                                        if (e[t]>0)and(r2[1,j]=0) then
                                        begin
                                                r2[1,j]:=t;
                                                dec(e[t]);
                                        end;
                                end;

        for i:=n-tmp downto 1 do write(r1[1,i]);
        for i:=tmp downto 1 do write(0);

        writeln;

        for i:=n-tmp downto 1do write(r2[1,i]);
        for i:=tmp downto 1 do write(0);

        writeln;

        end;
end.

uses math;
var
        i,n,count,j,t,res,ires,mres,tmp: longint;
        s: ansistring;
        r1,r2: array[0..9,0..100000] of longint;
        c,d,e: array[0..9] of longint;
        ck: boolean;
begin
        readln(s);
        for i:=1 to length(s) do
        begin
                inc(d[ord(s[i])-48]);
        end;
        n:=length(s);

        for i:=1 to 9 do
        begin
                c:=d;
                e:=d;

                count:=0;

                if ((c[i]<1) and (e[10-i]<1)) then continue;
                dec(c[i]); dec(e[10-i]);
                r1[i,1]:=i; r2[i,1]:=10-i;
                ck:=true;
                for j:=2 to n do
                begin
                        if ck=true then
                        begin
                        ck:=false;
                        for t:=0 to 9 do
                        begin
                                if (c[t]>0) and (e[9-t]>0) then
                                begin
                                        inc(count);
                                        cK:=true;
                                        dec(c[t]); dec(e[9-t]);
                                        r1[i,j]:=t; r2[i,j]:=9-t;
                                        if count>res then
                                        begin
                                                res:=count;
                                                ires:=i;
                                                mres:=0;
                                        end;
                                end;
                        end;
                        end;
                        if not ck then
                        begin
                                tmp:=math.min(c[0],e[0]);
                                c[0]:=c[0]-tmp;
                                e[0]:=e[0]-tmp;
                                if count+tmp>res then
                                begin
                                        res:=count+tmp;
                                        ires:=i;
                                        mres:=tmp;
                                end;
                                for t:=0 to 9 do
                                begin
                                        if c[t]>0 then
                                        begin
                                                r1[i,j]:=t;
                                                dec(c[t]);
                                        end;
                                        if e[t]>0 then
                                        begin
                                                r2[i,j]:=t;
                                                dec(e[t]);
                                        end;
                                end;
                        end;
                end;
        end;
        tmp:=mres;
        for i:=n-tmp downto 1 do write(r1[ires,i]);
        for i:=tmp downto 1 do write(0);
        writeln;
        for i:=n-tmp downto 1 do write(r2[ires,i]);
        for i:=tmp downto 1 do write(0);
        writeln;
end.

var
        n,m,i,j,k,nn,ans:longint;
        a,b,c,d,ansa,ansb:array[0..9]of longint;
procedure dfs(x,y:longint);
var
        i,j:longint;
begin
        if x=nn then begin
                if ans<y div 10-1 then begin
                ansa:=b;
                ansb:=c;
                ans:=y div 10-1;
                end;
                exit;
        end;
        if y<11 then
        for i:=1 to 9 do begin
                if (a[i]>0)and(d[y-i]>0) then begin
                        dec(a[i]);
                        dec(d[y-i]);
                        inc(b[0]);
                        b[b[0]]:=i;
                        inc(c[0]);
                        c[c[0]]:=y-i;
                        dfs(x+1,9);
                        dec(c[0]);
                        dec(b[0]);
                        inc(a[i]);
                        inc(d[y-i]);
                end;
        end;
        for i:=1 to 9 do begin
                for j:=1 to 9 do begin
                        if (a[i]>0)and(d[j]>0) then begin
                                dec(a[i]);
                                dec(d[j]);
                                inc(b[0]);
                                b[b[0]]:=i;
                                inc(c[0]);
                                c[c[0]]:=j;
                                dfs(x+1,x*10+10);
                                dec(c[0]);
                                dec(b[0]);
                                inc(a[i]);
                                inc(d[j]);
                        end;
                end;
        end;
end;
begin
        readln(n);
        nn:=0;
        while n>0 do begin
                inc(a[n mod 10]);
                n:=n div 10;
                inc(nn);
        end;
        for i:=1 to a[0] do begin
                j:=0;
                inc(b[0]);
                inc(c[0]);
        end;
        d:=a;
        ans:=0;
        dfs(a[0],10);
        for i:=nn downto 1 do write(ansb[i]);
        writeln;
        for i:=nn downto 1 do write(ansa[i]);
        writeln;
end.

var
        a:array[1..100000]of longint;
        b,c,d,e:array[0..9]of longint;
        s:ansistring;
        n,i,j,k,l,o:longint;
        ansa,ansb:array[0..100000]of longint;
        ans:array[1..9]of longint;
function min(x,y:longint):longint;
begin
        if x<y then exit(x) else exit(y);
end;
begin
        readln(s);
        for i:=1 to length(s) do begin
                val(s[i],j);
                inc(b[j]);
        end;
        d:=b;
        e:=b;
        o:=1;
        for i:=1 to 9 do begin
                b:=d;
                c:=e;
                l:=0;
                if (b[i]>0)and(c[10-i]>0) then begin
                        dec(b[i]);
                        dec(c[10-i]);
                        for j:=0 to 9 do begin
                                b[j]:=min(b[j],c[9-j]);
                                l:=l+b[j];
                        end;
                end;
                ans[i]:=l+c[0]-b[9]+c[0]-b[0];
                if ans[i]>ans[o] then o:=i;
        end;
        b:=d; c:=e;
        dec(b[o]);
        dec(d[o]);
        dec(c[10-o]);
        for j:=0 to 9 do begin
                b[j]:=min(b[j],c[9-j]);
        end;
        ansa[0]:=min(c[0]-b[0],c[0]-b[9]);
        ansb[0]:=ansa[0];
        d[0]:=d[0]-ansa[0];
        c[0]:=c[0]-ansb[0];
        inc(ansa[0]);
        ansa[ansa[0]]:=o;
        inc(ansb[0]);
        ansb[ansb[0]]:=10-o;
        for i:=0 to 9 do begin
                for j:=1 to b[i] do begin
                        inc(ansa[0]);
                        ansa[ansa[0]]:=i;
                        dec(d[i]);
                        inc(ansb[0]);
                        ansb[ansb[0]]:=9-i;
                        dec(c[9-i]);
                end;
        end;
        for i:=0 to 9 do begin
                for j:=1 to d[i] do begin
                        inc(ansa[0]);
                        ansa[ansa[0]]:=i;
                end;
                for j:=1 to c[i] do begin
                        inc(ansb[0]);
                        ansb[ansb[0]]:=i;
                end;
        end;
        for i:=ansa[0] downto 1 do write(ansa[i]);
        writeln;
        for i:=ansb[0] downto 1 do write(ansb[i]);
        writeln;
end.

var
        a:array[1..100000]of longint;
        b,c,d,e:array[0..9]of longint;
        s:ansistring;
        pk:boolean;
        n,i,j,k,l,o:longint;
        ansa,ansb:array[0..100000]of longint;
        ans:array[1..9]of longint;
function min(x,y:longint):longint;
begin
        if x<y then exit(x) else exit(y);
end;
begin
        readln(s);
        for i:=1 to length(s) do begin
                val(s[i],j);
                inc(b[j]);
        end;
        d:=b;
        e:=b;
        o:=1;
        for i:=1 to 9 do begin
                b:=d;
                c:=e;
                l:=0;
                if (b[i]>0)and(c[10-i]>0) then begin
                        dec(b[i]);
                        dec(c[10-i]);
                        for j:=0 to 9 do begin
                                b[j]:=min(b[j],c[9-j]);
                                l:=l+b[j];
                        end;
                end else o:=i;
                ans[i]:=l+c[0]-b[9]+c[0]-b[0];
                if ans[i]>ans[o] then o:=i;
        end;
        b:=d; c:=e;
        pk:=false;
        if (d[o]>0)and(c[10-o]>0) then begin
        dec(b[o]);
        pk:=true;
        dec(d[o]);
        dec(c[10-o]);
        end;
        for j:=0 to 9 do begin
                b[j]:=min(b[j],c[9-j]);
        end;
        ansa[0]:=min(c[0]-b[0],c[0]-b[9]);
        ansb[0]:=ansa[0];
        d[0]:=d[0]-ansa[0];
        c[0]:=c[0]-ansb[0];
        if pk then begin
        inc(ansa[0]);
        ansa[ansa[0]]:=o;
        inc(ansb[0]);
        ansb[ansb[0]]:=10-o;
        end;
        for i:=0 to 9 do begin
                for j:=1 to b[i] do begin
                        inc(ansa[0]);
                        ansa[ansa[0]]:=i;
                        dec(d[i]);
                        inc(ansb[0]);
                        ansb[ansb[0]]:=9-i;
                        dec(c[9-i]);
                end;
        end;
        for i:=0 to 9 do begin
                for j:=1 to d[i] do begin
                        inc(ansa[0]);
                        ansa[ansa[0]]:=i;
                end;
                for j:=1 to c[i] do begin
                        inc(ansb[0]);
                        ansb[ansb[0]]:=i;
                end;
        end;
        for i:=ansa[0] downto 1 do write(ansa[i]);
        writeln;
        for i:=ansb[0] downto 1 do write(ansb[i]);
        writeln;
end.

var
        a:array[1..100000]of longint;
        b,c,d,e:array[0..9]of longint;
        s:ansistring;
        pk:boolean;
        n,i,j,k,l,o:longint;
        ansa,ansb:array[0..100000]of longint;
        ans:array[1..9]of longint;
function min(x,y:longint):longint;
begin
        if x<y then exit(x) else exit(y);
end;
begin
        readln(s);
        for i:=1 to length(s) do begin
                val(s[i],j);
                inc(b[j]);
        end;
        d:=b;
        e:=b;
        o:=1;
        for i:=1 to 9 do begin
                b:=d;
                c:=e;
                l:=0;
                if (b[i]>0)and(c[10-i]>0) then begin
                        dec(b[i]);
                        dec(c[10-i]);
                        l:=1;
                        for j:=0 to 9 do begin
                                b[j]:=min(b[j],c[9-j]);
                                l:=l+b[j];
                        end;
                end;
                ans[i]:=l+c[0]-b[9]+c[0]-b[0];
                if ans[i]>ans[o] then o:=i;
        end;
        b:=d; c:=e;
        pk:=false;
        if (d[o]>0)and(c[10-o]>0) then begin
        dec(b[o]);
        pk:=true;
        dec(d[o]);
        dec(c[10-o]);
        end;
        for j:=0 to 9 do begin
                b[j]:=min(b[j],c[9-j]);
        end;
        ansa[0]:=min(c[0]-b[0],c[0]-b[9]);
        ansb[0]:=ansa[0];
        d[0]:=d[0]-ansa[0];
        c[0]:=c[0]-ansb[0];
        if pk then begin
        inc(ansa[0]);
        ansa[ansa[0]]:=o;
        inc(ansb[0]);
        ansb[ansb[0]]:=10-o;
        end;
        for i:=0 to 9 do begin
                for j:=1 to b[i] do begin
                        inc(ansa[0]);
                        ansa[ansa[0]]:=i;
                        dec(d[i]);
                        inc(ansb[0]);
                        ansb[ansb[0]]:=9-i;
                        dec(c[9-i]);
                end;
        end;
        for i:=0 to 9 do begin
                for j:=1 to d[i] do begin
                        inc(ansa[0]);
                        ansa[ansa[0]]:=i;
                end;
                for j:=1 to c[i] do begin
                        inc(ansb[0]);
                        ansb[ansb[0]]:=i;
                end;
        end;
        for i:=ansa[0] downto 1 do write(ansa[i]);
        writeln;
        for i:=ansb[0] downto 1 do write(ansb[i]);
        writeln;
end.

var
        a:array[1..100000]of longint;
        b,c,d,e:array[0..9]of longint;
        s:ansistring;
        n,i,j,k,l,o:longint;
        ansa,ansb:array[0..100000]of longint;
        ans:array[1..9]of longint;
function min(x,y:longint):longint;
begin
        if x<y then exit(x) else exit(y);
end;
begin
        readln(s);
        for i:=1 to length(s) do begin
                val(s[i],j);
                inc(b[j]);
        end;
        d:=b;
        e:=b;
        o:=1;
        for i:=1 to 9 do begin
                b:=d;
                c:=e;
                l:=0;
                if (b[i]>0)and(c[10-i]>0) then begin
                        dec(b[i]);
                        dec(c[10-i]);
                        for j:=0 to 9 do begin
                                b[j]:=min(b[j],c[9-j]);
                                l:=l+b[j];
                        end;
                end;
                ans[i]:=l+c[0]-b[9]+c[0]-b[0];
                if ans[i]>ans[o] then o:=i;
        end;
        b:=d; c:=e;
        dec(b[o]);
        dec(d[o]);
        dec(c[10-o]);
        for j:=0 to 9 do begin
                b[j]:=min(b[j],c[9-j]);
        end;
        ansa[0]:=c[0]-b[0];
        ansb[0]:=c[0]-b[9];
        d[0]:=d[0]-ansa[0];
        c[0]:=c[0]-ansb[0];
        inc(ansa[0]);
        ansa[ansa[0]]:=o;
        inc(ansb[0]);
        ansb[ansb[0]]:=10-o;
        for i:=0 to 9 do begin
                for j:=1 to b[i] do begin
                        inc(ansa[0]);
                        ansa[ansa[0]]:=i;
                        dec(d[i]);
                        inc(ansb[0]);
                        ansb[ansb[0]]:=9-i;
                        dec(c[9-i]);
                end;
        end;
        for i:=0 to 9 do begin
                for j:=1 to d[i] do begin
                        inc(ansa[0]);
                        ansa[ansa[0]]:=i;
                end;
                for j:=1 to c[i] do begin
                        inc(ansb[0]);
                        ansb[ansb[0]]:=i;
                end;
        end;
        for i:=ansa[0] downto 1 do write(ansa[i]);
        writeln;
        for i:=ansb[0] downto 1 do write(ansb[i]);
        writeln;
end.

uses math;
const
        fi='';
var
        f:text;
        s,r1,r2:string;
        n,kq,max,x,dis:longint;
        a,b,c,d:array [0..9] of longint;
procedure nhap;
var
        i:longint;
begin
        assign(f,fi);
        reset(f);
        readln(f,s);
        n:=length(s);
        for i:=1 to n do inc(a[ord(s[i])-48]);
        for i:=0 to 9 do b[i]:=a[i];
        dis:=1;
        kq:=-1;
        close(f);
end;
procedure cc;
var
        i,j,u,v,queo:longint;
begin
        c:=a; d:=b;
        v:=math.min(a[0],b[0]);
        if v=0 then exit;
        queo:=v;
        c[0]:=c[0]-v; d[0]:=d[0]-v;
        for i:=1 to 9 do
        if a[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if b[u]<=0 then continue;
                dec(a[i]); dec(b[u]);
                x:=queo;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(a[j],b[v]);
                end;
                if x>=max then
                begin
                        max:=x;
                        kq:=i;
                        dis:=0;
                end;
                inc(a[i]); inc(b[u]);
        end;
end;
procedure xuly;
var
        i,j,u,v:longint;
begin
        for i:=1 to 9 do
        if a[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if b[u]<=0 then continue;
                dec(a[i]); dec(b[u]);
                x:=0;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(a[j],b[v]);
                end;
                if x>=max then
                begin
                        max:=x;
                        kq:=i;
                end;
                inc(a[i]); inc(b[u]);
        end;
end;
procedure lam;
var
        i,j,u,v:longint;
begin
        if kq=-1 then
        begin
                writeln(s);
                writeln(s);
                halt;
        end;
        if dis=0 then
        begin
                v:=math.min(a[0],b[0]);
                for i:=1 to v do r1:='0'+r1;
                for i:=1 to v do r2:='0'+r2;
                a[0]:=a[0]-v; b[0]:=b[0]-v;
                for i:=1 to 9 do
                if a[i]>0 then
                begin
                        u:=10-i;
                        if b[u]>0 then
                        begin
                                dec(a[i]); dec(b[u]);
                                r1:=chr(i+48)+r1; r2:=chr(u+48)+r2;
                                break;
                        end;
                end;
                for i:=0 to 9 do
                if a[i]>0 then
                begin
                        u:=9-i;
                        if b[u]<=0 then continue;
                        v:=math.min(a[i],b[u]);
                        a[i]:=a[i]-v; b[u]:=b[u]-v;
                        for j:=1 to v do r1:=chr(i+48)+r1;
                        for j:=1 to v do r2:=chr(u+48)+r2;
                end;
                for i:=9 downto 0 do
                for j:=1 to a[i] do r1:=chr(i+48)+r1;
                for i:=9 downto 0 do
                for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end
        else
        begin
        r1:=chr(kq+48);
        dec(a[kq]);
        v:=10-kq;
        r2:=chr(v+48);
        dec(b[v]);
        for i:=0 to 9 do
        if a[i]>0 then
        begin
                u:=9-i;
                if b[u]<=0 then continue;
                v:=math.min(a[i],b[u]);
                a[i]:=a[i]-v; b[u]:=b[u]-v;
                for j:=1 to v do r1:=chr(i+48)+r1;
                for j:=1 to v do r2:=chr(u+48)+r2;
        end;
        for i:=9 downto 0 do
        for j:=1 to a[i] do r1:=chr(i+48)+r1;
        for i:=9 downto 0 do
        for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end;
        writeln(r1);
        writeln(r2);
end;
begin
        nhap;
        xuly;
        cc;
        lam;
end.

uses math;
const
        fi='';
var
        f:text;
        s,r1,r2:string;
        n,kq,max,x,dis,l1,l2:longint;
        a,b,c,d:array [0..9] of longint;
procedure nhap;
var
        i:longint;
begin
        assign(f,fi);
        reset(f);
        readln(f,s);
        n:=length(s);
        for i:=1 to n do inc(a[ord(s[i])-48]);
        for i:=0 to 9 do b[i]:=a[i];
        dis:=1;
        kq:=-1;
        close(f);
end;
procedure cc;
var
        i,j,u,v,queo:longint;
begin
        c:=a; d:=b;
        v:=math.min(a[0],b[0]);
        if v=0 then exit;
        queo:=v;
        c[0]:=c[0]-v; d[0]:=d[0]-v;
        if queo>max then
        begin
                dis:=0;
                kq:=0;
                max:=queo;
                l1:=-1;
        end;
        for i:=1 to 9 do
        if c[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if d[u]<=0 then continue;
                dec(c[i]); dec(d[u]);
                x:=queo+1;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(c[j],d[v]);
                end;
                if x>max then
                begin
                        max:=x;
                        kq:=i;
                        dis:=0;
                        l1:=i; l2:=u;
                end;
                inc(c[i]); inc(d[u]);
        end;
end;
procedure xuly;
var
        i,j,u,v:longint;
begin
        for i:=1 to 9 do
        if a[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if b[u]<=0 then continue;
                dec(a[i]); dec(b[u]);
                x:=1;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(a[j],b[v]);
                end;
                if x>max then
                begin
                        max:=x;
                        kq:=i;
                end;
                inc(a[i]); inc(b[u]);
        end;
end;
procedure lam;
var
        i,j,u,v:longint;
begin
        if kq=-1 then
        begin
                writeln(s);
                writeln(s);
                halt;
        end;
        if dis=0 then
        begin
                v:=math.min(a[0],b[0]);
                for i:=1 to v do r1:='0'+r1;
                for i:=1 to v do r2:='0'+r2;
                a[0]:=a[0]-v; b[0]:=b[0]-v;
                if l1<>-1 then
                begin
                dec(a[l1]); dec(b[l2]);
                r1:=chr(l1+48)+r1;
                r2:=chr(l2+48)+r2;
                end;
                for i:=0 to 9 do
                if a[i]>0 then
                begin
                        u:=9-i;
                        if b[u]<=0 then continue;
                        v:=math.min(a[i],b[u]);
                        a[i]:=a[i]-v; b[u]:=b[u]-v;
                        for j:=1 to v do r1:=chr(i+48)+r1;
                        for j:=1 to v do r2:=chr(u+48)+r2;
                end;
                for i:=0 to 9 do
                for j:=1 to a[i] do r1:=chr(i+48)+r1;
                for i:=0 to 9 do
                for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end
        else
        begin
        r1:=chr(kq+48);
        dec(a[kq]);
        v:=10-kq;
        r2:=chr(v+48);
        dec(b[v]);
        for i:=0 to 9 do
        if a[i]>0 then
        begin
                u:=9-i;
                if b[u]<=0 then continue;
                v:=math.min(a[i],b[u]);
                a[i]:=a[i]-v; b[u]:=b[u]-v;
                for j:=1 to v do r1:=chr(i+48)+r1;
                for j:=1 to v do r2:=chr(u+48)+r2;
        end;
        for i:=0 to 9 do
        for j:=1 to a[i] do r1:=chr(i+48)+r1;
        for i:=0 to 9 do
        for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end;
        writeln(r1);
        writeln(r2);
end;
begin
        nhap;
        xuly;
        cc;
        lam;
end.

uses math;
const
        fi='';
var
        f:text;
        s,r1,r2:ansistring;
        n,kq,max,x,dis,l1,l2:longint;
        a,b,c,d:array [0..9] of longint;
procedure nhap;
var
        i:longint;
begin
        assign(f,fi);
        reset(f);
        readln(f,s);
        n:=length(s);
        for i:=1 to n do inc(a[ord(s[i])-48]);
        for i:=0 to 9 do b[i]:=a[i];
        dis:=1;
        kq:=-1;
        close(f);
end;
procedure cc;
var
        i,j,u,v,queo:longint;
begin
        c:=a; d:=b;
        v:=math.min(a[0],b[0]);
        if v=0 then exit;
        queo:=v;
        c[0]:=c[0]-v; d[0]:=d[0]-v;
        if queo>max then
        begin
                dis:=0;
                kq:=0;
                max:=queo;
                l1:=-1;
        end;
        for i:=1 to 9 do
        if c[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if d[u]<=0 then continue;
                dec(c[i]); dec(d[u]);
                x:=queo+1;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(c[j],d[v]);
                end;
                if x>max then
                begin
                        max:=x;
                        kq:=i;
                        dis:=0;
                        l1:=i; l2:=u;
                end;
                inc(c[i]); inc(d[u]);
        end;
end;
procedure xuly;
var
        i,j,u,v:longint;
begin
        for i:=1 to 9 do
        if a[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if b[u]<=0 then continue;
                dec(a[i]); dec(b[u]);
                x:=1;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(a[j],b[v]);
                end;
                if x>max then
                begin
                        max:=x;
                        kq:=i;
                end;
                inc(a[i]); inc(b[u]);
        end;
end;
procedure lam;
var
        i,j,u,v:longint;
begin
        if kq=-1 then
        begin
                writeln(s);
                writeln(s);
                halt;
        end;
        if dis=0 then
        begin
                v:=math.min(a[0],b[0]);
                for i:=1 to v do r1:='0'+r1;
                for i:=1 to v do r2:='0'+r2;
                a[0]:=a[0]-v; b[0]:=b[0]-v;
                if l1<>-1 then
                begin
                dec(a[l1]); dec(b[l2]);
                r1:=chr(l1+48)+r1;
                r2:=chr(l2+48)+r2;
                end;
                for i:=0 to 9 do
                if a[i]>0 then
                begin
                        u:=9-i;
                        if b[u]<=0 then continue;
                        v:=math.min(a[i],b[u]);
                        a[i]:=a[i]-v; b[u]:=b[u]-v;
                        for j:=1 to v do r1:=chr(i+48)+r1;
                        for j:=1 to v do r2:=chr(u+48)+r2;
                end;
                for i:=1 to a[0] do r1:=r1+'0';
                for i:=1 to b[0] do r2:=r2+'0';
                for i:=1 to 9 do
                for j:=1 to a[i] do r1:=chr(i+48)+r1;
                for i:=1 to 9 do
                for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end
        else
        begin
        r1:=chr(kq+48);
        dec(a[kq]);
        v:=10-kq;
        r2:=chr(v+48);
        dec(b[v]);
        for i:=0 to 9 do
        if a[i]>0 then
        begin
                u:=9-i;
                if b[u]<=0 then continue;
                v:=math.min(a[i],b[u]);
                a[i]:=a[i]-v; b[u]:=b[u]-v;
                for j:=1 to v do r1:=chr(i+48)+r1;
                for j:=1 to v do r2:=chr(u+48)+r2;
        end;
         for i:=1 to a[0] do r1:=r1+'0';
                for i:=1 to b[0] do r2:=r2+'0';
        for i:=1 to 9 do
        for j:=1 to a[i] do r1:=chr(i+48)+r1;
        for i:=1 to 9 do
        for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end;
        writeln(r1);
        writeln(r2);
end;
begin
        nhap;
        xuly;
        cc;
        lam;
end.

uses math;
const
        fi='';
var
        f:text;
        s,r1,r2:string;
        n,kq,max,x,dis:longint;
        a,b,c,d:array [0..9] of longint;
procedure nhap;
var
        i:longint;
begin
        assign(f,fi);
        reset(f);
        readln(f,s);
        n:=length(s);
        for i:=1 to n do inc(a[ord(s[i])-48]);
        for i:=0 to 9 do b[i]:=a[i];
        dis:=1;
        kq:=-1;
        close(f);
end;
procedure cc;
var
        i,j,u,v,queo:longint;
begin
        c:=a; d:=b;
        v:=math.min(a[0],b[0]);
        if v=0 then exit;
        queo:=v;
        c[0]:=c[0]-v; d[0]:=d[0]-v;
        for i:=1 to 9 do
        if a[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if b[u]<=0 then continue;
                dec(a[i]); dec(b[u]);
                x:=queo;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(a[j],b[v]);
                end;
                if x>=max then
                begin
                        max:=x;
                        kq:=i;
                        dis:=0;
                end;
                inc(a[i]); inc(b[u]);
        end;
end;
procedure xuly;
var
        i,j,u,v:longint;
begin
        for i:=1 to 9 do
        if a[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if b[u]<=0 then continue;
                dec(a[i]); dec(b[u]);
                x:=0;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(a[j],b[v]);
                end;
                if x>=max then
                begin
                        max:=x;
                        kq:=i;
                end;
                inc(a[i]); inc(b[u]);
        end;
end;
procedure lam;
var
        i,j,u,v:longint;
begin
        if kq=-1 then
        begin
                writeln(s);
                writeln(s);
                halt;
        end;
        if dis=0 then
        begin
                v:=math.min(a[0],b[0]);
                for i:=1 to v do r1:='0'+r1;
                for i:=1 to v do r2:='0'+r2;
                a[0]:=a[0]-v; b[0]:=b[0]-v;
                for i:=0 to 9 do
                if a[i]>0 then
                begin
                        u:=9-i;
                        if b[u]<=0 then continue;
                        v:=math.min(a[i],b[u]);
                        a[i]:=a[i]-v; b[u]:=b[u]-v;
                        for j:=1 to v do r1:=chr(i+48)+r1;
                        for j:=1 to v do r2:=chr(u+48)+r2;
                end;
                for i:=9 downto 0 do
                for j:=1 to a[i] do r1:=chr(i+48)+r1;
                for i:=9 downto 0 do
                for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end
        else
        begin
        r1:=chr(kq+48);
        dec(a[kq]);
        v:=10-kq;
        r2:=chr(v+48);
        dec(b[v]);
        for i:=0 to 9 do
        if a[i]>0 then
        begin
                u:=9-i;
                if b[u]<=0 then continue;
                v:=math.min(a[i],b[u]);
                a[i]:=a[i]-v; b[u]:=b[u]-v;
                for j:=1 to v do r1:=chr(i+48)+r1;
                for j:=1 to v do r2:=chr(u+48)+r2;
        end;
        for i:=9 downto 0 do
        for j:=1 to a[i] do r1:=chr(i+48)+r1;
        for i:=9 downto 0 do
        for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end;
        writeln(r1);
        writeln(r2);
end;
begin
        nhap;
        xuly;
        cc;
        lam;
end.

uses math;
const
        fi='';
var
        f:text;
        s,r1,r2:ansistring;
        n,kq,max,x,dis,l1,l2:longint;
        a,b,c,d:array [0..9] of longint;
procedure nhap;
var
        i:longint;
begin
        assign(f,fi);
        reset(f);
        readln(f,s);
        n:=length(s);
        for i:=1 to n do inc(a[ord(s[i])-48]);
        for i:=0 to 9 do b[i]:=a[i];
        dis:=1;
        kq:=-1;
        close(f);
end;
procedure cc;
var
        i,j,u,v,queo:longint;
begin
        c:=a; d:=b;
        v:=math.min(a[0],b[0]);
        if v=0 then exit;
        queo:=v;
        c[0]:=c[0]-v; d[0]:=d[0]-v;
        if queo>max then
        begin
                dis:=0;
                kq:=0;
                max:=queo;
                l1:=-1;
        end;
        for i:=1 to 9 do
        if c[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if d[u]<=0 then continue;
                dec(c[i]); dec(d[u]);
                x:=queo+1;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(c[j],d[v]);
                end;
                if x>max then
                begin
                        max:=x;
                        kq:=i;
                        dis:=0;
                        l1:=i; l2:=u;
                end;
                inc(c[i]); inc(d[u]);
        end;
end;
procedure xuly;
var
        i,j,u,v:longint;
begin
        for i:=1 to 9 do
        if a[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if b[u]<=0 then continue;
                dec(a[i]); dec(b[u]);
                x:=1;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(a[j],b[v]);
                end;
                if x>max then
                begin
                        max:=x;
                        kq:=i;
                end;
                inc(a[i]); inc(b[u]);
        end;
end;
procedure lam;
var
        i,j,u,v:longint;
begin
        if kq=-1 then
        begin
                writeln(s);
                writeln(s);
                halt;
        end;
        if dis=0 then
        begin
                v:=math.min(a[0],b[0]);
                for i:=1 to v do r1:='0'+r1;
                for i:=1 to v do r2:='0'+r2;
                a[0]:=a[0]-v; b[0]:=b[0]-v;
                if l1<>-1 then
                begin
                dec(a[l1]); dec(b[l2]);
                r1:=chr(l1+48)+r1;
                r2:=chr(l2+48)+r2;
                end;
                for i:=0 to 9 do
                if a[i]>0 then
                begin
                        u:=9-i;
                        if b[u]<=0 then continue;
                        v:=math.min(a[i],b[u]);
                        a[i]:=a[i]-v; b[u]:=b[u]-v;
                        for j:=1 to v do r1:=chr(i+48)+r1;
                        for j:=1 to v do r2:=chr(u+48)+r2;
                end;
                for i:=0 to 9 do
                for j:=1 to a[i] do r1:=chr(i+48)+r1;
                for i:=0 to 9 do
                for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end
        else
        begin
        r1:=chr(kq+48);
        dec(a[kq]);
        v:=10-kq;
        r2:=chr(v+48);
        dec(b[v]);
        for i:=0 to 9 do
        if a[i]>0 then
        begin
                u:=9-i;
                if b[u]<=0 then continue;
                v:=math.min(a[i],b[u]);
                a[i]:=a[i]-v; b[u]:=b[u]-v;
                for j:=1 to v do r1:=chr(i+48)+r1;
                for j:=1 to v do r2:=chr(u+48)+r2;
        end;
        for i:=0 to 9 do
        for j:=1 to a[i] do r1:=chr(i+48)+r1;
        for i:=0 to 9 do
        for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end;
        writeln(r1);
        writeln(r2);
end;
begin
        nhap;
        xuly;
        cc;
        lam;
end.

uses math;
const
        fi='';
var
        f:text;
        s,r1,r2:ansistring;
        n,kq,max,x,dis:longint;
        a,b,c,d:array [0..9] of longint;
procedure nhap;
var
        i:longint;
begin
        assign(f,fi);
        reset(f);
        readln(f,s);
        n:=length(s);
        for i:=1 to n do inc(a[ord(s[i])-48]);
        for i:=0 to 9 do b[i]:=a[i];
        dis:=1;
        kq:=-1;
        close(f);
end;
procedure cc;
var
        i,j,u,v,queo:longint;
begin
        c:=a; d:=b;
        v:=math.min(a[0],b[0]);
        if v=0 then exit;
        queo:=v;
        c[0]:=c[0]-v; d[0]:=d[0]-v;
        for i:=1 to 9 do
        if a[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if b[u]<=0 then continue;
                dec(a[i]); dec(b[u]);
                x:=queo;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(a[j],b[v]);
                end;
                if x>=max then
                begin
                        max:=x;
                        kq:=i;
                        dis:=0;
                end;
                inc(a[i]); inc(b[u]);
        end;
end;
procedure xuly;
var
        i,j,u,v:longint;
begin
        for i:=1 to 9 do
        if a[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if b[u]<=0 then continue;
                dec(a[i]); dec(b[u]);
                x:=0;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(a[j],b[v]);
                end;
                if x>=max then
                begin
                        max:=x;
                        kq:=i;
                        dis:=0;
                end;
                inc(a[i]); inc(b[u]);
        end;
end;
procedure lam;
var
        i,j,u,v:longint;
begin
        if kq=-1 then
        begin
                writeln(s);
                writeln(s);
                halt;
        end;
        if dis=0 then
        begin
                v:=math.min(a[0],b[0]);
                for i:=1 to v do r1:='0'+r1;
                for i:=1 to v do r2:='0'+r2;
                a[0]:=a[0]-v; b[0]:=b[0]-v;
                for i:=1 to 9 do
                if a[i]>0 then
                begin
                        u:=10-i;
                        if b[u]>0 then
                        begin
                                dec(a[i]); dec(b[u]);
                                r1:=chr(i+48)+r1; r2:=chr(u+48)+r2;
                                break;
                        end;
                end;
                for i:=0 to 9 do
                if a[i]>0 then
                begin
                        u:=9-i;
                        if b[u]<=0 then continue;
                        v:=math.min(a[i],b[u]);
                        a[i]:=a[i]-v; b[u]:=b[u]-v;
                        for j:=1 to v do r1:=chr(i+48)+r1;
                        for j:=1 to v do r2:=chr(u+48)+r2;
                end;
                for i:=9 downto 0 do
                for j:=1 to a[i] do r1:=chr(i+48)+r1;
                for i:=9 downto 0 do
                for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end
        else
        begin
        r1:=chr(kq+48);
        dec(a[kq]);
        v:=10-kq;
        r2:=chr(v+48);
        dec(b[v]);
        for i:=0 to 9 do
        if a[i]>0 then
        begin
                u:=9-i;
                if b[u]<=0 then continue;
                v:=math.min(a[i],b[u]);
                a[i]:=a[i]-v; b[u]:=b[u]-v;
                for j:=1 to v do r1:=chr(i+48)+r1;
                for j:=1 to v do r2:=chr(u+48)+r2;
        end;
        for i:=9 downto 0 do
        for j:=1 to a[i] do r1:=chr(i+48)+r1;
        for i:=9 downto 0 do
        for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end;
        writeln(r1);
        writeln(r2);
end;
begin
        nhap;
        xuly;
        cc;
        lam;
end.

uses math;
const
        fi='';
var
        f:text;
        s,r1,r2:string;
        n,kq,max,x,dis:longint;
        a,b,c,d:array [0..9] of longint;
procedure nhap;
var
        i:longint;
begin
        assign(f,fi);
        reset(f);
        readln(f,s);
        n:=length(s);
        for i:=1 to n do inc(a[ord(s[i])-48]);
        for i:=0 to 9 do b[i]:=a[i];
        dis:=1;
        close(f);
end;
procedure cc;
var
        i,j,u,v,queo:longint;
begin
        c:=a; d:=b;
        v:=math.min(a[0],b[0]);
        if v=0 then exit;
        queo:=v;
        c[0]:=c[0]-v; d[0]:=d[0]-v;
        for i:=1 to 9 do
        if a[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if b[u]<=0 then continue;
                dec(a[i]); dec(b[u]);
                x:=queo;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(a[j],b[v]);
                end;
                if x>max then
                begin
                        max:=x;
                        kq:=i;
                        dis:=0;
                end;
                inc(a[i]); inc(b[u]);
        end;
end;
procedure xuly;
var
        i,j,u,v:longint;
begin
        for i:=1 to 9 do
        if a[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if b[u]<=0 then continue;
                dec(a[i]); dec(b[u]);
                x:=0;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(a[j],b[v]);
                end;
                if x>max then
                begin
                        max:=x;
                        kq:=i;
                end;
                inc(a[i]); inc(b[u]);
        end;
end;
procedure lam;
var
        i,j,u,v:longint;
begin
        if dis=0 then
        begin
                v:=math.min(a[0],b[0]);
                for i:=1 to v do r1:='0'+r1;
                for i:=1 to v do r2:='0'+r2;
                a[0]:=a[0]-v; b[0]:=b[0]-v;
                for i:=0 to 9 do
                if a[i]>0 then
                begin
                        u:=9-i;
                        if b[u]<=0 then continue;
                        v:=math.min(a[i],b[u]);
                        a[i]:=a[i]-v; b[u]:=b[u]-v;
                        for j:=1 to v do r1:=chr(i+48)+r1;
                        for j:=1 to v do r2:=chr(u+48)+r2;
                end;
                for i:=9 downto 0 do
                for j:=1 to a[i] do r1:=chr(i+48)+r1;
                for i:=9 downto 0 do
                for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end
        else
        begin
        r1:=chr(kq+48);
        dec(a[kq]);
        v:=10-kq;
        r2:=chr(v+48);
        dec(b[v]);
        for i:=0 to 9 do
        if a[i]>0 then
        begin
                u:=9-i;
                if b[u]<=0 then continue;
                v:=math.min(a[i],b[u]);
                a[i]:=a[i]-v; b[u]:=b[u]-v;
                for j:=1 to v do r1:=chr(i+48)+r1;
                for j:=1 to v do r2:=chr(u+48)+r2;
        end;
        for i:=9 downto 0 do
        for j:=1 to a[i] do r1:=chr(i+48)+r1;
        for i:=9 downto 0 do
        for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end;
        writeln(r1);
        writeln(r2);
end;
begin
        nhap;
        xuly;
        cc;
        lam;
end.

uses math;
const
        fi='';
var
        f:text;
        s,r1,r2:ansistring;
        n,kq,max,x,dis,l1,l2:longint;
        a,b,c,d:array [0..9] of longint;
procedure nhap;
var
        i:longint;
begin
        assign(f,fi);
        reset(f);
        readln(f,s);
        n:=length(s);
        for i:=1 to n do inc(a[ord(s[i])-48]);
        for i:=0 to 9 do b[i]:=a[i];
        dis:=1;
        kq:=-1;
        close(f);
end;
procedure cc;
var
        i,j,u,v,queo:longint;
begin
        c:=a; d:=b;
        v:=math.min(a[0],b[0]);
        if v=0 then exit;
        queo:=v;
        c[0]:=c[0]-v; d[0]:=d[0]-v;
        for i:=1 to 9 do
        if c[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if d[u]<=0 then continue;
                dec(c[i]); dec(d[u]);
                x:=queo+1;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(c[j],d[v]);
                end;
                if x>=max then
                begin
                        max:=x;
                        kq:=i;
                        dis:=0;
                        l1:=i; l2:=u;
                end;
                inc(c[i]); inc(d[u]);
        end;
end;
procedure xuly;
var
        i,j,u,v:longint;
begin
        for i:=1 to 9 do
        if a[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if b[u]<=0 then continue;
                dec(a[i]); dec(b[u]);
                x:=1;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(a[j],b[v]);
                end;
                if x>=max then
                begin
                        max:=x;
                        kq:=i;
                end;
                inc(a[i]); inc(b[u]);
        end;
end;
procedure lam;
var
        i,j,u,v:longint;
begin
        if kq=-1 then
        begin
                writeln(s);
                writeln(s);
                halt;
        end;
        if dis=0 then
        begin
                v:=math.min(a[0],b[0]);
                for i:=1 to v do r1:='0'+r1;
                for i:=1 to v do r2:='0'+r2;
                a[0]:=a[0]-v; b[0]:=b[0]-v;
                dec(a[l1]); dec(b[l2]);
                r1:=chr(l1+48)+r1;
                r2:=chr(l2+48)+r2;
                for i:=0 to 9 do
                if a[i]>0 then
                begin
                        u:=9-i;
                        if b[u]<=0 then continue;
                        v:=math.min(a[i],b[u]);
                        a[i]:=a[i]-v; b[u]:=b[u]-v;
                        for j:=1 to v do r1:=chr(i+48)+r1;
                        for j:=1 to v do r2:=chr(u+48)+r2;
                end;
                for i:=9 downto 0 do
                for j:=1 to a[i] do r1:=chr(i+48)+r1;
                for i:=9 downto 0 do
                for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end
        else
        begin
        r1:=chr(kq+48);
        dec(a[kq]);
        v:=10-kq;
        r2:=chr(v+48);
        dec(b[v]);
        for i:=0 to 9 do
        if a[i]>0 then
        begin
                u:=9-i;
                if b[u]<=0 then continue;
                v:=math.min(a[i],b[u]);
                a[i]:=a[i]-v; b[u]:=b[u]-v;
                for j:=1 to v do r1:=chr(i+48)+r1;
                for j:=1 to v do r2:=chr(u+48)+r2;
        end;
        for i:=9 downto 0 do
        for j:=1 to a[i] do r1:=chr(i+48)+r1;
        for i:=9 downto 0 do
        for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end;
        writeln(r1);
        writeln(r2);
end;
begin
        nhap;
        xuly;
        cc;
        lam;
end.

uses math;
const
        fi='';
var
        f:text;
        s,r1,r2:string;
        n,kq,max,x,dis:longint;
        a,b,c,d:array [0..9] of longint;
procedure nhap;
var
        i:longint;
begin
        assign(f,fi);
        reset(f);
        readln(f,s);
        n:=length(s);
        for i:=1 to n do inc(a[ord(s[i])-48]);
        for i:=0 to 9 do b[i]:=a[i];
        close(f);
end;
procedure cc;
var
        i,j,u,v:longint;
begin
        c:=a; d:=b;
        v:=math.min(a[0],b[0]);
        if v=0 then exit;
        c[0]:=c[0]-v; d[0]:=d[0]-v;
        for i:=1 to 9 do
        if a[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if b[u]<=0 then continue;
                dec(a[i]); dec(b[u]);
                x:=0;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(a[j],b[v]);
                end;
                if x>max then
                begin
                        max:=x;
                        kq:=i;
                        dis:=0;
                end;
                inc(a[i]); inc(b[u]);
        end;
end;
procedure xuly;
var
        i,j,u,v:longint;
begin
        for i:=1 to 9 do
        if a[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if b[u]<=0 then continue;
                dec(a[i]); dec(b[u]);
                x:=0;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(a[j],b[v]);
                end;
                if x>max then
                begin
                        max:=x;
                        kq:=i;
                end;
                inc(a[i]); inc(b[u]);
        end;
end;
procedure lam;
var
        i,j,u,v:longint;
begin
        if dis=0 then
        begin
                v:=math.min(a[0],b[0]);
                for i:=1 to v do r1:='0'+r1;
                for i:=1 to v do r2:='0'+r2;
                a[0]:=a[0]-v; b[0]:=b[0]-v;
                for i:=0 to 9 do
                if a[i]>0 then
                begin
                        u:=9-i;
                        if b[u]<=0 then continue;
                        v:=math.min(a[i],b[u]);
                        a[i]:=a[i]-v; b[u]:=b[u]-v;
                        for j:=1 to v do r1:=chr(i+48)+r1;
                        for j:=1 to v do r2:=chr(u+48)+r2;
                end;
                for i:=9 downto 0 do
                for j:=1 to a[i] do r1:=chr(i+48)+r1;
                for i:=9 downto 0 do
                for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end
        else
        begin
        r1:=chr(kq+48);
        dec(a[kq]);
        v:=10-kq;
        r2:=chr(v+48);
        dec(b[v]);
        for i:=0 to 9 do
        if a[i]>0 then
        begin
                u:=9-i;
                if b[u]<=0 then continue;
                v:=math.min(a[i],b[u]);
                a[i]:=a[i]-v; b[u]:=b[u]-v;
                for j:=1 to v do r1:=chr(i+48)+r1;
                for j:=1 to v do r2:=chr(u+48)+r2;
        end;
        for i:=9 downto 0 do
        for j:=1 to a[i] do r1:=chr(i+48)+r1;
        for i:=9 downto 0 do
        for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end;
        writeln(r1);
        writeln(r2);
end;
begin
        nhap;
        xuly;
        cc;
        lam;
end.

uses math;
const
        fi='';
var
        f:text;
        s,r1,r2:ansistring;
        n,kq,max,x,dis,l1,l2:longint;
        a,b,c,d:array [0..9] of longint;
procedure nhap;
var
        i:longint;
begin
        assign(f,fi);
        reset(f);
        readln(f,s);
        n:=length(s);
        for i:=1 to n do inc(a[ord(s[i])-48]);
        for i:=0 to 9 do b[i]:=a[i];
        dis:=1;
        kq:=-1;
        close(f);
end;
procedure cc;
var
        i,j,u,v,queo:longint;
begin
        c:=a; d:=b;
        v:=math.min(a[0],b[0]);
        if v=0 then exit;
        queo:=v;
        c[0]:=c[0]-v; d[0]:=d[0]-v;
        if queo>max then
        begin
                dis:=0;
                kq:=0;
                max:=queo;
                l1:=-1;
        end;
        for i:=1 to 9 do
        if c[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if d[u]<=0 then continue;
                dec(c[i]); dec(d[u]);
                x:=queo+1;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(c[j],d[v]);
                end;
                if x>max then
                begin
                        max:=x;
                        kq:=i;
                        dis:=0;
                        l1:=i; l2:=u;
                end;
                inc(c[i]); inc(d[u]);
        end;
end;
procedure xuly;
var
        i,j,u,v:longint;
begin
        for i:=1 to 9 do
        if a[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if b[u]<=0 then continue;
                dec(a[i]); dec(b[u]);
                x:=1;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(a[j],b[v]);
                end;
                if x>max then
                begin
                        max:=x;
                        kq:=i;
                end;
                inc(a[i]); inc(b[u]);
        end;
end;
procedure lam;
var
        i,j,u,v:longint;
begin
        if kq=-1 then
        begin
                writeln(s);
                writeln(s);
                halt;
        end;
        if dis=0 then
        begin
                v:=math.min(a[0],b[0]);
                for i:=1 to v do r1:='0'+r1;
                for i:=1 to v do r2:='0'+r2;
                a[0]:=a[0]-v; b[0]:=b[0]-v;
                if l1<>-1 then
                begin
                dec(a[l1]); dec(b[l2]);
                r1:=chr(l1+48)+r1;
                r2:=chr(l2+48)+r2;
                end;
                for i:=0 to 9 do
                if a[i]>0 then
                begin
                        u:=9-i;
                        if b[u]<=0 then continue;
                        v:=math.min(a[i],b[u]);
                        a[i]:=a[i]-v; b[u]:=b[u]-v;
                        for j:=1 to v do r1:=chr(i+48)+r1;
                        for j:=1 to v do r2:=chr(u+48)+r2;
                end;
               for i:=1 to v do r1:=r1+'0';
                for i:=1 to v do r2:=r2+'0';
                a[0]:=a[0]-v; b[0]:=b[0]-v;
        for i:=0 to 9 do
        for j:=1 to a[i] do r1:=chr(i+48)+r1;
        for i:=0 to 9 do
        for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end
        else
        begin
        r1:=chr(kq+48);
        dec(a[kq]);
        v:=10-kq;
        r2:=chr(v+48);
        dec(b[v]);
        for i:=0 to 9 do
        if a[i]>0 then
        begin
                u:=9-i;
                if b[u]<=0 then continue;
                v:=math.min(a[i],b[u]);
                a[i]:=a[i]-v; b[u]:=b[u]-v;
                for j:=1 to v do r1:=chr(i+48)+r1;
                for j:=1 to v do r2:=chr(u+48)+r2;
        end;
        v:=math.min(a[0],b[0]);
         for i:=1 to v do r1:=r1+'0';
                for i:=1 to v do r2:=r2+'0';
                a[0]:=a[0]-v; b[0]:=b[0]-v;
        for i:=0 to 9 do
        for j:=1 to a[i] do r1:=chr(i+48)+r1;
        for i:=0 to 9 do
        for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end;
        writeln(r1);
        writeln(r2);
end;
begin
        nhap;
        xuly;
        cc;
        lam;
end.

uses math;
const
        fi='';
var
        f:text;
        s,r1,r2:ansistring;
        n,kq,max,x,dis,l1,l2:longint;
        a,b,c,d:array [0..9] of longint;
procedure nhap;
var
        i:longint;
begin
        assign(f,fi);
        reset(f);
        readln(f,s);
        n:=length(s);
        for i:=1 to n do inc(a[ord(s[i])-48]);
        for i:=0 to 9 do b[i]:=a[i];
        dis:=1;
        kq:=-1;
        close(f);
end;
procedure cc;
var
        i,j,u,v,queo:longint;
begin
        c:=a; d:=b;
        v:=math.min(a[0],b[0]);
        if v=0 then exit;
        queo:=v;
        c[0]:=c[0]-v; d[0]:=d[0]-v;
        for i:=1 to 9 do
        if c[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if d[u]<=0 then continue;
                dec(c[i]); dec(d[u]);
                x:=queo+1;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(c[j],d[v]);
                end;
                if x>max then
                begin
                        max:=x;
                        kq:=i;
                        dis:=0;
                        l1:=i; l2:=u;
                end;
                inc(c[i]); inc(d[u]);
        end;
end;
procedure xuly;
var
        i,j,u,v:longint;
begin
        for i:=1 to 9 do
        if a[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if b[u]<=0 then continue;
                dec(a[i]); dec(b[u]);
                x:=1;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(a[j],b[v]);
                end;
                if x>max then
                begin
                        max:=x;
                        kq:=i;
                end;
                inc(a[i]); inc(b[u]);
        end;
end;
procedure lam;
var
        i,j,u,v:longint;
begin
        if kq=-1 then
        begin
                writeln(s);
                writeln(s);
                halt;
        end;
        if dis=0 then
        begin
                v:=math.min(a[0],b[0]);
                for i:=1 to v do r1:='0'+r1;
                for i:=1 to v do r2:='0'+r2;
                a[0]:=a[0]-v; b[0]:=b[0]-v;
                dec(a[l1]); dec(b[l2]);
                r1:=chr(l1+48)+r1;
                r2:=chr(l2+48)+r2;
                for i:=0 to 9 do
                if a[i]>0 then
                begin
                        u:=9-i;
                        if b[u]<=0 then continue;
                        v:=math.min(a[i],b[u]);
                        a[i]:=a[i]-v; b[u]:=b[u]-v;
                        for j:=1 to v do r1:=chr(i+48)+r1;
                        for j:=1 to v do r2:=chr(u+48)+r2;
                end;
                for i:=9 downto 0 do
                for j:=1 to a[i] do r1:=chr(i+48)+r1;
                for i:=9 downto 0 do
                for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end
        else
        begin
        r1:=chr(kq+48);
        dec(a[kq]);
        v:=10-kq;
        r2:=chr(v+48);
        dec(b[v]);
        for i:=0 to 9 do
        if a[i]>0 then
        begin
                u:=9-i;
                if b[u]<=0 then continue;
                v:=math.min(a[i],b[u]);
                a[i]:=a[i]-v; b[u]:=b[u]-v;
                for j:=1 to v do r1:=chr(i+48)+r1;
                for j:=1 to v do r2:=chr(u+48)+r2;
        end;
        for i:=9 downto 0 do
        for j:=1 to a[i] do r1:=chr(i+48)+r1;
        for i:=9 downto 0 do
        for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end;
        writeln(r1);
        writeln(r2);
end;
begin
        nhap;
        xuly;
        cc;
        lam;
end.

uses math;
const
        fi='';
var
        f:text;
        s,r1,r2:ansistring;
        n,kq,max,x,dis,l1,l2:longint;
        a,b,c,d:array [0..9] of longint;
procedure nhap;
var
        i:longint;
begin
        assign(f,fi);
        reset(f);
        readln(f,s);
        n:=length(s);
        for i:=1 to n do inc(a[ord(s[i])-48]);
        for i:=0 to 9 do b[i]:=a[i];
        dis:=1;
        kq:=-1;
        close(f);
end;
procedure cc;
var
        i,j,u,v,queo:longint;
begin
        c:=a; d:=b;
        v:=math.min(a[0],b[0]);
        if v=0 then exit;
        queo:=v;
        c[0]:=c[0]-v; d[0]:=d[0]-v;
        if queo>max then
        begin
                dis:=0;
                kq:=0;
                max:=queo;
                l1:=-1;
        end;
        for i:=1 to 9 do
        if c[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if d[u]<=0 then continue;
                dec(c[i]); dec(d[u]);
                x:=queo+1;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(c[j],d[v]);
                end;
                if x>max then
                begin
                        max:=x;
                        kq:=i;
                        dis:=0;
                        l1:=i; l2:=u;
                end;
                inc(c[i]); inc(d[u]);
        end;
end;
procedure xuly;
var
        i,j,u,v:longint;
begin
        for i:=1 to 9 do
        if a[i]>0 then
        begin
                if i=0 then u:=0
                else u:=10-i;
                if b[u]<=0 then continue;
                dec(a[i]); dec(b[u]);
                x:=1;
                for j:=0 to 9 do
                begin
                        v:=9-j;
                        x:=x+math.min(a[j],b[v]);
                end;
                if x>max then
                begin
                        max:=x;
                        kq:=i;
                end;
                inc(a[i]); inc(b[u]);
        end;
end;
procedure lam;
var
        i,j,u,v:longint;
begin
        if kq=-1 then
        begin
                writeln(s);
                writeln(s);
                halt;
        end;
        if dis=0 then
        begin
                v:=math.min(a[0],b[0]);
                for i:=1 to v do r1:='0'+r1;
                for i:=1 to v do r2:='0'+r2;
                a[0]:=a[0]-v; b[0]:=b[0]-v;
                if l1<>-1 then
                begin
                dec(a[l1]); dec(b[l2]);
                r1:=chr(l1+48)+r1;
                r2:=chr(l2+48)+r2;
                end;
                for i:=0 to 9 do
                if a[i]>0 then
                begin
                        u:=9-i;
                        if b[u]<=0 then continue;
                        v:=math.min(a[i],b[u]);
                        a[i]:=a[i]-v; b[u]:=b[u]-v;
                        for j:=1 to v do r1:=chr(i+48)+r1;
                        for j:=1 to v do r2:=chr(u+48)+r2;
                end;
                v:=math.min(a[0],b[0]);
               for i:=1 to v do r1:=r1+'0';
                for i:=1 to v do r2:=r2+'0';
                a[0]:=a[0]-v; b[0]:=b[0]-v;
        for i:=0 to 9 do
        for j:=1 to a[i] do r1:=chr(i+48)+r1;
        for i:=0 to 9 do
        for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end
        else
        begin
        r1:=chr(kq+48);
        dec(a[kq]);
        v:=10-kq;
        r2:=chr(v+48);
        dec(b[v]);
        for i:=0 to 9 do
        if a[i]>0 then
        begin
                u:=9-i;
                if b[u]<=0 then continue;
                v:=math.min(a[i],b[u]);
                a[i]:=a[i]-v; b[u]:=b[u]-v;
                for j:=1 to v do r1:=chr(i+48)+r1;
                for j:=1 to v do r2:=chr(u+48)+r2;
        end;
        v:=math.min(a[0],b[0]);
         for i:=1 to v do r1:=r1+'0';
                for i:=1 to v do r2:=r2+'0';
                a[0]:=a[0]-v; b[0]:=b[0]-v;
        for i:=0 to 9 do
        for j:=1 to a[i] do r1:=chr(i+48)+r1;
        for i:=0 to 9 do
        for j:=1 to b[i] do r2:=chr(i+48)+r2;
        end;
        writeln(r1);
        writeln(r2);
end;
begin
        nhap;
        xuly;
        cc;
        lam;
end.

Program cf99b;
const ch:array[0..9] of char='0123456789';
var t,a,b,c:array[0..9] of longint;
    n,i,j,k,l,pre,best,cur,cp,d:longint;
    cc:char;
function min(a,b:longint):longint;
begin
  if a<b then exit(a) else exit(b);
end;
function calc:longint;
var p:longint; aa:longint;
begin
  aa:=0;
  for p:=0 to 9 do aa:=aa+min(a[p],b[9-p]);
  exit(aa);
end;
begin
  while not eoln do
    begin
      read(cc);
      inc(t[ord(cc)-ord('0')]);
    end;
  best:=0;
  for i:=1 to 5 do
    if ((i=5) and (t[5]>=2))
    or ((i<>5) and (t[i]>=1) and (t[10-i]>=1))
  then
    begin
      for j:=0 to 9 do begin a[j]:=t[j];b[j]:=t[j];end;
      a[i]:=a[i]-1;
      b[10-i]:=b[10-i]-1;
      cur:=calc()+min(a[0]-min(a[0],b[9]),b[0]-min(b[0],a[9]))+1;
      if cur>best then
        begin
          best:=cur;
          cp:=i;
        end;
    end;
  if cp=0 then
    begin
      for i:=1 to 10 do
        for j:=1 to t[i mod 10] do
          write(i mod 10);
      writeln;
      for i:=1 to 10 do
        for j:=1 to t[i mod 10] do
          write(i mod 10);
    end
  else
    begin
      a:=t;b:=t;
      a[cp]:=a[cp]-1;
      b[10-cp]:=b[10-cp]-1;
      pre:=min(a[0]-min(a[0],b[9]),b[0]-min(b[0],a[9]));
      a[0]:=a[0]-pre;b[0]:=b[0]-pre;
      for i:=0 to 9 do c[i]:=min(a[i],b[9-i]);
      for i:=0 to 9 do a[i]:=a[i]-c[i];
      for i:=0 to 9 do b[9-i]:=b[9-i]-c[i];
      for i:=0 to 9 do
        if a[i]>0 then
          for j:=1 to a[i] do write(ch[i]);
      for i:=0 to 9 do
        if c[i]>0 then
          for j:=1 to c[i] do write(ch[i]);
      write(ch[cp]);
      for i:=1 to pre do write('0');
      writeln;
      for i:=0 to 9 do
        if b[i]>0 then
          for j:=1 to b[i] do write(ch[i]);
      for i:=0 to 9 do
        if c[i]>0 then
          for j:=1 to c[i] do write(ch[9-i]);
      write(ch[10-cp]);
      for i:=1 to pre do write('0');
    end;
end.

Var a,b:array[0..123]of longint;
ans:array[0..100333,1..2]of longint;
i,j,k,kk,x,p:longint;
s:ansistring;
  begin
    readln(s);
    for i:=1 to length(s) do
      inc(a[ord(s[i])-48]);
    for i:=0 to 9 do
      b[i]:=a[i];
    k:=0;
    x:=0;
    for i:=0 to 9 do
      begin
        while (a[i]>0)and(b[(10-i-x)mod 10]>0) do
          begin
            inc(k);
            ans[k,1]:=i;
            ans[k,2]:=(10-i-x)mod 10;
            dec(a[i]);
            dec(b[(10-i-x)mod 10]);
            if (i<>0)or((10-i-x)mod 10<>0) then x:=1
            else x:=0;
          end;
      end;
    kk:=k;
    for i:=0 to 9 do
     for j:=1 to a[i] do
      begin
        inc(k);
        ans[k,1]:=i;
      end;
    for i:=0 to 9 do
     for j:=1 to b[i] do
      begin
        inc(kk);
        ans[kk,2]:=i;
      end;
    for i:=k downto 1 do
      Write(ans[i,1]);
    Writeln;
    for i:=k downto 1 do
      Write(ans[i,2]);
     Writeln;
  end.

program shablon;

{$MODE OBJFPC}{$H+}
{$O+ R-  Q-}
{$COperators ON}

uses
   SysUtils,
   Math;

const inf = 1 / 0;
      nmax = 100 * 1000 + 100;

var n : longint;
    s : string;
    a, b : array[1 .. nmax] of longint;
    c1, c2 : array[0 .. 9] of longint;

procedure pout;
var i : longint;
begin
    for i := 1 to n do begin
        write(a[i]);
    end;
    writeln;
    for i := 1 to n do begin
        write(b[i]);
    end;
    {$IFNDEF ONLINE_JUDGE}
    close(input);
    close(output);
    {$ENDIF}
    halt(0);
end;

procedure pinit;
begin
    {$IFNDEF ONLINE_JUDGE}
    assign(input, 'input.txt');
    assign(output, 'output.txt');
    reset(input);
    rewrite(output);
    {$ENDIF}
    readln(s);
end;

function get(x : longint) : longint;
var i : longint;
begin
    result := 0;
    if c1[x] = 0 then exit;
    if c2[10 - x] = 0 then exit;
    dec(c1[x]);
    dec(c2[10 - x]);
    result := 1;
    for i := 0 to 9 do begin
        inc(result, min(c1[i], c2[9 - i]));
    end;
    inc(c1[x]);
    inc(c2[10 - x]);
end;

procedure solve;
var i, ans, ind, an, r, t1, t2, j, c10, nul0 : longint;
begin
    n := length(s);
    fillchar(c1, sizeof(c1), 0);
    fillchar(a, sizeof(a), 0);
    fillchar(b, sizeof(b), 0);
    for i := 1 to n do begin
        inc(c1[strtoint(s[i])]);
    end;
    c2 := c1;
    ans := -1;
    ind := 0;
    r := 0;
    c10 := c1[0];
    for nul0 := 0 to c10 do begin
        for i := 9 downto 1 do begin
            an := get(i) + nul0;
            if an > ans then begin
                ans := an;
                ind := i;
                r := nul0;
            end;
        end;
        dec(c1[0]);
        dec(c2[0]);
    end;
    c1[0] := c10 - r;
    c2[0] := c10 - r;
    if ans <> 0 then begin
        a[n - r] := ind;
        b[n - r] := 10 - ind;
        dec(c1[ind]);
        dec(c2[10 - ind]);
        j := 9;
        t1 := 0;
        t2 := 0;
        inc(r);
    end
    else begin
        j := -1;
        t1 := 0;
        t2 := 0;
    end;
    for i := n - r downto 1 do begin
        while (j > -1) and (min(c1[j], c2[9 - j]) = 0) do begin
            dec(j);
        end;
        if j > -1 then begin
            a[i] := j;
            b[i] := 9 - j;
            dec(c1[j]);
            dec(c2[9 - j]);
        end
        else begin
            while (t1 < 10) and (c1[t1] = 0) do begin
                inc(t1);
            end;
            if t1 < 10 then begin
                a[i] := t1;
                dec(c1[t1]);
            end
            else begin
                writeln('WTF?!1');
                halt(3);
            end;
            while (t2 < 10) and (c2[t2] = 0) do begin
                inc(t2);
            end;
            if t2 < 10 then begin
                b[i] := t2;
                dec(c2[t2]);
            end
            else begin
                writeln('WTF?!2');
                halt(3);
            end;
        end;
    end;
end;

begin
    pinit;
    solve;
    pout;
end.

program shablon;

{$MODE OBJFPC}{$H+}
{$O+ R-  Q-}
{$COperators ON}

uses
   SysUtils,
   Math;

const inf = 1 / 0;
      nmax = 100 * 1000 + 100;

var n : longint;
    s : string;
    a, b : array[1 .. nmax] of longint;
    c1, c2 : array[0 .. 9] of longint;

procedure pout;
var i : longint;
begin
    for i := 1 to n do begin
        write(a[i]);
    end;
    writeln;
    for i := 1 to n do begin
        write(b[i]);
    end;
    {$IFNDEF ONLINE_JUDGE}
    close(input);
    close(output);
    {$ENDIF}
    halt(0);
end;

procedure pinit;
begin
    {$IFNDEF ONLINE_JUDGE}
    assign(input, 'input.txt');
    assign(output, 'output.txt');
    reset(input);
    rewrite(output);
    {$ENDIF}
    readln(s);
end;

function get(x : longint) : longint;
var i : longint;
begin
    result := 0;
    if c1[x] = 0 then exit;
    if c2[10 - x] = 0 then exit;
    dec(c1[x]);
    dec(c2[10 - x]);
    result := 1;
    for i := 0 to 9 do begin
        inc(result, min(c1[i], c2[9 - i]));
    end;
    inc(c1[x]);
    inc(c2[10 - x]);
end;

procedure solve;
var i, ans, ind, an, r, t1, t2, j, c10, nul0 : longint;
begin
    n := length(s);
    fillchar(c1, sizeof(c1), 0);
    fillchar(a, sizeof(a), 0);
    fillchar(b, sizeof(b), 0);
    for i := 1 to n do begin
        inc(c1[strtoint(s[i])]);
    end;
    c2 := c1;
    ans := -1;
    ind := 0;
    r := 0;
    c10 := c1[0];
    for nul0 := 0 to c10 do begin
        for i := 9 downto 1 do begin
            an := get(i);
            if an  + nul0 > ans then begin
                ans := an;
                ind := i;
                r := nul0;
            end;
        end;
        dec(c1[0]);
        dec(c2[0]);
    end;
    c1[0] := c10 - r;
    c2[0] := c10 - r;
    if ans <> 0 then begin
        a[n - r] := ind;
        b[n - r] := 10 - ind;
        dec(c1[ind]);
        dec(c2[10 - ind]);
        j := 9;
        t1 := 0;
        t2 := 0;
        inc(r);
    end
    else begin
        j := -1;
        t1 := 0;
        t2 := 0;
    end;
    for i := n - r downto 1 do begin
        while (j > -1) and (min(c1[j], c2[9 - j]) = 0) do begin
            dec(j);
        end;
        if j > -1 then begin
            a[i] := j;
            b[i] := 9 - j;
            dec(c1[j]);
            dec(c2[9 - j]);
        end
        else begin
            while (t1 < 10) and (c1[t1] = 0) do begin
                inc(t1);
            end;
            if t1 < 10 then begin
                a[i] := t1;
                dec(c1[t1]);
            end
            else begin
                writeln('WTF?!1');
                halt(3);
            end;
            while (t2 < 10) and (c2[t2] = 0) do begin
                inc(t2);
            end;
            if t2 < 10 then begin
                b[i] := t2;
                dec(c2[t2]);
            end
            else begin
                writeln('WTF?!2');
                halt(3);
            end;
        end;
    end;
end;

begin
    pinit;
    solve;
    pout;
end.

{$H+}
var
a1:string;
num,pre,prepre,vxod,max,alter:longint;
function min(a1,a2:longint):longint;
begin
     if a1<a2 then min:=a1 else min:=a2;
end;
procedure poisk(a:string;b,dozv:byte);
var
c,s:array[0..9]of longint;
verx,nizz:array[1..100000]of byte;
a1:string;
d,i,p,nach,mini,vt,j,k:longint;
begin
for i:=0 to 9 do begin c[i]:=0;s[i]:=0;end;
d:=length(a);
for i:=1 to d do begin
p:=ord(a[i])-ord('0');
inc(c[p]);inc(s[p]);
end;
nach:=1;
if b=1 then
if (c[9]<>0)and(s[1]<>0)then begin
    verx[1]:=9;nizz[1]:=1;
    dec(c[9]);dec(s[1]);inc(nach);
    end;
if b=2 then
    if (c[5]<>0)and(s[5]<>0)then begin
    verx[1]:=5;nizz[1]:=5;
    dec(c[5]);dec(s[5]);inc(nach);
    end;
if b=3 then
        if (c[8]<>0)and(s[2]<>0)then begin
        verx[1]:=8;nizz[1]:=2;
        dec(c[8]);dec(s[2]);inc(nach);
        end;
if b=4 then
            if (c[7]<>0)and(s[3]<>0)then begin
            verx[1]:=7;nizz[1]:=3;
            dec(c[7]);dec(s[3]);inc(nach);
            end;
if b=5 then
                if (c[6]<>0)and(s[4]<>0)then begin
                verx[1]:=6;nizz[1]:=4;
                dec(c[6]);dec(s[4]);inc(nach);
                end;
mini:=min(c[0],s[9]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=0;nizz[i]:=9;
    end;
    c[0]:=c[0]-mini;s[9]:=s[9]-mini;
nach:=nach+mini;
mini:=min(c[1],s[8]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=1;nizz[i]:=8;
    end;
    c[1]:=c[1]-mini;s[8]:=s[8]-mini;
nach:=nach+mini;
mini:=min(c[2],s[7]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=2;nizz[i]:=7;
    end;
    c[2]:=c[2]-mini;s[7]:=s[7]-mini;
nach:=nach+mini;
mini:=min(c[3],s[6]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=3;nizz[i]:=6;
    end;
    c[3]:=c[3]-mini;s[6]:=s[6]-mini;
nach:=nach+mini;
mini:=min(c[4],s[5]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=4;nizz[i]:=5;
    end;
    c[4]:=c[4]-mini;s[5]:=s[5]-mini;
nach:=nach+mini;
mini:=min(c[5],s[4]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=5;nizz[i]:=4;
    end;
    c[5]:=c[5]-mini;s[4]:=s[4]-mini;
nach:=nach+mini;
mini:=min(c[6],s[3]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=6;nizz[i]:=3;
    end;
    c[6]:=c[6]-mini;s[3]:=s[3]-mini;
nach:=nach+mini;
mini:=min(c[7],s[2]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=7;nizz[i]:=2;
    end;
    c[7]:=c[7]-mini;s[2]:=s[2]-mini;
nach:=nach+mini;
mini:=min(c[8],s[1]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=8;nizz[i]:=1;
    end;
    c[8]:=c[8]-mini;s[1]:=s[1]-mini;
nach:=nach+mini;
mini:=min(c[9],s[0]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=9;nizz[i]:=0;
    end;
    c[9]:=c[9]-mini;s[0]:=s[0]-mini;
nach:=nach+mini;vt:=nach;
for j:=1 to 9 do begin
    if c[j]<>0 then
    for i:=nach to nach+c[j]-1 do begin
        verx[i]:=j;
        end;
nach:=nach+c[j];
end;
nach:=vt;
for j:=1 to 9 do begin
    if s[j]<>0 then
    for i:=nach to nach+s[j]-1 do begin
        nizz[i]:=j;
        end;
nach:=nach+s[j];
end;
k:=0;
for i:=d downto 1 do
    if (verx[i]=0)and(nizz[i]=0)then inc(k) else break;
d:=i;
if dozv=1 then begin
for i:=d downto 1 do write(verx[i]);for i:=1 to k do write(0);
writeln;
for i:=d downto 1 do write(nizz[i]);for i:=1 to k do write(0);
writeln;
end;
pre:=0;prepre:=0;
for i:=d downto 1 do
    if(verx[i]+nizz[i]=9)then inc(pre);
for i:=1 downto 1 do
if(verx[i]+nizz[i]=10)then inc(prepre);
end;
begin
read(a1);
max:=0;
for num:=1 to 5 do begin
poisk(a1,num,0);
if (max<pre)and(prepre>0)then begin
                              max:=pre;
                              vxod:=num;
                              end else
if (prepre>0)then alter:=num;
end;
if vxod>0 then
poisk(a1,vxod,1)else poisk(a1,alter,1);
end.

{$H+}
var
a1:string;
num,pre,prepre,vxod,max,alter:longint;
function min(a1,a2:longint):longint;
begin
     if a1<a2 then min:=a1 else min:=a2;
end;
procedure poisk(a:string;b,dozv:byte);
var
c,s:array[0..9]of longint;
verx,nizz:array[1..100000]of byte;
a1:string;
d,i,p,nach,mini,vt,j,k:longint;
begin
for i:=0 to 9 do begin c[i]:=0;s[i]:=0;end;
d:=length(a);
for i:=1 to d do begin
p:=ord(a[i])-ord('0');
inc(c[p]);inc(s[p]);
end;
nach:=1;
if b=1 then
if (c[9]<>0)and(s[1]<>0)then begin
    verx[1]:=9;nizz[1]:=1;
    dec(c[9]);dec(s[1]);inc(nach);
    end;
if b=2 then
    if (c[5]<>0)and(s[5]<>0)then begin
    verx[1]:=5;nizz[1]:=5;
    dec(c[5]);dec(s[5]);inc(nach);
    end;
if b=3 then
        if (c[8]<>0)and(s[2]<>0)then begin
        verx[1]:=8;nizz[1]:=2;
        dec(c[8]);dec(s[2]);inc(nach);
        end;
if b=4 then
            if (c[7]<>0)and(s[3]<>0)then begin
            verx[1]:=7;nizz[1]:=3;
            dec(c[7]);dec(s[3]);inc(nach);
            end;
if b=5 then
                if (c[6]<>0)and(s[4]<>0)then begin
                verx[1]:=6;nizz[1]:=4;
                dec(c[6]);dec(s[4]);inc(nach);
                end;
mini:=min(c[0],s[9]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=0;nizz[i]:=9;
    end;
    c[0]:=c[0]-mini;s[9]:=s[9]-mini;
nach:=nach+mini;
mini:=min(c[1],s[8]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=1;nizz[i]:=8;
    end;
    c[1]:=c[1]-mini;s[8]:=s[8]-mini;
nach:=nach+mini;
mini:=min(c[2],s[7]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=2;nizz[i]:=7;
    end;
    c[2]:=c[2]-mini;s[7]:=s[7]-mini;
nach:=nach+mini;
mini:=min(c[3],s[6]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=3;nizz[i]:=6;
    end;
    c[3]:=c[3]-mini;s[6]:=s[6]-mini;
nach:=nach+mini;
mini:=min(c[4],s[5]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=4;nizz[i]:=5;
    end;
    c[4]:=c[4]-mini;s[5]:=s[5]-mini;
nach:=nach+mini;
mini:=min(c[5],s[4]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=5;nizz[i]:=4;
    end;
    c[5]:=c[5]-mini;s[4]:=s[4]-mini;
nach:=nach+mini;
mini:=min(c[6],s[3]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=6;nizz[i]:=3;
    end;
    c[6]:=c[6]-mini;s[3]:=s[3]-mini;
nach:=nach+mini;
mini:=min(c[7],s[2]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=7;nizz[i]:=2;
    end;
    c[7]:=c[7]-mini;s[2]:=s[2]-mini;
nach:=nach+mini;
mini:=min(c[8],s[1]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=8;nizz[i]:=1;
    end;
    c[8]:=c[8]-mini;s[1]:=s[1]-mini;
nach:=nach+mini;
mini:=min(c[9],s[0]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=9;nizz[i]:=0;
    end;
    c[9]:=c[9]-mini;s[0]:=s[0]-mini;
nach:=nach+mini;vt:=nach;
for j:=1 to 9 do begin
    if c[j]<>0 then
    for i:=nach to nach+c[j]-1 do begin
        verx[i]:=j;
        end;
nach:=nach+c[j];
end;
nach:=vt;
for j:=1 to 9 do begin
    if s[j]<>0 then
    for i:=nach to nach+s[j]-1 do begin
        nizz[i]:=j;
        end;
nach:=nach+s[j];
end;
k:=0;
for i:=d downto 1 do
    if (verx[i]=0)and(nizz[i]=0)then inc(k) else break;
d:=i;
if dozv=1 then begin
for i:=d downto 1 do write(verx[i]);for i:=1 to k do write(0);
writeln;
for i:=d downto 1 do write(nizz[i]);for i:=1 to k do write(0);
writeln;
end;
pre:=0;prepre:=0;
for i:=d downto 1 do
    if(verx[i]+nizz[i]=9)then inc(pre);
if(verx[1]+nizz[1]=10)then inc(prepre);
end;
begin
read(a1);
max:=0;
for num:=1 to 5 do begin
poisk(a1,num,0);
if (max<pre)and(prepre=1)then vxod:=num;
if (prepre=1)then alter:=num;
end;
if vxod>0 then
poisk(a1,vxod,1)else poisk(a1,alter,1);
end.

{$H+}
var
a1:string;
num,pre,prepre,vxod,max:longint;
function min(a1,a2:longint):longint;
begin
     if a1<a2 then min:=a1 else min:=a2;
end;
procedure poisk(a:string;b,dozv:byte);
var
c,s:array[0..9]of longint;
verx,nizz:array[1..100000]of byte;
a1:string;
d,i,p,nach,mini,vt,j,k:longint;
begin
for i:=0 to 9 do begin c[i]:=0;s[i]:=0;end;
d:=length(a);
for i:=1 to d do begin
p:=ord(a[i])-ord('0');
inc(c[p]);inc(s[p]);
end;
nach:=1;
if b=1 then
if (c[9]<>0)and(s[1]<>0)then begin
    verx[1]:=9;nizz[1]:=1;
    dec(c[9]);dec(s[1]);inc(nach);
    end;
if b=2 then
    if (c[5]<>0)and(s[5]<>0)then begin
    verx[1]:=5;nizz[1]:=5;
    dec(c[5]);dec(s[5]);inc(nach);
    end;
if b=3 then
        if (c[8]<>0)and(s[2]<>0)then begin
        verx[1]:=8;nizz[1]:=2;
        dec(c[8]);dec(s[2]);inc(nach);
        end;
if b=4 then
            if (c[7]<>0)and(s[3]<>0)then begin
            verx[1]:=7;nizz[1]:=3;
            dec(c[7]);dec(s[3]);inc(nach);
            end;
if b=5 then
                if (c[6]<>0)and(s[4]<>0)then begin
                verx[1]:=6;nizz[1]:=4;
                dec(c[6]);dec(s[4]);inc(nach);
                end;
mini:=min(c[0],s[9]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=0;nizz[i]:=9;
    end;
    c[0]:=c[0]-mini;s[9]:=s[9]-mini;
nach:=nach+mini;
mini:=min(c[1],s[8]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=1;nizz[i]:=8;
    end;
    c[1]:=c[1]-mini;s[8]:=s[8]-mini;
nach:=nach+mini;
mini:=min(c[2],s[7]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=2;nizz[i]:=7;
    end;
    c[2]:=c[2]-mini;s[7]:=s[7]-mini;
nach:=nach+mini;
mini:=min(c[3],s[6]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=3;nizz[i]:=6;
    end;
    c[3]:=c[3]-mini;s[6]:=s[6]-mini;
nach:=nach+mini;
mini:=min(c[4],s[5]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=4;nizz[i]:=5;
    end;
    c[4]:=c[4]-mini;s[5]:=s[5]-mini;
nach:=nach+mini;
mini:=min(c[5],s[4]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=5;nizz[i]:=4;
    end;
    c[5]:=c[5]-mini;s[4]:=s[4]-mini;
nach:=nach+mini;
mini:=min(c[6],s[3]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=6;nizz[i]:=3;
    end;
    c[6]:=c[6]-mini;s[3]:=s[3]-mini;
nach:=nach+mini;
mini:=min(c[7],s[2]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=7;nizz[i]:=2;
    end;
    c[7]:=c[7]-mini;s[2]:=s[2]-mini;
nach:=nach+mini;
mini:=min(c[8],s[1]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=8;nizz[i]:=1;
    end;
    c[8]:=c[8]-mini;s[1]:=s[1]-mini;
nach:=nach+mini;
mini:=min(c[9],s[0]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=9;nizz[i]:=0;
    end;
    c[9]:=c[9]-mini;s[0]:=s[0]-mini;
nach:=nach+mini;vt:=nach;
for j:=1 to 9 do begin
    if c[j]<>0 then
    for i:=nach to nach+c[j]-1 do begin
        verx[i]:=j;
        end;
nach:=nach+c[j];
end;
nach:=vt;
for j:=1 to 9 do begin
    if s[j]<>0 then
    for i:=nach to nach+s[j]-1 do begin
        nizz[i]:=j;
        end;
nach:=nach+s[j];
end;
k:=0;
for i:=d downto 1 do
    if (verx[i]=0)and(nizz[i]=0)then inc(k) else break;
d:=i;
if dozv=1 then begin
for i:=d downto 1 do write(verx[i]);for i:=1 to k do write(0);
writeln;
for i:=d downto 1 do write(nizz[i]);for i:=1 to k do write(0);
writeln;
end;
pre:=0;prepre:=0;
for i:=d downto 1 do
    if(verx[i]+nizz[i]=9)then inc(pre);
if(verx[1]+nizz[1]=10)then inc(prepre);
end;
begin
read(a1);
max:=0;
for num:=1 to 5 do begin
poisk(a1,num,0);
if (max<pre)and(prepre=1)then vxod:=num;
end;
poisk(a1,vxod,1);
end.

{$H+}
var
a1:string;
num,pre,prepre,vxod,max,alter:longint;
function min(a1,a2:longint):longint;
begin
     if a1<a2 then min:=a1 else min:=a2;
end;
procedure poisk(a:string;b,dozv:byte);
var
c,s:array[0..9]of longint;
verx,nizz:array[1..100000]of byte;
a1:string;
d,i,p,nach,mini,vt,j,k:longint;
begin
for i:=0 to 9 do begin c[i]:=0;s[i]:=0;end;
d:=length(a);
for i:=1 to d do begin
p:=ord(a[i])-ord('0');
inc(c[p]);inc(s[p]);
end;
nach:=1;
if b=1 then
if (c[9]<>0)and(s[1]<>0)then begin
    verx[1]:=9;nizz[1]:=1;
    dec(c[9]);dec(s[1]);inc(nach);
    end;
if b=2 then
    if (c[5]<>0)and(s[5]<>0)then begin
    verx[1]:=5;nizz[1]:=5;
    dec(c[5]);dec(s[5]);inc(nach);
    end;
if b=3 then
        if (c[8]<>0)and(s[2]<>0)then begin
        verx[1]:=8;nizz[1]:=2;
        dec(c[8]);dec(s[2]);inc(nach);
        end;
if b=4 then
            if (c[7]<>0)and(s[3]<>0)then begin
            verx[1]:=7;nizz[1]:=3;
            dec(c[7]);dec(s[3]);inc(nach);
            end;
if b=5 then
                if (c[6]<>0)and(s[4]<>0)then begin
                verx[1]:=6;nizz[1]:=4;
                dec(c[6]);dec(s[4]);inc(nach);
                end;
mini:=min(c[0],s[9]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=0;nizz[i]:=9;
    end;
    c[0]:=c[0]-mini;s[9]:=s[9]-mini;
nach:=nach+mini;
mini:=min(c[1],s[8]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=1;nizz[i]:=8;
    end;
    c[1]:=c[1]-mini;s[8]:=s[8]-mini;
nach:=nach+mini;
mini:=min(c[2],s[7]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=2;nizz[i]:=7;
    end;
    c[2]:=c[2]-mini;s[7]:=s[7]-mini;
nach:=nach+mini;
mini:=min(c[3],s[6]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=3;nizz[i]:=6;
    end;
    c[3]:=c[3]-mini;s[6]:=s[6]-mini;
nach:=nach+mini;
mini:=min(c[4],s[5]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=4;nizz[i]:=5;
    end;
    c[4]:=c[4]-mini;s[5]:=s[5]-mini;
nach:=nach+mini;
mini:=min(c[5],s[4]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=5;nizz[i]:=4;
    end;
    c[5]:=c[5]-mini;s[4]:=s[4]-mini;
nach:=nach+mini;
mini:=min(c[6],s[3]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=6;nizz[i]:=3;
    end;
    c[6]:=c[6]-mini;s[3]:=s[3]-mini;
nach:=nach+mini;
mini:=min(c[7],s[2]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=7;nizz[i]:=2;
    end;
    c[7]:=c[7]-mini;s[2]:=s[2]-mini;
nach:=nach+mini;
mini:=min(c[8],s[1]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=8;nizz[i]:=1;
    end;
    c[8]:=c[8]-mini;s[1]:=s[1]-mini;
nach:=nach+mini;
mini:=min(c[9],s[0]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=9;nizz[i]:=0;
    end;
    c[9]:=c[9]-mini;s[0]:=s[0]-mini;
nach:=nach+mini;vt:=nach;
k:=min(c[0],s[0]);
c[0]:=c[0]-k;s[0]:=s[0]-k;
for j:=0 to 9 do begin
    if c[j]<>0 then
    for i:=nach to nach+c[j]-1 do begin
        verx[i]:=j;
        end;
nach:=nach+c[j];
end;
nach:=vt;
for j:=0 to 9 do begin
    if s[j]<>0 then
    for i:=nach to nach+s[j]-1 do begin
        nizz[i]:=j;
        end;
nach:=nach+s[j];
end;
{k:=0;
for i:=d downto 1 do
    if (verx[i]=0)and(nizz[i]=0)then inc(k) else break;}
d:=i;
if dozv=1 then begin
for i:=d downto 1 do write(verx[i]);for i:=1 to k do write(0);
writeln;
for i:=d downto 1 do write(nizz[i]);for i:=1 to k do write(0);
writeln;
end;
pre:=0;prepre:=0;
for i:=d downto 1 do
    if(verx[i]+nizz[i]=9)then inc(pre);
if(verx[1]+nizz[1]=10)then inc(prepre);
end;
begin
read(a1);
max:=0;
for num:=1 to 5 do begin
poisk(a1,num,0);
if (max<pre)and(prepre>=1)then begin
                                    max:=pre;
                                    vxod:=num;
                                    end;
if (prepre>=1)then alter:=num;
end;
if vxod>0 then
poisk(a1,vxod,1)else poisk(a1,alter,1);
end.

{$H+}
var
c,s:array[0..9]of longint;
verx,nizz:array[1..100000]of byte;
a:string;

d,i,p,nach,mini,vt,j:longint;
function min(a1,a2:longint):longint;
begin
     if a1<a2 then min:=a1 else min:=a2;
end;
begin
read(a);
d:=length(a);
for i:=1 to d do begin
p:=ord(a[i])-ord('0');
inc(c[p]);inc(s[p]);
end;
nach:=1;
for i:=nach to s[0] do begin
   verx[i]:=0;nizz[i]:=0;
   end;
nach:=nach+s[0];
if (c[9]<>0)and(s[1]<>0)then begin
    verx[s[0]+1]:=9;nizz[s[0]+1]:=1;
    dec(c[9]);dec(s[1]);inc(nach);
    end else
    if (c[5]<>0)and(s[5]<>0)then begin
    verx[s[0]+1]:=5;nizz[s[0]+1]:=5;
    dec(c[5]);dec(s[5]);inc(nach);
    end else
        if (c[8]<>0)and(s[2]<>0)then begin
        verx[s[0]+1]:=8;nizz[s[0]+1]:=2;
        dec(c[8]);dec(s[2]);inc(nach);
        end else
            if (c[7]<>0)and(s[3]<>0)then begin
            verx[s[0]+1]:=7;nizz[s[0]+1]:=3;
            dec(c[7]);dec(s[3]);inc(nach);
            end else
                if (c[6]<>0)and(s[4]<>0)then begin
                verx[s[0]+1]:=6;nizz[s[0]+1]:=4;
                dec(c[6]);dec(s[4]);inc(nach);
                end;
mini:=min(c[1],s[8]);
for i:=nach to nach+mini do begin
    verx[i]:=1;nizz[i]:=8;
    end;
    c[1]:=c[1]-mini;s[8]:=s[8]-mini;
nach:=nach+mini;
mini:=min(c[2],s[7]);
for i:=nach to nach+mini do begin
    verx[i]:=2;nizz[i]:=7;
    end;
    c[2]:=c[2]-mini;s[7]:=s[7]-mini;
nach:=nach+mini;
mini:=min(c[3],s[6]);
for i:=nach to nach+mini do begin
    verx[i]:=3;nizz[i]:=6;
    end;
    c[3]:=c[3]-mini;s[6]:=s[6]-mini;
nach:=nach+mini;
mini:=min(c[4],s[5]);
for i:=nach to nach+mini do begin
    verx[i]:=4;nizz[i]:=5;
    end;
    c[4]:=c[4]-mini;s[5]:=s[5]-mini;
nach:=nach+mini;
mini:=min(c[5],s[4]);
for i:=nach to nach+mini do begin
    verx[i]:=5;nizz[i]:=4;
    end;
    c[5]:=c[5]-mini;s[4]:=s[4]-mini;
nach:=nach+mini;
mini:=min(c[6],s[3]);
for i:=nach to nach+mini do begin
    verx[i]:=6;nizz[i]:=3;
    end;
    c[6]:=c[6]-mini;s[3]:=s[3]-mini;
nach:=nach+mini;
mini:=min(c[7],s[2]);
for i:=nach to nach+mini do begin
    verx[i]:=7;nizz[i]:=2;
    end;
    c[7]:=c[7]-mini;s[2]:=s[2]-mini;
nach:=nach+mini;
mini:=min(c[4],s[5]);
for i:=nach to nach+mini do begin
    verx[i]:=8;nizz[i]:=1;
    end;
    c[8]:=c[8]-mini;s[1]:=s[1]-mini;
nach:=nach+mini;vt:=nach;
for j:=1 to 9 do begin
    for i:=nach to nach+c[j] do verx[i]:=j;
    nach:=nach+c[j];
end;
nach:=vt;
for j:=1 to 9 do begin
    for i:=nach to nach+s[j] do nizz[i]:=j;
    nach:=nach+s[j];
end;
for i:=d downto 1 do write(verx[i]);
writeln;
for i:=d downto 1 do write(nizz[i]);
writeln;
end.

{$H+}
var
a1:string;
num,pre,prepre,vxod,max,alter:longint;
function min(a1,a2:longint):longint;
begin
     if a1<a2 then min:=a1 else min:=a2;
end;
procedure poisk(a:string;b,dozv:byte);
var
c,s:array[0..9]of longint;
verx,nizz:array[1..100000]of byte;
a1:string;
d,i,p,nach,mini,vt,j,k:longint;
begin
for i:=0 to 9 do begin c[i]:=0;s[i]:=0;end;
d:=length(a);
for i:=1 to d do begin
p:=ord(a[i])-ord('0');
inc(c[p]);inc(s[p]);
end;
nach:=1;
if b=1 then
if (c[9]<>0)and(s[1]<>0)then begin
    verx[1]:=9;nizz[1]:=1;
    dec(c[9]);dec(s[1]);inc(nach);
    end;
if b=2 then
    if (c[5]<>0)and(s[5]<>0)then begin
    verx[1]:=5;nizz[1]:=5;
    dec(c[5]);dec(s[5]);inc(nach);
    end;
if b=3 then
        if (c[8]<>0)and(s[2]<>0)then begin
        verx[1]:=8;nizz[1]:=2;
        dec(c[8]);dec(s[2]);inc(nach);
        end;
if b=4 then
            if (c[7]<>0)and(s[3]<>0)then begin
            verx[1]:=7;nizz[1]:=3;
            dec(c[7]);dec(s[3]);inc(nach);
            end;
if b=5 then
                if (c[6]<>0)and(s[4]<>0)then begin
                verx[1]:=6;nizz[1]:=4;
                dec(c[6]);dec(s[4]);inc(nach);
                end;
mini:=min(c[0],s[9]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=0;nizz[i]:=9;
    end;
    c[0]:=c[0]-mini;s[9]:=s[9]-mini;
nach:=nach+mini;
mini:=min(c[1],s[8]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=1;nizz[i]:=8;
    end;
    c[1]:=c[1]-mini;s[8]:=s[8]-mini;
nach:=nach+mini;
mini:=min(c[2],s[7]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=2;nizz[i]:=7;
    end;
    c[2]:=c[2]-mini;s[7]:=s[7]-mini;
nach:=nach+mini;
mini:=min(c[3],s[6]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=3;nizz[i]:=6;
    end;
    c[3]:=c[3]-mini;s[6]:=s[6]-mini;
nach:=nach+mini;
mini:=min(c[4],s[5]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=4;nizz[i]:=5;
    end;
    c[4]:=c[4]-mini;s[5]:=s[5]-mini;
nach:=nach+mini;
mini:=min(c[5],s[4]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=5;nizz[i]:=4;
    end;
    c[5]:=c[5]-mini;s[4]:=s[4]-mini;
nach:=nach+mini;
mini:=min(c[6],s[3]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=6;nizz[i]:=3;
    end;
    c[6]:=c[6]-mini;s[3]:=s[3]-mini;
nach:=nach+mini;
mini:=min(c[7],s[2]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=7;nizz[i]:=2;
    end;
    c[7]:=c[7]-mini;s[2]:=s[2]-mini;
nach:=nach+mini;
mini:=min(c[8],s[1]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=8;nizz[i]:=1;
    end;
    c[8]:=c[8]-mini;s[1]:=s[1]-mini;
nach:=nach+mini;
mini:=min(c[9],s[0]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=9;nizz[i]:=0;
    end;
    c[9]:=c[9]-mini;s[0]:=s[0]-mini;
nach:=nach+mini;vt:=nach;
for j:=1 to 9 do begin
    if c[j]<>0 then
    for i:=nach to nach+c[j]-1 do begin
        verx[i]:=j;
        end;
nach:=nach+c[j];
end;
nach:=vt;
for j:=1 to 9 do begin
    if s[j]<>0 then
    for i:=nach to nach+s[j]-1 do begin
        nizz[i]:=j;
        end;
nach:=nach+s[j];
end;
k:=0;
for i:=d downto 1 do
    if (verx[i]=0)and(nizz[i]=0)then inc(k) else break;
d:=i;
if dozv=1 then begin
for i:=d downto 1 do write(verx[i]);for i:=1 to k do write(0);
writeln;
for i:=d downto 1 do write(nizz[i]);for i:=1 to k do write(0);
writeln;
end;
pre:=0;prepre:=0;
for i:=d downto 1 do
    if(verx[i]+nizz[i]=9)then inc(pre);
for i:=d downto 1 do
if(verx[i]+nizz[i]=10)then inc(prepre);
end;
begin
read(a1);
max:=0;
for num:=1 to 5 do begin
poisk(a1,num,0);
if (max<pre)and(prepre>0)then begin
                              max:=pre;
                              vxod:=num;
                              end;
if (prepre>0)then alter:=num;
end;
if vxod>0 then
poisk(a1,vxod,1)else poisk(a1,alter,1);
end.

{$H+}
var
c,s:array[0..9]of longint;
verx,nizz:array[1..100000]of byte;
a:string;
d,i,p,nach,mini,vt,j,k:longint;
function min(a1,a2:longint):longint;
begin
     if a1<a2 then min:=a1 else min:=a2;
end;
begin
read(a);
d:=length(a);
for i:=1 to d do begin
p:=ord(a[i])-ord('0');
inc(c[p]);inc(s[p]);
end;
nach:=1;
{for i:=nach to s[0] do begin
   verx[i]:=0;nizz[i]:=0;
   end;
nach:=nach+s[0];}
if (c[9]<>0)and(s[1]<>0)then begin
    verx[1]:=9;nizz[1]:=1;
    dec(c[9]);dec(s[1]);inc(nach);
    end else
    if (c[5]<>0)and(s[5]<>0)then begin
    verx[1]:=5;nizz[1]:=5;
    dec(c[5]);dec(s[5]);inc(nach);
    end else
        if (c[8]<>0)and(s[2]<>0)then begin
        verx[1]:=8;nizz[1]:=2;
        dec(c[8]);dec(s[2]);inc(nach);
        end else
            if (c[7]<>0)and(s[3]<>0)then begin
            verx[1]:=7;nizz[1]:=3;
            dec(c[7]);dec(s[3]);inc(nach);
            end else
                if (c[6]<>0)and(s[4]<>0)then begin
                verx[1]:=6;nizz[1]:=4;
                dec(c[6]);dec(s[4]);inc(nach);
                end;
mini:=min(c[0],s[9]);
for i:=nach to nach+mini do begin
    verx[i]:=0;nizz[i]:=9;
    end;
    c[0]:=c[0]-mini;s[9]:=s[9]-mini;
nach:=nach+mini;
mini:=min(c[1],s[8]);
for i:=nach to nach+mini do begin
    verx[i]:=1;nizz[i]:=8;
    end;
    c[1]:=c[1]-mini;s[8]:=s[8]-mini;
nach:=nach+mini;
mini:=min(c[2],s[7]);
for i:=nach to nach+mini do begin
    verx[i]:=2;nizz[i]:=7;
    end;
    c[2]:=c[2]-mini;s[7]:=s[7]-mini;
nach:=nach+mini;
mini:=min(c[3],s[6]);
for i:=nach to nach+mini do begin
    verx[i]:=3;nizz[i]:=6;
    end;
    c[3]:=c[3]-mini;s[6]:=s[6]-mini;
nach:=nach+mini;
mini:=min(c[4],s[5]);
for i:=nach to nach+mini do begin
    verx[i]:=4;nizz[i]:=5;
    end;
    c[4]:=c[4]-mini;s[5]:=s[5]-mini;
nach:=nach+mini;
mini:=min(c[5],s[4]);
for i:=nach to nach+mini do begin
    verx[i]:=5;nizz[i]:=4;
    end;
    c[5]:=c[5]-mini;s[4]:=s[4]-mini;
nach:=nach+mini;
mini:=min(c[6],s[3]);
for i:=nach to nach+mini do begin
    verx[i]:=6;nizz[i]:=3;
    end;
    c[6]:=c[6]-mini;s[3]:=s[3]-mini;
nach:=nach+mini;
mini:=min(c[7],s[2]);
for i:=nach to nach+mini do begin
    verx[i]:=7;nizz[i]:=2;
    end;
    c[7]:=c[7]-mini;s[2]:=s[2]-mini;
nach:=nach+mini;
mini:=min(c[8],s[1]);
for i:=nach to nach+mini do begin
    verx[i]:=8;nizz[i]:=1;
    end;
    c[8]:=c[8]-mini;s[1]:=s[1]-mini;
nach:=nach+mini;
mini:=min(c[9],s[0]);
for i:=nach to nach+mini do begin
    verx[i]:=9;nizz[i]:=0;
    end;
    c[9]:=c[9]-mini;s[0]:=s[0]-mini;
nach:=nach+mini;vt:=nach;
for j:=1 to 9 do begin
    if c[j]<>0 then
    for i:=nach to nach+c[j]-1 do begin
        verx[i]:=j;
        end;
nach:=nach+c[j];
end;
nach:=vt;
for j:=1 to 9 do begin
    if s[j]<>0 then
    for i:=nach to nach+s[j]-1 do begin
        nizz[i]:=j;
        end;
nach:=nach+s[j];
end;
k:=0;
for i:=d downto 1 do
    if (verx[i]=0)and(nizz[i]=0)then inc(k) else break;
d:=i;
for i:=d downto 1 do write(verx[i]);for i:=1 to k do write(0);
writeln;
for i:=d downto 1 do write(nizz[i]);for i:=1 to k do write(0);
writeln;
end.

{$H+}
var
c,s:array[0..9]of longint;
verx,nizz:array[1..100000]of byte;
a:string;
d,i,p,nach,mini,vt,j,k:longint;
function min(a1,a2:longint):longint;
begin
     if a1<a2 then min:=a1 else min:=a2;
end;
begin
read(a);
d:=length(a);
for i:=1 to d do begin
p:=ord(a[i])-ord('0');
inc(c[p]);inc(s[p]);
end;
nach:=1;
{for i:=nach to s[0] do begin
   verx[i]:=0;nizz[i]:=0;
   end;
nach:=nach+s[0];}
if (c[9]<>0)and(s[1]<>0)then begin
    verx[1]:=9;nizz[1]:=1;
    dec(c[9]);dec(s[1]);inc(nach);
    end else
    if (c[5]<>0)and(s[5]<>0)then begin
    verx[1]:=5;nizz[1]:=5;
    dec(c[5]);dec(s[5]);inc(nach);
    end else
        if (c[8]<>0)and(s[2]<>0)then begin
        verx[1]:=8;nizz[1]:=2;
        dec(c[8]);dec(s[2]);inc(nach);
        end else
            if (c[7]<>0)and(s[3]<>0)then begin
            verx[1]:=7;nizz[1]:=3;
            dec(c[7]);dec(s[3]);inc(nach);
            end else
                if (c[6]<>0)and(s[4]<>0)then begin
                verx[1]:=6;nizz[1]:=4;
                dec(c[6]);dec(s[4]);inc(nach);
                end;
mini:=min(c[0],s[9]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=0;nizz[i]:=9;
    end;
    c[0]:=c[0]-mini;s[9]:=s[9]-mini;
nach:=nach+mini;
mini:=min(c[1],s[8]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=1;nizz[i]:=8;
    end;
    c[1]:=c[1]-mini;s[8]:=s[8]-mini;
nach:=nach+mini;
mini:=min(c[2],s[7]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=2;nizz[i]:=7;
    end;
    c[2]:=c[2]-mini;s[7]:=s[7]-mini;
nach:=nach+mini;
mini:=min(c[3],s[6]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=3;nizz[i]:=6;
    end;
    c[3]:=c[3]-mini;s[6]:=s[6]-mini;
nach:=nach+mini;
mini:=min(c[4],s[5]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=4;nizz[i]:=5;
    end;
    c[4]:=c[4]-mini;s[5]:=s[5]-mini;
nach:=nach+mini;
mini:=min(c[5],s[4]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=5;nizz[i]:=4;
    end;
    c[5]:=c[5]-mini;s[4]:=s[4]-mini;
nach:=nach+mini;
mini:=min(c[6],s[3]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=6;nizz[i]:=3;
    end;
    c[6]:=c[6]-mini;s[3]:=s[3]-mini;
nach:=nach+mini;
mini:=min(c[7],s[2]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=7;nizz[i]:=2;
    end;
    c[7]:=c[7]-mini;s[2]:=s[2]-mini;
nach:=nach+mini;
mini:=min(c[8],s[1]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=8;nizz[i]:=1;
    end;
    c[8]:=c[8]-mini;s[1]:=s[1]-mini;
nach:=nach+mini;
mini:=min(c[9],s[0]);
for i:=nach to nach+mini-1 do begin
    verx[i]:=9;nizz[i]:=0;
    end;
    c[9]:=c[9]-mini;s[0]:=s[0]-mini;
nach:=nach+mini;vt:=nach;
for j:=1 to 9 do begin
    if c[j]<>0 then
    for i:=nach to nach+c[j]-1 do begin
        verx[i]:=j;
        end;
nach:=nach+c[j];
end;
nach:=vt;
for j:=1 to 9 do begin
    if s[j]<>0 then
    for i:=nach to nach+s[j]-1 do begin
        nizz[i]:=j;
        end;
nach:=nach+s[j];
end;
k:=0;
for i:=d downto 1 do
    if (verx[i]=0)and(nizz[i]=0)then inc(k) else break;
d:=i;
for i:=d downto 1 do write(verx[i]);for i:=1 to k do write(0);
writeln;
for i:=d downto 1 do write(nizz[i]);for i:=1 to k do write(0);
writeln;
end.

program fda;
type
        arr=array[0..10] of longint;
var
        s:ansistring;
        i,j,k,e,t,n,m:longint;
        a:arr;
        b:arr;
        ans:arr;//ans:array[0..10] of longint;
        ans1,ans2:longint;
        s1,s2,ss:ansistring;
function min(x,y:longint):longint;
begin
        if x<y then exit(x) else exit(y);
end;
procedure work(a,b:arr);
var
        c:arr;//array[0..10] of longint;
        i,j,k:longint;
begin
        k:=0;
        for i:=0 to 9 do begin
                j:=min(a[i],b[9-i]);
                c[i]:=j;
                k:=k+c[i];
                a[i]:=a[i]-j;
                b[9-i]:=b[9-i]-j;
        end;
        j:=min(a[0],b[0]);
        c[10]:=j;
        k:=k+j;
        if k>ans1 then begin
                ans1:=k;
                ans:=c;
                ans2:=m;
        end;
end;
begin
        readln(s);
        for i:=1 to length(s) do begin
                val(s[i],j);
                inc(a[j]);
                inc(b[j]);
        end;
        ans[10]:=min(a[0],b[0])-1;
        ans1:=ans[10]-1;
        ans2:=0;
        for i:=1 to 9 do begin
                if (a[i]>0) and (b[10-i]>0) then begin
                        dec(a[i]);
                        dec(b[10-i]);
                        m:=i;
                        work(a,b);
                        inc(a[i]);
                        inc(b[10-i]);
                end;
        end;
        str(ans2,s1);
        str((10-ans2) mod 10,s2);
        dec(a[ans2]);
        dec(b[(10-ans2) mod 10]);
        for i:=1 to ans[10] do begin
                s1:=s1+'0';
                s2:=s2+'0';
                dec(a[0]);
                dec(b[0]);
        end;
        for i:=9 downto 0 do begin
                for j:=1 to ans[i] do begin
                        str(i,ss);s1:=ss+s1;
                        str(9-i,ss);s2:=ss+s2;
                        dec(a[i]);
                        dec(b[9-i]);
                end;
        end;
        for i:=0 to 9 do begin
                for j:=1 to a[i] do begin
                        str(i,ss);s1:=ss+s1;
                end;
                for j:=1 to b[i] do begin
                        str(i,ss);s2:=ss+s2;
                end;
        end;
        writeln(s1);
        writeln(s2);
end.

uses math;

var j,last,max,tmp,i1,t,m,n,i:longint;
ok:boolean;
s:ansistring;
a1,a2,f1,f2,c,a:array[0..200000]of longint;

 begin
  readln(s);
  t:=0;
  n:=length(s);
  for i:=1 to n do
   if s[i]='0' then t:=t+1 else
    begin
     m:=m+1;
     a[m]:=ord(s[i])-48;
     inc(c[a[m]]);
    end;

  max:=-1;
  last:=1;

  for i1:=1 to 9 do
    if c[i1]>0 then
      begin
       if c[10-i1]>0 then
         begin
          for i:=0 to 9 do
            begin
             f1[i]:=c[i];
             f2[i]:=c[i];
            end;

          dec(f1[i1]);
          dec(f2[10-i1]);

          tmp:=1;

          for i:=0 to 9 do
            begin
             tmp:=tmp+min(f1[i],f2[9-i]);
            end;

          if tmp>max then
            begin
             max:=tmp;
             last:=i1;
            end;

         end;
      end;

  if max=-1 then
    begin
     for i:=1 to m do
       begin
        a1[m-i+1]:=a[i];
        a2[m-i+1]:=a[i];
       end;
    end else
    begin
     for i:=0 to 9 do
       begin
        f1[i]:=c[i];
        f2[i]:=c[i];
       end;

     dec(f1[last]);
     dec(f2[10-last]);

     a1[1]:=last;
     a2[1]:=10-last;

     for j:=2 to m do
       begin
        ok:=true;
        for i:=1 to 9 do
          if f1[i]>0 then
            if f2[9-i]>0 then
              begin
               dec(f1[i]);
               dec(f2[9-i]);
               ok:=false;
               a1[j]:=i;
               a2[j]:=9-i;
               break;
              end;

        if ok then
          begin
           for i:=1 to 9 do
             if f1[i]>0 then
               begin
                a1[j]:=i;
                dec(f1[i]);
                break;
               end;

           for i:=1 to 9 do
             if f2[i]>0 then
               begin
                a2[j]:=i;
                dec(f2[i]);
                break;
               end;
          end;
       end;
    end;

  for i:=m downto 1 do write(a1[i]);
  for i:=1 to t do write(0);
  writeln;

  for i:=m downto 1 do write(a2[i]);
  for i:=1 to t do write(0);
  writeln;

 end.

uses math;

var j,last,max,tmp,i1,t,m,n,i:longint;
ok:boolean;
s:ansistring;
a1,a2,f1,f2,c,a:array[0..200000]of longint;

 begin
  readln(s);
  t:=0;
  n:=length(s);
  for i:=1 to n do
   if s[i]='0' then t:=t+1 else
    begin
     m:=m+1;
     a[m]:=ord(s[i])-48;
     inc(c[a[m]]);
    end;

  max:=-1;
  last:=1;

  for i1:=1 to 9 do
    if c[i1]>0 then
      begin
       if c[10-i1]>0 then
         begin
          for i:=0 to 9 do
            begin
             f1[i]:=c[i];
             f2[i]:=c[i];
            end;

          dec(f1[i1]);
          dec(f2[10-i1]);

          tmp:=1;

          for i:=0 to 4 do
            begin
             tmp:=tmp+min(f1[i],f2[9-i]);
            end;

          if tmp>max then
            begin
             max:=tmp;
             last:=i1;
            end;

         end;
      end;

  if max=-1 then
    begin
     for i:=1 to m do
       begin
        a1[m-i+1]:=a[i];
        a2[m-i+1]:=a[i];
       end;
    end else
    begin
     for i:=0 to 9 do
       begin
        f1[i]:=c[i];
        f2[i]:=c[i];
       end;

     dec(f1[last]);
     dec(f2[10-last]);

     a1[1]:=last;
     a2[1]:=10-last;

     for j:=2 to m do
       begin
        ok:=true;
        for i:=1 to 4 do
          if f1[i]>0 then
            if f2[9-i]>0 then
              begin
               dec(f1[i]);
               dec(f2[9-i]);
               ok:=false;
               a1[j]:=i;
               a2[j]:=9-i;
               break;
              end;

        if ok then
          begin
           for i:=1 to 9 do
             if f1[i]>0 then
               begin
                a1[j]:=i;
                dec(f1[i]);
                break;
               end;

           for i:=1 to 9 do
             if f2[i]>0 then
               begin
                a2[j]:=i;
                dec(f2[i]);
                break;
               end;
          end;
       end;
    end;

  for i:=m downto 1 do write(a1[i]);
  for i:=1 to t do write(0);
  writeln;

  for i:=m downto 1 do write(a2[i]);
  for i:=1 to t do write(0);
  writeln;

 end.

var st:ansistring;
    a,b,c:array[0..10] of longint;
    max,maxk,c1,i,e,j,o:longint;
    x,y:array[0..1000000] of longint;

function min(a,b:longint):longint;
  begin
    if a<b then exit(a) else exit(b);
  end;

begin
  readln(st);
  fillchar(a,sizeof(a),0);
  for i:=1 to length(st) do
    inc(a[ord(st[i])-48]);
  max:=0;
  maxk:=0;
  for i:=1 to 5 do
    begin
      b:=a;
      c:=a;
      dec(b[i]);
      dec(c[10-i]);
      if (b[i]>=0) and (c[10-i]>=0) then
        begin
          e:=1;
          for j:=1 to 8 do
            e:=e+min(b[j],c[9-j]);
          if e>max then
            begin
              max:=e;
              maxk:=i;
            end;
        end;
    end;
  if (max=0) and (a[0]=0) then
    begin
      writeln(st);
      writeln(st);
    end
  else
    if max=0 then
      begin
        for i:=1 to length(st) do if st[i]<>'0' then write(st[i]);
        for i:=1 to a[0] do write('0');writeln;
        for i:=1 to length(st) do if st[i]<>'0' then write(st[i]);
        for i:=1 to a[0] do write('0');writeln;
      end
    else
    begin
      o:=0;
      for i:=1 to a[0] do
        begin
          inc(o);
          x[o]:=0;
          y[o]:=0;
        end;
      inc(o);
      x[o]:=maxk;
      y[o]:=10-maxk;
      b:=a;
      dec(a[maxk]);
      dec(b[10-maxk]);
      for i:=1 to 8 do
        begin
          c1:=min(a[i],b[9-i]);
          a[i]:=a[i]-c1;
          b[9-i]:=b[9-i]-c1;
          for j:=1 to c1 do
            begin
              inc(o);
              x[o]:=i;
              y[o]:=9-i;
            end;
        end;
      for i:=1 to 9 do
        for j:=1 to a[i] do
          write(i);
      for i:=o downto 1 do write(x[i]);writeln;
      for i:=1 to 9 do
        for j:=1 to b[i] do
          write(i);
      for i:=o downto 1 do write(y[i]);writeln;
    end;
end.

var st:ansistring;
    a,b,c:array[0..10] of longint;
    max,maxk,c1,i,e,j,o:longint;
    x,y:array[0..1000000] of longint;

function min(a,b:longint):longint;
  begin
    if a<b then exit(a) else exit(b);
  end;

begin
  readln(st);
  fillchar(a,sizeof(a),0);
  for i:=1 to length(st) do
    inc(a[ord(st[i])-48]);
  max:=0;
  maxk:=0;
  for i:=1 to 5 do
    begin
      b:=a;
      c:=a;
      dec(b[i]);
      dec(c[10-i]);
      if (b[i]>=0) and (c[10-i]>=0) then
        begin
          e:=1;
          for j:=1 to 4 do
            e:=e+min(b[j],c[9-j])*2;
          if e>max then
            begin
              max:=e;
              maxk:=i;
            end;
        end;
    end;
  if max=0 then
    begin
      writeln(st);
      writeln(st);
    end
  else
    begin
      o:=0;
      for i:=1 to a[0] do
        begin
          inc(o);
          x[o]:=0;
          y[o]:=0;
        end;
      inc(o);
      x[o]:=maxk;
      y[o]:=10-maxk;
      b:=a;
      dec(a[maxk]);
      dec(b[10-maxk]);
      for i:=1 to 8 do
        for j:=1 to min(a[i],b[9-i]) do
          begin
            inc(o);
            x[o]:=i;
            y[o]:=9-i;
            c1:=min(a[i],b[9-i]);
            a[i]:=a[i]-c1;
            b[9-i]:=b[9-i]-c1;
          end;
      for i:=1 to 9 do
        for j:=1 to a[i] do
          write(i);
      for i:=o downto 1 do write(x[i]);writeln;
      for i:=1 to 9 do
        for j:=1 to b[i] do
          write(i);
      for i:=o downto 1 do write(y[i]);writeln;
    end;
end.

var st:ansistring;
    a,b,c:array[0..10] of longint;
    max,maxk,c1,i,e,j,o:longint;
    x,y:array[0..1000000] of longint;

function min(a,b:longint):longint;
  begin
    if a<b then exit(a) else exit(b);
  end;

begin
  readln(st);
  fillchar(a,sizeof(a),0);
  for i:=1 to length(st) do
    inc(a[ord(st[i])-48]);
  max:=0;
  maxk:=0;
  for i:=1 to 5 do
    begin
      b:=a;
      c:=a;
      dec(b[i]);
      dec(c[10-i]);
      if (b[i]>=0) and (c[10-i]>=0) then
        begin
          e:=1;
          for j:=1 to 4 do
            e:=e+min(b[j],c[9-j])*2;
          if e>max then
            begin
              max:=e;
              maxk:=i;
            end;
        end;
    end;
  if (max=0) and (a[0]=0) then
    begin
      writeln(st);
      writeln(st);
    end
  else
    if max=0 then
      begin
        for i:=1 to length(st) do if st[i]<>'0' then write(st[i]);
        for i:=1 to a[0] do write('0');writeln;
        for i:=1 to length(st) do if st[i]<>'0' then write(st[i]);
        for i:=1 to a[0] do write('0');writeln;
      end
    else
    begin
      o:=0;
      for i:=1 to a[0] do
        begin
          inc(o);
          x[o]:=0;
          y[o]:=0;
        end;
      inc(o);
      x[o]:=maxk;
      y[o]:=10-maxk;
      b:=a;
      dec(a[maxk]);
      dec(b[10-maxk]);
      for i:=1 to 8 do
        for j:=1 to min(a[i],b[9-i]) do
          begin
            inc(o);
            x[o]:=i;
            y[o]:=9-i;
            c1:=min(a[i],b[9-i]);
            a[i]:=a[i]-c1;
            b[9-i]:=b[9-i]-c1;
          end;
      for i:=1 to 9 do
        for j:=1 to a[i] do
          write(i);
      for i:=o downto 1 do write(x[i]);writeln;
      for i:=1 to 9 do
        for j:=1 to b[i] do
          write(i);
      for i:=o downto 1 do write(y[i]);writeln;
    end;
end.

uses
  math;

var
  u1,u2,a:array[0..500500]of longint;
  kc1,kc2,kc:array[0..100]of longint;
  m1,m2,cr,m,c,i,n,pc1,pc2,c1,c2,max,qq:longint;
  s:ansistring;

begin
  readln(s);
  n:=length(s);
  fillchar(kc,sizeof(kc),$0);
  for i:=1 to n do a[i]:=ord(s[i])-48;
  for i:=1 to n do inc(kc[a[i]]);
  m:=n;
  while (kc[0]>0)do begin
    u1[m]:=0;
    u2[m]:=0;
    dec(m);
    dec(kc[0]);
  end;
  pc1:=-1;pc2:=-1;
  max:=-1;
  for c1:=0 to 9 do begin
    c2:=10-c1;
    if (kc[c1]=0)or(kc[c2]=0)then continue;
    dec(kc[c1]);dec(kc[c2]);  cr:=1;
    for c:=0 to 4 do begin
      qq:=min(kc[c],kc[9-c]);
      inc(cr,qq);
    end;
    if (cr>max)then begin max:=cr;pc1:=c1;pc2:=c2; end;
    inc(kc[c1]);inc(kc[c2]);
  end;
  u1[m]:=pc1;
  u2[m]:=pc2;
  dec(m);
  c1:=pc1;c2:=pc2;
  for c:=0 to 9 do begin kc1[c]:=kc[c];kc2[c]:=kc[c]; end;
  dec(kc1[c1]);
  dec(kc2[c2]);
  for c:=0 to 9 do begin
    qq:=min(kc1[c],kc2[9-c]);
    for i:=1 to qq do begin
      u1[m]:=c;
      u2[m]:=9-c;
      dec(m);
    end;
    dec(kc1[c],qq);dec(kc2[9-c],qq);
  end;
  m1:=m;m2:=m;
  for i:=0 to 9 do begin
    while (kc1[i]>0)do begin
      u1[m1]:=i;
      dec(m1);
      dec(kc1[i]);
    end;
    while (kc2[i]>0)do begin
      u2[m2]:=i;
      dec(m2);
      dec(kc2[i]);
    end;
  end;
  for i:=1 to n do write(u1[i]);
  writeln;
  for i:=1 to n do write(u2[i]);
end.

uses
  math;

var
  u1,u2,a:array[0..500500]of longint;
  kc1,kc2,kc:array[0..100]of longint;
  m1,m2,cr,m,c,i,n,pc1,pc2,c1,c2,max,qq:longint;
  s:ansistring;

begin
  readln(s);
  n:=length(s);
  fillchar(kc,sizeof(kc),$0);
  for i:=1 to n do a[i]:=ord(s[i])-48;
  for i:=1 to n do inc(kc[a[i]]);
  m:=n;
  while (kc[0]>0)do begin
    u1[m]:=0;
    u2[m]:=0;
    dec(m);
    dec(kc[0]);
  end;
  pc1:=-1;pc2:=-1;
  max:=-1;
  for c1:=0 to 9 do begin
    c2:=10-c1;
    if (kc[c1]=0)or(kc[c2]=0)then continue;
    dec(kc[c1]);dec(kc[c2]);  cr:=1;
    for c:=0 to 4 do begin
      qq:=min(kc[c],kc[9-c]);
      inc(cr,qq);
    end;
    if (cr>max)then begin max:=cr;pc1:=c1;pc2:=c2; end;
    inc(kc[c1]);inc(kc[c2]);
  end;
  if (pc1<>-1)then begin
    u1[m]:=pc1;
    u2[m]:=pc2;
    dec(m);
    c1:=pc1;c2:=pc2;
    for c:=0 to 9 do begin kc1[c]:=kc[c];kc2[c]:=kc[c]; end;
    dec(kc1[c1]);
    dec(kc2[c2]);
    for c:=0 to 9 do begin
      qq:=min(kc1[c],kc2[9-c]);
      for i:=1 to qq do begin
        u1[m]:=c;
        u2[m]:=9-c;
        dec(m);
      end;
      dec(kc1[c],qq);dec(kc2[9-c],qq);
    end;
  end else for c:=0 to 9 do begin kc1[c]:=kc[c];kc2[c]:=kc[c]; end;
  m1:=m;m2:=m;
  for i:=0 to 9 do begin
    while (kc1[i]>0)do begin
      u1[m1]:=i;
      dec(m1);
      dec(kc1[i]);
    end;
    while (kc2[i]>0)do begin
      u2[m2]:=i;
      dec(m2);
      dec(kc2[i]);
    end;
  end;
  for i:=1 to n do write(u1[i]);
  writeln;
  for i:=1 to n do write(u2[i]);
end.

var f1,f2:text;
A:array[1..100011] of longint;
D1,D2,kq1,kq2:array[1..100011] of longint;
s1,s2,ss1,ss2:array[0..10] of longint;
i,n,j,x:longint;
Found:boolean;
ch:char;
st:ansistring;
rem:longint;
res:longint;

Procedure try (vt,gt:longint);
var count:longint;
ok:boolean;
i,j:longint;
Begin
        ok:=false;
        i:=vt;
        count:=n-vt;
        if (s1[gt]>0) and (s2[10-gt]>0) then
        begin
          d1[vt]:=gt;
          d2[vt]:=10-gt;
          dec(s1[gt]);
          dec(s2[10-gt]);
          ok:=true;
          i:=vt-1;
        end;

        if ok then
        begin
          count:=count+1;
          for i:=vt-1 downto 1 do
          begin
            found:=false;
            for j:=0 to 9 do
            if (s1[j]>0) and (s2[9-j]>0) then
            begin
              found:=true;
              dec(s1[j]);
              dec(s2[9-j]);
              D1[i]:=j;
              D2[i]:=9-j;
              inc(count);
              break;
            end;
            if found=false then break;
          End;
        end;
        if found=false then
        for j:=i downto 1 do
        begin
          for x:=0 to 9 do
          if s1[x]>0 then begin D1[j]:=x;dec(s1[x]); break; end;
          for x:=0 to 9 do
          if s2[x]>0 then begin d2[j]:=x;dec(s2[x]); break; end;
        end;
        if count>res then
        begin
          res:=count;
          kq1:=d1;
          kq2:=d2;
        end;
End;

begin
        assign(f1,'');reset(f1);
        assign(f2,'');rewrite(F2);
        readln(f1,st);
        n:=length(st);
        for i:=1 to n do
        begin
          a[i]:=ord(st[i])-48;
          inc(s1[a[i]]);
          inc(s2[a[i]]);
        End;
        res:=-1;

          ss1:=s1;
          ss2:=s2;
          for j:=1 to 9 do
          Begin
          s1:=ss1;
          s2:=ss2;
          try(n,j);
          end;
        j:=1;
        while (kq1[j]=0) and (kq2[j]=0) and (j<=n) do
        begin
          inc(j);
        end;

        for i:=j to n do
          write(f2,kq1[i]);
        for i:=1 to j-1 do write(f2,0);
          writeln(f2);
        for i:=j to n do
          write(f2,kq2[i]);
        for i:=1 to j-1 do write(f2,0);
        close(f1);
        close(f2);
end.

var f1,f2:text;
A:array[1..100011] of longint;
D1,D2,kq1,kq2:array[1..100011] of longint;
s1,s2,ss1,ss2:array[0..10] of longint;
i,n,j,x:longint;
Found:boolean;
ch:char;
st:ansistring;
rem:longint;
res:longint;

Procedure try (vt,gt:longint);
var count:longint;
ok:boolean;
i,j:longint;
Begin
        ok:=false;
        i:=vt;
        count:=n-vt;
        if (s1[gt]>0) and (s2[10-gt]>0) then
        begin
          d1[vt]:=gt;
          d2[vt]:=10-gt;
          dec(s1[gt]);
          dec(s2[10-gt]);
          ok:=true;
          i:=vt-1;
        end;

        if ok then
        begin
          count:=count+1;
          for i:=vt-1 downto 1 do
          begin
            found:=false;
            for j:=0 to 9 do
            if (s1[j]>0) and (s2[9-j]>0) then
            begin
              found:=true;
              dec(s1[j]);
              dec(s2[9-j]);
              D1[i]:=j;
              D2[i]:=9-j;
              inc(count);
              break;
            end;
            if found=false then break;
          End;
        end;
        if found=false then
        for j:=i downto 1 do
        begin
          for x:=0 to 9 do
          if s1[x]>0 then begin D1[j]:=x;dec(s1[x]); break; end;
          for x:=0 to 9 do
          if s2[x]>0 then begin d2[j]:=x;dec(s2[x]); break; end;
        end;
        if count>res then
        begin
          res:=count;
          kq1:=d1;
          kq2:=d2;
        end;
End;

begin
        assign(f1,'');reset(f1);
        assign(f2,'');rewrite(F2);
        readln(f1,st);
        n:=length(st);
        for i:=1 to n do
        begin
          a[i]:=ord(st[i])-48;
          inc(s1[a[i]]);
          inc(s2[a[i]]);
        End;
        res:=-1;

          ss1:=s1;
          ss2:=s2;
          for j:=1 to 9 do
          Begin
          s1:=ss1;
          s2:=ss2;
          try(n,j);
          end;

        for i:=1 to n do
          write(f2,kq1[i]);writeln(f2);
        for i:=1 to n do
          write(f2,kq2[i]);
        close(f1);
        close(f2);
end.

var f1,f2:text;
A:array[1..100011] of longint;
D1,D2,kq1,kq2:array[1..100011] of longint;
s1,s2,ss1,ss2:array[0..9] of longint;
i,n,j,x:longint;
Found:boolean;
ch:char;
st:ansistring;
rem:longint;
res:longint;

Procedure try (vt,gt:longint);
var count:longint;
ok:boolean;
i,j:longint;
Begin
        ok:=false;
        i:=vt;
        count:=n-vt;
        if (s1[gt]>0) and (s2[10-gt]>0) then
        begin
          d1[vt]:=gt;
          d2[vt]:=10-gt;
          dec(s1[gt]);
          dec(s2[10-gt]);
          ok:=true;
          i:=vt-1;
        end;

        if ok then
        begin
          count:=count+1;
          for i:=vt-1 downto 1 do
          begin
            found:=false;
            for j:=1 to 9 do
            if (s1[j]>0) and (s2[9-j]>0) then
            begin
              found:=true;
              dec(s1[j]);
              dec(s2[9-j]);
              D1[i]:=j;
              D2[i]:=9-j;
              inc(count);
              break;
            end;
            if found=false then break;
          End;
        end;
        if found=false then
        for j:=i downto 1 do
        begin
          for x:=0 to 9 do
          if s1[x]>0 then begin D1[j]:=x;dec(s1[x]); break; end;
          for x:=0 to 9 do
          if s2[x]>0 then begin d2[j]:=x;dec(s2[x]); break; end;
        end;
        if count>res then
        begin
          res:=count;
          kq1:=d1;
          kq2:=d2;
        end;
End;

begin
        assign(f1,'');reset(f1);
        assign(f2,'');rewrite(F2);
        readln(f1,st);
        n:=length(st);
        for i:=1 to n do
        begin
          a[i]:=ord(st[i])-48;
          inc(s1[a[i]]);
          inc(s2[a[i]]);
        End;
        res:=-1;
        for i:=n downto 1 do
        if s1[0]>0 then
        begin
         dec(s1[0]);
         dec(s2[0]);
         d1[i]:=0;
         d2[i]:=0;
        end
        else
        Begin
          ss1:=s1;
          ss2:=s2;
          for j:=1 to 9 do
          Begin
          s1:=ss1;
          s2:=ss2;
          try(i,j);
          end;
          break;
        End;

        for i:=1 to n do
          write(f2,kq1[i]);writeln(f2);
        for i:=1 to n do
          write(f2,kq2[i]);
        close(f1);
        close(f2);
end.

var f1,f2:text;
A:array[1..100011] of longint;
D1,D2:array[1..100011] of longint;
s1,s2:array[0..9] of longint;
i,n,j,x:longint;
Found:boolean;
ch:char;
st:ansistring;
rem:longint;
begin
        assign(f1,'');reset(f1);
        assign(f2,'');rewrite(F2);
        readln(f1,st);
        n:=length(st);
        for i:=1 to n do
        begin
          a[i]:=ord(st[i])-48;
          inc(s1[a[i]]);
          inc(s2[a[i]]);
        End;
        for i:=n downto 1 do
        begin
          if s1[0]>0 then
          begin
            dec(s1[0]);
            dec(s2[0]);
            D1[i]:=0;
            D2[i]:=0;
          end
          else
          begin
            if d1[i+1]=0 then rem:=0 else rem:=1;
            found:=false;
            for j:=1 to 9 do
            if (s1[j]>0) and (s2[10-rem-j]>0) then
            begin
              found:=true;
              dec(s1[j]);
              dec(s2[10-rem-j]);
              D1[i]:=j;
              D2[i]:=10-rem-j;
              break;
            end;
            if found=false then break;
          end;
        end;
        for j:=i downto 1 do
        begin
          for x:=0 to 9 do
          if s1[x]>0 then begin D1[j]:=x;dec(s1[x]); break; end;
          for x:=0 to 9 do
          if s2[x]>0 then begin d2[j]:=x;dec(s2[x]); break; end;
        end;
        for i:=1 to n do write(F2,d1[i]);writeln(f2);
        for i:=1 to n do write(f2,d2[i]);
        close(f1);
        close(f2);
end.

var f1,f2:text;
A:array[1..100011] of longint;
D1,D2:array[1..100011] of longint;
s1,s2:array[0..9] of longint;
i,n,j,x:longint;
Found:boolean;
ch:char;
st:ansistring;
rem:longint;
begin
        assign(f1,'');reset(f1);
        assign(f2,'');rewrite(F2);
        readln(f1,st);
        n:=length(st);
        for i:=1 to n do
        begin
          a[i]:=ord(st[i])-48;
          inc(s1[a[i]]);
          inc(s2[a[i]]);
        End;
        for i:=n downto 1 do
        begin
          if s1[0]>0 then
          begin
            dec(s1[0]);
            dec(s2[0]);
            D1[i]:=0;
            D2[i]:=0;
          end
          else
          begin
            if d1[i+1]=0 then rem:=0 else rem:=1;
            found:=false;
            for j:=1 to 9 do
            if (s1[j]>0) and (s2[10-rem-j]>0) then
            begin
              found:=true;
              dec(s1[j]);
              dec(s2[10-rem-j]);
              D1[i]:=j;
              D2[i]:=10-rem-j;
              break;
            end;
            if found=false then break;
          end;
        end;
        if found=false then
        for j:=i downto 1 do
        begin
          for x:=0 to 9 do
          if s1[x]>0 then begin D1[j]:=x;dec(s1[x]); break; end;
          for x:=0 to 9 do
          if s2[x]>0 then begin d2[j]:=x;dec(s2[x]); break; end;
        end;
        for i:=1 to n do write(F2,d1[i]);writeln(f2);
        for i:=1 to n do write(f2,d2[i]);
        close(f1);
        close(f2);
end.

uses math;
var i,j,x,y,n,m,max,p,r,rez,ii: longint;
    b1,b2,o: array[0..10] of longint;
    c: char;
    s1,s2,r1,r2: ansistring;
begin
     while not eoln do
      begin
       read(c);
       inc(b1[ord(c)-48]);
      end;
     o:=b1;
     b2:=b1;
     for ii:=0 to o[0] do
      begin
          max:=ii;
          for i:=1 to 9 do
           begin
            if (b1[i]=0) or (b2[10-i]=0) then continue;
            dec(b1[i]);dec(b2[10-i]);
            x:=r;
            for j:=0 to 9 do
             begin
              y:=min(b1[j],b2[9-j]);
              x:=x+y;
             end;
            if x>max then
             begin
              max:=x;
              p:=i;
             end;
            inc(b1[i]);inc(b2[10-i]);
           end;
          if max=ii then
           begin
            if rez<>0 then continue;
            rez:=max;
            r1:='';r2:='';
            for i:=9 downto 0 do
               for j:=1 to b1[i] do r1:=r1+chr(i+48);
            r1:=r1+s1;
            for i:=9 downto 0 do
               for j:=1 to b2[i] do r2:=r2+chr(i+48);
            r2:=r2+s2;
            continue;
           end;
          if max<=rez then continue;
          rez:=max;
          r1:=chr(p+48) + s1;
          r2:=chr(10-p+48) + s2;
          dec(b1[p]);dec(b2[10-p]);
          for i:=0 to 9 do
           begin
            y:=min(b1[i],b2[9-i]);
            for j:=1 to y do
             begin
              r1:=chr(i+48) + r1;
              r2:=chr(9-i+48) + r2;
             end;
            dec(b1[i],y);
            dec(b2[9-i],y);
           end;
          for i:=0 to 9 do
            for j:=1 to b1[i] do r1:=chr(i+48)+r1;
          for i:=0 to 9 do
            for j:=1 to b2[i] do r2:=chr(i+48)+r2;
          b1:=o;
          b2:=o;
          dec(b1[0],ii+1);dec(b2[0],ii+1);
          s1:='0'+s1;
          s2:='0'+s2;
      end;
     writeln(r1);
     writeln(r2);
end.

uses math;
var i,j,x,y,n,m,max,p,r,rez,ii: longint;
    b1,b2,o: array[0..10] of longint;
    c: char;
    s1,s2,r1,r2: ansistring;
begin
     while not eoln do
      begin
       read(c);
       inc(b1[ord(c)-48]);
      end;
     o:=b1;
     b2:=b1;
     for ii:=0 to b1[0] do
      begin
          r:=ii;
          for i:=1 to 9 do
           begin
            if (b1[i]=0) or (b2[10-i]=0) then continue;
            dec(b1[i]);dec(b2[10-i]);
            x:=r;
            for j:=1 to 9 do
             begin
              y:=min(b1[j],b2[9-j]);
              x:=x+y;
             end;
            if x>max then
             begin
              max:=x;
              p:=i;
             end;
            inc(b1[i]);inc(b2[10-i]);
           end;
          if max=0 then
           begin
            r1:='';r2:='';
            for i:=1 to 9 do
               for j:=1 to o[i] do r1:=r1+chr(i+48);
            r1:=r1+s1;
            for i:=1 to 9 do
               for j:=1 to o[i] do r2:=r2+chr(i+48);
            r2:=r2+s2;
            continue;
           end;
          if max<=rez then continue;
          rez:=max;
          r1:=chr(p+48) + s1;
          r2:=chr(10-p+48) + s2;
          dec(b1[p]);dec(b2[10-p]);
          for i:=1 to 8 do
           begin
            y:=min(b1[i],b2[9-i]);
            for j:=1 to y do
             begin
              r1:=chr(i+48) + r1;
              r2:=chr(9-i+48) + r2;
             end;
            dec(b1[i],y);
            dec(b2[9-i],y);
           end;
          for i:=0 to 9 do
            for j:=1 to b1[i] do r1:=chr(i+48)+r1;
          for i:=0 to 9 do
            for j:=1 to b2[i] do r2:=chr(i+48)+r2;
          b1:=o;
          b2:=o;
          dec(b1[0],ii+1);dec(b2[0],ii+1);
          s1:='0'+s1;
          s2:='0'+s2;
      end;
     writeln(r1);
     writeln(r2);
end.

uses math;
var i,j,x,y,n,m,max,p,r,rez,ii: longint;
    b1,b2,o: array[0..10] of longint;
    c: char;
    s1,s2,r1,r2: ansistring;
begin
     while not eoln do
      begin
       read(c);
       inc(b1[ord(c)-48]);
      end;
     o:=b1;
     b2:=b1;
     for ii:=0 to o[0] do
      begin
          dec(b1[0],ii);dec(b2[0],ii);
          if ii>0 then
           begin
            s1:='0'+s1;
            s2:='0'+s2;
           end;
          max:=ii;
          for i:=1 to 9 do
           begin
            if (b1[i]=0) or (b2[10-i]=0) then continue;
            dec(b1[i]);dec(b2[10-i]);
            x:=ii+1;
            for j:=0 to 9 do
             begin
              y:=min(b1[j],b2[9-j]);
              x:=x+y;
             end;
            if x>max then
             begin
              max:=x;
              p:=i;
             end;
            inc(b1[i]);inc(b2[10-i]);
           end;
          if max=ii then
           begin
            rez:=max;
            r1:='';r2:='';
            for i:=9 downto 0 do
               for j:=1 to b1[i] do r1:=r1+chr(i+48);
            r1:=r1+s1;
            for i:=9 downto 0 do
               for j:=1 to b2[i] do r2:=r2+chr(i+48);
            r2:=r2+s2;
            continue;
           end;
          if max<=rez then continue;
          rez:=max;
          r1:=chr(p+48) + s1;
          r2:=chr(10-p+48) + s2;
          dec(b1[p]);dec(b2[10-p]);
          for i:=0 to 9 do
           begin
            y:=min(b1[i],b2[9-i]);
            for j:=1 to y do
             begin
              r1:=chr(i+48) + r1;
              r2:=chr(9-i+48) + r2;
             end;
            dec(b1[i],y);
            dec(b2[9-i],y);
           end;
          for i:=0 to 9 do
            for j:=1 to b1[i] do r1:=chr(i+48)+r1;
          for i:=0 to 9 do
            for j:=1 to b2[i] do r2:=chr(i+48)+r2;
          b1:=o;
          b2:=o;
      end;
     writeln(r1);
     writeln(r2);
end.

uses math;
var i,j,x,y,n,m,max,p,r,rez,ii: longint;
    b1,b2,o: array[0..10] of longint;
    c: char;
    s1,s2,r1,r2: ansistring;
begin
     while not eoln do
      begin
       read(c);
       inc(b1[ord(c)-48]);
      end;
     o:=b1;
     b2:=b1;
     for ii:=0 to o[0] do
      begin
          max:=ii;
          for i:=1 to 9 do
           begin
            if (b1[i]=0) or (b2[10-i]=0) then continue;
            dec(b1[i]);dec(b2[10-i]);
            x:=ii+1;
            for j:=0 to 9 do
             begin
              y:=min(b1[j],b2[9-j]);
              x:=x+y;
             end;
            if x>max then
             begin
              max:=x;
              p:=i;
             end;
            inc(b1[i]);inc(b2[10-i]);
           end;
          if max=ii then
           begin
            if rez<>0 then continue;
            rez:=max;
            r1:='';r2:='';
            for i:=9 downto 0 do
               for j:=1 to b1[i] do r1:=r1+chr(i+48);
            r1:=r1+s1;
            for i:=9 downto 0 do
               for j:=1 to b2[i] do r2:=r2+chr(i+48);
            r2:=r2+s2;
            continue;
           end;
          if max<=rez then continue;
          rez:=max;
          r1:=chr(p+48) + s1;
          r2:=chr(10-p+48) + s2;
          dec(b1[p]);dec(b2[10-p]);
          for i:=0 to 9 do
           begin
            y:=min(b1[i],b2[9-i]);
            for j:=1 to y do
             begin
              r1:=chr(i+48) + r1;
              r2:=chr(9-i+48) + r2;
             end;
            dec(b1[i],y);
            dec(b2[9-i],y);
           end;
          for i:=0 to 9 do
            for j:=1 to b1[i] do r1:=chr(i+48)+r1;
          for i:=0 to 9 do
            for j:=1 to b2[i] do r2:=chr(i+48)+r2;
          b1:=o;
          b2:=o;
          dec(b1[0],ii+1);dec(b2[0],ii+1);
          s1:='0'+s1;
          s2:='0'+s2;
      end;
     writeln(r1);
     writeln(r2);
end.

uses math;
var i,j,x,y,n,m,max,p,r,rez,ii: longint;
    b1,b2,o: array[0..10] of longint;
    c: char;
    s1,s2,r1,r2: ansistring;
begin
     while not eoln do
      begin
       read(c);
       inc(b1[ord(c)-48]);
      end;
     o:=b1;
     b2:=b1;
     for ii:=0 to o[0] do
      begin
          dec(b1[0],ii+1);dec(b2[0],ii+1);
          if ii>0 then
           begin
            s1:='0'+s1;
            s2:='0'+s2;
           end;
          max:=ii;
          for i:=1 to 9 do
           begin
            if (b1[i]=0) or (b2[10-i]=0) then continue;
            dec(b1[i]);dec(b2[10-i]);
            x:=ii+1;
            for j:=0 to 9 do
             begin
              y:=min(b1[j],b2[9-j]);
              x:=x+y;
             end;
            if x>max then
             begin
              max:=x;
              p:=i;
             end;
            inc(b1[i]);inc(b2[10-i]);
           end;
          if max=ii then
           begin
            rez:=max;
            r1:='';r2:='';
            for i:=9 downto 0 do
               for j:=1 to b1[i] do r1:=r1+chr(i+48);
            r1:=r1+s1;
            for i:=9 downto 0 do
               for j:=1 to b2[i] do r2:=r2+chr(i+48);
            r2:=r2+s2;
            continue;
           end;
          if max<=rez then continue;
          rez:=max;
          r1:=chr(p+48) + s1;
          r2:=chr(10-p+48) + s2;
          dec(b1[p]);dec(b2[10-p]);
          for i:=0 to 9 do
           begin
            y:=min(b1[i],b2[9-i]);
            for j:=1 to y do
             begin
              r1:=chr(i+48) + r1;
              r2:=chr(9-i+48) + r2;
             end;
            dec(b1[i],y);
            dec(b2[9-i],y);
           end;
          for i:=0 to 9 do
            for j:=1 to b1[i] do r1:=chr(i+48)+r1;
          for i:=0 to 9 do
            for j:=1 to b2[i] do r2:=chr(i+48)+r2;
          if ii=4 then
           begin
            writeln(r1);
            writeln(r2);
           end;
          b1:=o;
          b2:=o;
      end;
     writeln(r1);
     writeln(r2);
end.

uses math;
var i,j,x,y,n,m,max,p: longint;
    b1,b2,o: array[0..9] of longint;
    c: char;
    s1,s2: ansistring;
begin
     while not eoln do
      begin
       read(c);
       inc(b1[ord(c)-48]);
      end;
     while b1[0]>0 do
      begin
       dec(b1[0]);
       s1:='0'+s1;
      end;
     b2:=b1;
     o:=b1;
     s2:=s1;
     for i:=1 to 9 do
      begin
       if (b1[i]=0) or (b2[10-i]=0) then continue;
       dec(b1[i]);dec(b2[10-i]);
       x:=1;
       for j:=1 to 8 do
        begin
         y:=min(b1[j],b2[9-j]);
         x:=x+y;
        end;
       if x>max then
        begin
         max:=x;
         p:=i;
        end;
       inc(b1[i]);inc(b2[10-i]);
      end;
     if max=0 then
      begin
       for i:=1 to 9 do
          for j:=1 to o[i] do write(i);
       writeln(s1);
       for i:=1 to 9 do
          for j:=1 to o[i] do write(i);
       writeln(s2);
       exit;
      end;
     s1:=chr(p+48) + s1;
     s2:=chr(10-p+48) + s2;
     dec(b1[p]);dec(b2[10-p]);
     for i:=1 to 4 do
      begin
       y:=min(b1[i],b2[9-i]);
       for j:=1 to y do
        begin
         s1:=chr(i+48) + s1;
         s2:=chr(57-i) + s2;
        end;
       dec(b1[i],y);
       dec(b2[9-i],y);
      end;
     for i:=1 to 9 do
       for j:=1 to b1[i] do write(i);
     writeln(s1);
     for i:=1 to 9 do
       for j:=1 to b2[i] do write(i);
     writeln(s2);
end.

uses math;
var i,j,x,y,n,m,max,p: longint;
    b1,b2,o: array[0..9] of longint;
    c: char;
    s1,s2: ansistring;
begin
     while not eoln do
      begin
       read(c);
       inc(b1[ord(c)-48]);
      end;
     while b1[0]>0 do
      begin
       dec(b1[0]);
       s1:='0'+s1;
      end;
     b2:=b1;
     o:=b1;
     s2:=s1;
     for i:=1 to 9 do
      begin
       if (b1[i]=0) or (b2[10-i]=0) then continue;
       dec(b1[i]);dec(b2[10-i]);
       x:=1;
       for j:=1 to 8 do
        begin
         y:=min(b1[j],b2[9-j]);
         x:=x+y;
        end;
       if x>max then
        begin
         max:=x;
         p:=i;
        end;
       inc(b1[i]);inc(b2[10-i]);
      end;
     if max=0 then
      begin
       for i:=1 to 9 do
          for j:=1 to o[i] do write(i);
       writeln(s1);
       for i:=1 to 9 do
          for j:=1 to o[i] do write(i);
       writeln(s2);
       exit;
      end;
     s1:=chr(p+48) + s1;
     s2:=chr(10-p+48) + s2;
     dec(b1[p]);dec(b2[10-p]);
     for i:=1 to 8 do
      begin
       y:=min(b1[i],b2[9-i]);
       for j:=1 to y do
        begin
         s1:=chr(i+48) + s1;
         s2:=chr(9-i+48) + s2;
        end;
       dec(b1[i],y);
       dec(b2[9-i],y);
      end;
     for i:=1 to 9 do
       for j:=1 to b1[i] do write(i);
     writeln(s1);
     for i:=1 to 9 do
       for j:=1 to b2[i] do write(i);
     writeln(s2);
end.

uses math;
var i,j,x,y,n,m,max,p,r,rez,ii: longint;
    b1,b2,o: array[0..10] of longint;
    c: char;
    s1,s2,r1,r2: ansistring;
begin
     while not eoln do
      begin
       read(c);
       inc(b1[ord(c)-48]);
      end;
     o:=b1;
     b2:=b1;
     for ii:=0 to o[0] do
      begin
          max:=ii;
          for i:=1 to 9 do
           begin
            if (b1[i]=0) or (b2[10-i]=0) then continue;
            dec(b1[i]);dec(b2[10-i]);
            x:=r;
            for j:=1 to 9 do
             begin
              y:=min(b1[j],b2[9-j]);
              x:=x+y;
             end;
            if x>max then
             begin
              max:=x;
              p:=i;
             end;
            inc(b1[i]);inc(b2[10-i]);
           end;
          if max=ii then
           begin
            if rez<>0 then continue;
            rez:=max;
            r1:='';r2:='';
            for i:=9 downto 0 do
               for j:=1 to b1[i] do r1:=r1+chr(i+48);
            r1:=r1+s1;
            for i:=9 downto 0 do
               for j:=1 to b2[i] do r2:=r2+chr(i+48);
            r2:=r2+s2;
            continue;
           end;
          if max<=rez then continue;
          rez:=max;
          r1:=chr(p+48) + s1;
          r2:=chr(10-p+48) + s2;
          dec(b1[p]);dec(b2[10-p]);
          for i:=1 to 8 do
           begin
            y:=min(b1[i],b2[9-i]);
            for j:=1 to y do
             begin
              r1:=chr(i+48) + r1;
              r2:=chr(9-i+48) + r2;
             end;
            dec(b1[i],y);
            dec(b2[9-i],y);
           end;
          for i:=0 to 9 do
            for j:=1 to b1[i] do r1:=chr(i+48)+r1;
          for i:=0 to 9 do
            for j:=1 to b2[i] do r2:=chr(i+48)+r2;
          b1:=o;
          b2:=o;
          dec(b1[0],ii+1);dec(b2[0],ii+1);
          s1:='0'+s1;
          s2:='0'+s2;
      end;
     writeln(r1);
     writeln(r2);
end.

{$H+}

var a, b: array [0..100] of Longint;
    s: String;
    i, max, best, n: Longint;

procedure w(x: Longint);
var s1, s2: String;
    i, j: Longint;
Begin
    if (x = 0) or (x = 5) then begin
        dec(a[x]);
        dec(b[x]);
        s1 := chr(x + 48);
        s2 := chr(x + 48);
    end
    else begin
        dec(a[x]);
        dec(b[10 - x]);
        s1 := chr(x + 48);
        s2 := chr(10 - x + 48);
    end;

    for i := 0 to 9 do begin
        x := a[i];
        if b[9 - i] < x then
            x := a[9 - i];
        a[i] := a[i] - x;
        b[9 - i] := b[9 - i] - x;
        for j := 1 to x do begin
            s1 := chr(i + 48) + s1;
            s2 := chr(9 - i + 48) + s2;
        end;
    end;

    for i := 0 to 9 do
        for j := 1 to a[i] do
            s1 := chr(i + 48) + s1;
    for i := 0 to 9 do
        for j := 1 to b[i] do
            s2 := chr(i + 48) + s2;
    writeln(s1);
    writeln(s2);

End;

procedure src;
var x, sum, j: Longint;
Begin
    sum := 1;
    for j := 0 to 9 do begin
        x := a[j];
        if b[9 - j] < x then
            x := b[9 - j];
        sum := sum + x;
    end;
    if sum > max then begin
        best := i;
        max := sum;
    end;
End;

Begin
    readln(s);
    n := length(s);
    for i := 1 to n do begin
        inc(a[ord(s[i]) - 48]);
        inc(b[ord(s[i]) - 48]);
    end;
    best := -1;
    for i := 1 to 9 do begin
        if (i = 5) then begin
            if (a[i] >= 1) and (b[i] >= 1) then begin
                b[i] := b[i] - 1;
                a[i] := a[i] - 1;
                src;
                a[i] := a[i] + 1;
                b[i] := b[i] + 1;
            end;
        end else begin
            if (a[i] >= 1) and (b[10 - i] >= 1) then begin
                dec(a[i]);
                dec(b[10 - i]);
                src;
                inc(a[i]);
                inc(b[10 - i]);
            end;
        end;
    end;

    if best = -1 then begin
        writeln(s);
        writeln(s);
        halt;
    end;

    w(best);
End.

{$H+}

var a, b: array [0..100] of Longint;
    s: String;
    i, max, best, n: Longint;

procedure w(x: Longint);
var s1, s2: String;
    i, j: Longint;
Begin
    if (x = 0) or (x = 5) then begin
        dec(a[x]);
        dec(b[x]);
        s1 := chr(x + 48);
        s2 := chr(x + 48);
    end
    else begin
        dec(a[x]);
        dec(b[10 - x]);
        s1 := chr(x + 48);
        s2 := chr(10 - x + 48);
    end;

    for i := 0 to 9 do begin
        x := a[i];
        if b[9 - i] < x then
            x := a[9 - i];
        a[i] := a[i] - x;
        b[9 - i] := b[9 - i] - x;
        for j := 1 to x do begin
            s1 := chr(i + 48) + s1;
            s2 := chr(9 - i + 48) + s2;
        end;
    end;

    for i := 1 to a[0] do
        s1 := s1 + chr(48);
    for i := 1 to b[0] do
        s2 := s2 + chr(48);

    for i := 1 to 9 do
        for j := 1 to a[i] do
            s1 := chr(i + 48) + s1;
    for i := 1 to 9 do
        for j := 1 to b[i] do
            s2 := chr(i + 48) + s2;
    writeln(s1);
    writeln(s2);

End;

procedure src;
var x, sum, j: Longint;
    q: Boolean;
Begin
    sum := 1;
    for j := 0 to 9 do begin
        x := a[j];
        if b[9 - j] < x then
            x := b[9 - j];
        sum := sum + x;
    end;
    if sum > max then begin
        best := i;
        max := sum;
    end;
End;

Begin
    readln(s);
    n := length(s);
    for i := 1 to n do begin
        inc(a[ord(s[i]) - 48]);
        inc(b[ord(s[i]) - 48]);
    end;
    best := -1;
    for i := 1 to 9 do begin
        if (i = 5) then begin
            if (a[i] >= 1) and (b[i] >= 1) then begin
                b[i] := b[i] - 1;
                a[i] := a[i] - 1;
                src;
                a[i] := a[i] + 1;
                b[i] := b[i] + 1;
            end;
        end else begin
            if (a[i] >= 1) and (b[10 - i] >= 1) then begin
                dec(a[i]);
                dec(b[10 - i]);
                src;
                inc(a[i]);
                inc(b[10 - i]);
            end;
        end;
    end;

    if best = -1 then begin
        writeln(s);
        writeln(s);
        halt;
    end;
    w(best);
End.

{$H+}

var a, b: array [0..100] of Longint;
    s: String;
    i, max, best, n: Longint;

procedure w(x: Longint);
var s1, s2: String;
    i, j: Longint;
Begin
    if (x = 0) or (x = 5) then begin
        dec(a[x]);
        dec(b[x]);
        s1 := chr(x + 48);
        s2 := chr(x + 48);
    end
    else begin
        dec(a[x]);
        dec(b[10 - x]);
        s1 := chr(x + 48);
        s2 := chr(10 - x + 48);
    end;

    for i := 0 to 9 do begin
        x := a[i];
        if b[9 - i] < x then
            x := b[9 - i];
        a[i] := a[i] - x;
        b[9 - i] := b[9 - i] - x;
        for j := 1 to x do begin
            s1 := chr(i + 48) + s1;
            s2 := chr(9 - i + 48) + s2;
        end;
    end;

    for i := 1 to a[0] do
        s1 := s1 + chr(48);
    for i := 1 to b[0] do
        s2 := s2 + chr(48);

    for i := 1 to 9 do
        for j := 1 to a[i] do
            s1 := chr(i + 48) + s1;
    for i := 1 to 9 do
        for j := 1 to b[i] do
            s2 := chr(i + 48) + s2;
    writeln(s1);
    writeln(s2);

End;

procedure src;
var x, sum, j: Longint;
    q: Boolean;
Begin
    sum := 1;
    for j := 0 to 9 do begin
        x := a[j];
        if b[9 - j] < x then
            x := b[9 - j];
        sum := sum + x;
    end;
    if sum > max then begin
        best := i;
        max := sum;
    end;
End;

Begin
    readln(s);
    n := length(s);
    for i := 1 to n do begin
        inc(a[ord(s[i]) - 48]);
        inc(b[ord(s[i]) - 48]);
    end;
    best := -1;
    for i := 1 to 9 do begin
        if (i = 5) then begin
            if (a[i] >= 1) and (b[i] >= 1) then begin
                b[i] := b[i] - 1;
                a[i] := a[i] - 1;
                src;
                a[i] := a[i] + 1;
                b[i] := b[i] + 1;
            end;
        end else begin
            if (a[i] >= 1) and (b[10 - i] >= 1) then begin
                dec(a[i]);
                dec(b[10 - i]);
                src;
                inc(a[i]);
                inc(b[10 - i]);
            end;
        end;
    end;

    if best = -1 then begin
        writeln(s);
        writeln(s);
        halt;
    end;
    w(best);
End.

{$H+}

var a, b: array [0..100] of Int64;
    s: String;
    i, max, best, n: Longint;

procedure w(o: Longint);
var s1, s2: String;
    i, j, x: Longint;
Begin
    if (x = 5) then begin
        dec(a[o]);
        dec(b[o]);
        s1 := chr(o + 48);
        s2 := chr(o + 48);
    end
    else begin
        dec(a[o]);
        dec(b[10 - o]);
        s1 := chr(o + 48);
        s2 := chr(10 - o + 48);
    end;

    for i := 0 to 9 do begin
        x := a[i];
        if b[9 - i] < x then
            x := b[9 - i];
        a[i] := a[i] - x;
        b[9 - i] := b[9 - i] - x;
        for j := 1 to x do begin
            s1 := chr(i + 48) + s1;
            s2 := chr(9 - i + 48) + s2;
        end;
    end;

    x := a[0];
    if b[0] < x then
        x := b[0];
    a[0] := a[0] - x;
    b[0] := b[0] - x;
    for i := 1 to x do begin
        s1 := s1 + chr(48);
        s2 := s2 + chr(48);
    end;

    for i := 0 to 9 do
        for j := 1 to a[i] do
            s1 := chr(i + 48) + s1;
    for i := 0 to 9 do
        for j := 1 to b[i] do
            s2 := chr(i + 48) + s2;
    writeln(s1);
    writeln(s2);

End;

procedure src;
var x, sum, j: Longint;
    q: Boolean;
Begin
    sum := 1;
    for j := 0 to 9 do begin
        x := a[j];
        if b[9 - j] < x then
            x := b[9 - j];
        sum := sum + x;
    end;
    if sum > max then begin
        best := i;
        max := sum;
    end;
End;

Begin
    readln(s);
    n := length(s);
    max := 0;
    for i := 1 to n do begin
        inc(a[ord(s[i]) - 48]);
        inc(b[ord(s[i]) - 48]);
    end;
    best := -1;
    for i := 1 to 9 do begin
        if (i = 5) then begin
            if (a[i] >= 1) and (b[i] >= 1) then begin
                b[i] := b[i] - 1;
                a[i] := a[i] - 1;
                src;
                a[i] := a[i] + 1;
                b[i] := b[i] + 1;
            end;
        end else begin
            if (a[i] >= 1) and (b[10 - i] >= 1) then begin
                dec(a[i]);
                dec(b[10 - i]);
                src;
                inc(a[i]);
                inc(b[10 - i]);
            end;
        end;
    end;

    if best = -1 then begin
        writeln(s);
        writeln(s);
        halt;
    end;
    w(best);
End.

{$H+}

var a, b: array [0..100] of Longint;
    s: String;
    i, max, best, n: Longint;

procedure w(x: Longint);
var s1, s2: String;
    i, j: Longint;
Begin
    if (x = 0) or (x = 5) then begin
    dec(a[x]);
        dec(b[10 - x]);
        s1 := chr(x + 48);
        s2 := chr(10 - x + 48);
    end
    else begin
        dec(a[x]);
        dec(b[10 - x]);
        s1 := chr(x + 48);
        s2 := chr(10 - x + 48);
    end;

    for i := 0 to 9 do begin
        x := a[i];
        if b[9 - i] < x then
            x := a[9 - i];
        a[i] := a[i] - x;
        b[9 - i] := b[9 - i] - x;
        for j := 1 to x do begin
            s1 := chr(i + 48) + s1;
            s2 := chr(9 - i + 48) + s2;
        end;
    end;

    for i := 0 to 9 do
        for j := 1 to a[i] do
            s1 := chr(i + 48) + s1;
    for i := 0 to 9 do
        for j := 1 to b[i] do
            s2 := chr(i + 48) + s2;
    writeln(s1);
    writeln(s2);

End;

procedure src;
var x, sum, j: Longint;
Begin
    sum := 1;
    for j := 0 to 9 do begin
        x := a[j];
        if b[9 - j] < x then
            x := b[9 - j];
        sum := sum + x;
    end;
    if sum > max then begin
        best := i;
        max := sum;
    end;
End;

Begin
    readln(s);
    n := length(s);
    for i := 1 to n do begin
        inc(a[ord(s[i]) - 48]);
        inc(b[ord(s[i]) - 48]);
    end;

    for i := 0 to 9 do begin
        if (i = 0) or (i = 5) then begin
            if (a[i] >= 1) and (b[i] >= 1) then begin
                b[i] := b[i] - 1;
                a[i] := a[i] - 1;
                src;
                a[i] := a[i] + 1;
                b[i] := b[i] + 1;
            end;
        end else begin
            if (a[i] >= 1) and (b[10 - i] >= 1) then begin
                dec(a[i]);
                dec(b[10 - i]);
                src;
                inc(a[i]);
                inc(b[10 - i]);
            end;
        end;
    end;

    if best = 0 then begin
        writeln(s);
        writeln(s);
        halt;
    end;

    w(best);
End.

{$H+}

var a, b: array [0..100] of Int64;
    s: String;
    i, max, best, n: Longint;

procedure w(o: Longint);
var s1, s2: String;
    i, j, x: Longint;
Begin
    if (o = 5) then begin
        dec(a[o]);
        dec(b[o]);
        s1 := chr(o + 48);
        s2 := chr(o + 48);
    end
    else begin
        dec(a[o]);
        dec(b[10 - o]);
        s1 := chr(o + 48);
        s2 := chr(10 - o + 48);
    end;

    for i := 0 to 9 do begin
        x := a[i];
        if b[9 - i] < x then
            x := b[9 - i];
        a[i] := a[i] - x;
        b[9 - i] := b[9 - i] - x;
        for j := 1 to x do begin
            s1 := chr(i + 48) + s1;
            s2 := chr(9 - i + 48) + s2;
        end;
    end;

    x := a[0];
    if b[0] < x then
        x := b[0];
    a[0] := a[0] - x;
    b[0] := b[0] - x;
    for i := 1 to x do begin
        s1 := s1 + chr(48);
        s2 := s2 + chr(48);
    end;

    for i := 0 to 9 do
        for j := 1 to a[i] do
            s1 := chr(i + 48) + s1;
    for i := 0 to 9 do
        for j := 1 to b[i] do
            s2 := chr(i + 48) + s2;
    writeln(s1);
    writeln(s2);
End;

procedure src;
var x, sum, j, x1, x2: Longint;
    q: Boolean;
Begin
    sum := 1;
    x1 := a[0];
    x2 := b[0];
    for j := 0 to 9 do begin
        x := a[j];
        if b[9 - j] < x then
            x := b[9 - j];
        if j = 0 then
            x1 := x1 - x;
        if j = 9 then
            x2 := x2 - x;
        sum := sum + x;
    end;
    x := x1;
    if x2 < x then
        x := x2;
    sum := sum + x;

    if sum > max then begin
        best := i;
        max := sum;
    end;
End;

Begin
    readln(s);
    n := length(s);
    max := 0;
    for i := 1 to n do begin
        inc(a[ord(s[i]) - 48]);
        inc(b[ord(s[i]) - 48]);
    end;
    best := -1;
    for i := 1 to 9 do begin
        if (i = 5) then begin
            if (a[i] >= 1) and (b[i] >= 1) then begin
                b[i] := b[i] - 1;
                a[i] := a[i] - 1;
                src;
                a[i] := a[i] + 1;
                b[i] := b[i] + 1;
            end;
        end else begin
            if (a[i] >= 1) and (b[10 - i] >= 1) then begin
                dec(a[i]);
                dec(b[10 - i]);
                src;
                inc(a[i]);
                inc(b[10 - i]);
            end;
        end;
    end;

    if best = -1 then begin
        writeln(s);
        writeln(s);
        halt;
    end;
    w(best);
End.

{$H+}

var a, b: array [0..100] of Longint;
    s: String;
    i, max, best, n: Longint;

procedure w(x: Longint);
var s1, s2: String;
    i, j: Longint;
Begin
    if (x = 0) or (x = 5) then begin
        dec(a[x]);
        dec(b[x]);
        s1 := chr(x + 48);
        s2 := chr(x + 48);
    end
    else begin
        dec(a[x]);
        dec(b[10 - x]);
        s1 := chr(x + 48);
        s2 := chr(10 - x + 48);
    end;

    for i := 0 to 9 do begin
        x := a[i];
        if b[9 - i] < x then
            x := b[9 - i];
        a[i] := a[i] - x;
        b[9 - i] := b[9 - i] - x;
        for j := 1 to x do begin
            s1 := chr(i + 48) + s1;
            s2 := chr(9 - i + 48) + s2;
        end;
    end;

    x := a[0];
    if b[0] < x then
        x := b[0];
    a[0] := a[0] - x;
    b[0] := b[0] - x;
    for i := 1 to x do begin
        s1 := s1 + chr(48);
        s2 := s2 + chr(48);
    end;

    for i := 0 to 9 do
        for j := 1 to a[i] do
            s1 := chr(i + 48) + s1;
    for i := 0 to 9 do
        for j := 1 to b[i] do
            s2 := chr(i + 48) + s2;
    writeln(s1);
    writeln(s2);

End;

procedure src;
var x, sum, j: Longint;
    q: Boolean;
Begin
    sum := 1;
    for j := 0 to 9 do begin
        x := a[j];
        if b[9 - j] < x then
            x := b[9 - j];
        sum := sum + x;
    end;
    if sum > max then begin
        best := i;
        max := sum;
    end;
End;

Begin
    readln(s);
    n := length(s);
    for i := 1 to n do begin
        inc(a[ord(s[i]) - 48]);
        inc(b[ord(s[i]) - 48]);
    end;
    best := -1;
    for i := 1 to 9 do begin
        if (i = 5) then begin
            if (a[i] >= 1) and (b[i] >= 1) then begin
                b[i] := b[i] - 1;
                a[i] := a[i] - 1;
                src;
                a[i] := a[i] + 1;
                b[i] := b[i] + 1;
            end;
        end else begin
            if (a[i] >= 1) and (b[10 - i] >= 1) then begin
                dec(a[i]);
                dec(b[10 - i]);
                src;
                inc(a[i]);
                inc(b[10 - i]);
            end;
        end;
    end;

    if best = -1 then begin
        writeln(s);
        writeln(s);
        halt;
    end;
    w(best);
End.

{$H+}

var a, b: array [0..100] of Int64;
    s: String;
    i, max, best, n: Longint;

procedure w(o: Longint);
var s1, s2: String;
    i, j, x: Longint;
Begin
    if (o = 5) then begin
        dec(a[o]);
        dec(b[o]);
        s1 := chr(o + 48);
        s2 := chr(o + 48);
    end
    else begin
        dec(a[o]);
        dec(b[10 - o]);
        s1 := chr(o + 48);
        s2 := chr(10 - o + 48);
    end;

    for i := 0 to 9 do begin
        x := a[i];
        if b[9 - i] < x then
            x := b[9 - i];
        a[i] := a[i] - x;
        b[9 - i] := b[9 - i] - x;
        for j := 1 to x do begin
            s1 := chr(i + 48) + s1;
            s2 := chr(9 - i + 48) + s2;
        end;
    end;

    x := a[0];
    if b[0] < x then
        x := b[0];
    a[0] := a[0] - x;
    b[0] := b[0] - x;
    for i := 1 to x do begin
        s1 := s1 + chr(48);
        s2 := s2 + chr(48);
    end;

    for i := 0 to 9 do
        for j := 1 to a[i] do
            s1 := chr(i + 48) + s1;
    for i := 0 to 9 do
        for j := 1 to b[i] do
            s2 := chr(i + 48) + s2;
    writeln(s1);
    writeln(s2);

End;

procedure src;
var x, sum, j: Longint;
    q: Boolean;
Begin
    sum := 1;
    for j := 0 to 9 do begin
        x := a[j];
        if b[9 - j] < x then
            x := b[9 - j];
        sum := sum + x;
    end;
    if sum > max then begin
        best := i;
        max := sum;
    end;
End;

Begin
    readln(s);
    n := length(s);
    max := 0;
    for i := 1 to n do begin
        inc(a[ord(s[i]) - 48]);
        inc(b[ord(s[i]) - 48]);
    end;
    best := -1;
    for i := 1 to 9 do begin
        if (i = 5) then begin
            if (a[i] >= 1) and (b[i] >= 1) then begin
                b[i] := b[i] - 1;
                a[i] := a[i] - 1;
                src;
                a[i] := a[i] + 1;
                b[i] := b[i] + 1;
            end;
        end else begin
            if (a[i] >= 1) and (b[10 - i] >= 1) then begin
                dec(a[i]);
                dec(b[10 - i]);
                src;
                inc(a[i]);
                inc(b[10 - i]);
            end;
        end;
    end;

    if best = -1 then begin
        writeln(s);
        writeln(s);
        halt;
    end;
    w(best);
End.

{$apptype console}
uses SysUtils;

var s : string;
    c,c2 : array[0..9] of integer;

function min(a,b : integer) : integer;
begin
   result := a;
   if b < a then result := b;
end;

function GetCnt : integer;
var i: integer;
begin
  result := 0;
  for i := 0 to 9 do begin
     inc(result, min(c[i], c2[9-i]) );
  end;
end;

var i,j,max, imax, t : integer;
    good: array[1..100001] of integer;
    gl : integer;
begin
{  reset( input, 'in.txt' );}
  {}
  readln( s );
  fillchar( c,sizeof(c), 0 );
  for i := 1 to length(s) do
     if s[i] in ['0'..'9'] then inc( c[ ord(s[i])-ord('0') ] );
  move(c,c2,sizeof(c));
{}
  max := -1; imax:= -1;
  for i := 1 to 5 do begin
     if (c[i] > 0) and (c2[10-i]>0) then begin
       dec(c[i]); dec(c2[10-i]);
       t := GetCnt();
       if t > max then begin imax := i; max :=t; end;
       inc(c[i]); inc(c2[10-i]);
     end;
  end;
{}
  if imax = -1 then begin
    for i := 1 to 9 do for j := 1 to c[i] do write(i);
    for i := 1 to c[0] do write(0);
{}
    writeln;
    for i := 1 to 9 do for j := 1 to c[i] do write(i);
    for i := 1 to c[0] do write(0);
  end else begin
     dec(c[imax]); dec(c2[10-imax]);
     gl := 0;
     for i := 0 to 9 do begin
        t := min(c[i], c2[9-i]);
        for j := 1 to t do begin
           inc(gl);
           good[gl] := i;
           dec(c[i]);
           dec(c2[9-i]);
        end;
     end;
{}
    for i := 1 to 9 do for j := 1 to c[i] do write(i);
    for i := 1 to gl do write( good[i] );
    write(imax);
    for i := 1 to c[0] do write(0);
    writeln;
{}
    for i := 1 to 9 do for j := 1 to c2[i] do write(i);
    for i := 1 to gl do write( 9-good[i] );
    write(10-imax);
    for i := 1 to c2[0] do write(0);
  end;
end.

{$APPTYPE CONSOLE}
uses math;
var
  s:string;
  a,b1,b2,cr1,cr2:array[0..100001] of integer;
  c1,d1,c2,d2:array[0..9] of integer;
  z,sm,nl,mx,f,j,l,k,error,i,n:integer;

begin
 {reset(input,'Input.txt');
 rewrite(output,'Output.txt'); }

 readln(s);

 n:=length(s);
 a[0]:=n;

 Fillchar(c1,sizeof(c1),0);
 Fillchar(c2,sizeof(c2),0);

 For i:=1 to n do
 begin
  val(s[i],a[i],error);
  inc(c1[a[i]]);
  inc(c2[a[i]]);
 end;

  mx:=-1;

 For i:=1 to c1[0] do
 begin
  inc(cr1[0]);
  cr1[cr1[0]]:=0;
  cr2[cr1[0]]:=0;
 end;

 For i:=1 to 9 do
  For j:=1 to 9 do
  begin
   cr1[0]:=c1[0];
   d1:=c1;
   d2:=c2;
   nl:=c2[0];
   d1[0]:=0;
   d2[0]:=0;
  If (i+j=10) and (c1[i]>0) and (c2[j]>0) then
  begin
   inc(cr1[0]);
   dec(d1[i]);
   dec(d2[j]);
   cr1[cr1[0]]:=i;
   cr2[cr1[0]]:=j;
   inc(nl);

   For k:=0 to 9 do
    For l:=0 to 9 do
     If (k+l=9) then
     begin
      For f:=1 to min(d1[k],d2[l]) do
      begin
       inc(cr1[0]);
       cr1[cr1[0]]:=k;
       cr2[cr1[0]]:=l;
       inc(nl);
      end;
      z:=min(d1[k],d2[l]);
      d1[k]:=d1[k]-z;
      d2[l]:=d2[l]-z;
     end;
  end;
   If nl>mx then
   begin
     mx:=nl;
     cr2[0]:=cr1[0];

     For l:=0 to 9 do
      For k:=1 to d1[l] do
      begin
       inc(cr1[0]);
       cr1[cr1[0]]:=l;
      end;

     For l:=0 to 9 do
      For k:=1 to d2[l] do
      begin
       inc(cr2[0]);
       cr2[cr2[0]]:=l;
      end;

     b1:=cr1;
     b2:=cr2;
   end;
  end;

  For i:=1 to 9 do
  For j:=1 to 9 do
  begin
    cr1[0]:=0;
    d1:=c1;
    d2:=c2;
    nl:=0;
   If (i+j=10) and (c1[i]>0) and (c2[j]>0) then
   begin
    dec(d1[i]);
    dec(d2[j]);
    inc(cr1[0]);
    cr1[cr1[0]]:=i;
    cr2[cr1[0]]:=j;
    inc(nl);

    For k:=0 to 9 do
     For l:=0 to 9 do
      If (k+l=9) then
      begin
       For f:=1 to min(d1[k],d2[l]) do
       begin
        inc(cr1[0]);
        cr1[cr1[0]]:=k;
        cr2[cr1[0]]:=l;
        inc(nl);
       end;
       z:=min(d1[k],d2[l]);
       d1[k]:=d1[k]-z;
       d2[l]:=d2[l]-z;
      end;
   end;

   If nl>mx then
    begin
      mx:=nl;
      cr2[0]:=cr1[0];

      For l:=0 to 9 do
       For k:=1 to d1[l] do
       begin
        inc(cr1[0]);
        cr1[cr1[0]]:=l;
       end;

      For l:=0 to 9 do
       For k:=1 to d2[l] do
       begin
        inc(cr2[0]);
        cr2[cr2[0]]:=l;
       end;

      b1:=cr1;
      b2:=cr2;
    end;
  end;

 For i:=b1[0] downto 1 do write(b1[i]);
 writeln;

 For i:=b2[0] downto 1 do write(b2[i]);
 writeln;

end.

{$APPTYPE CONSOLE}
uses math;
var
  s:string;
  a,b1,b2,cr1,cr2:array[0..100001] of integer;
  c1,d1,c2,d2:array[0..9] of integer;
  z,sm,nl,mx,f,j,l,k,error,i,n:integer;

begin
 {reset(input,'Input.txt');
 rewrite(output,'Output.txt'); }

 readln(s);

 n:=length(s);
 a[0]:=n;

 Fillchar(c1,sizeof(c1),0);
 Fillchar(c2,sizeof(c2),0);

 For i:=1 to n do
 begin
  val(s[i],a[i],error);
  inc(c1[a[i]]);
  inc(c2[a[i]]);
 end;

  mx:=-1;

 For i:=1 to c1[0] do
 begin
  inc(cr1[0]);
  cr1[cr1[0]]:=0;
  cr2[cr1[0]]:=0;
 end;

 For i:=1 to 9 do
  For j:=1 to 9 do
  begin
   cr1[0]:=c1[0];
   d1:=c1;
   d2:=c2;
   nl:=c2[0];
   d1[0]:=0;
   d2[0]:=0;
  If (i+j=10) and (c1[i]>0) and (c2[j]>0) then
  begin
   inc(cr1[0]);
   dec(d1[i]);
   dec(d2[j]);
   cr1[cr1[0]]:=i;
   cr2[cr1[0]]:=j;

   For k:=0 to 9 do
    For l:=0 to 9 do
     If (k+l=9) then
     begin
      For f:=1 to min(d1[k],d2[l]) do
      begin
       inc(cr1[0]);
       cr1[cr1[0]]:=k;
       cr2[cr1[0]]:=l;
       inc(nl);
      end;
      z:=min(d1[k],d2[l]);
      d1[k]:=d1[k]-z;
      d2[l]:=d2[l]-z;
     end;
  end;
   If nl>mx then
   begin
     mx:=nl;
     cr2[0]:=cr1[0];

     For l:=0 to 9 do
      For k:=1 to d1[l] do
      begin
       inc(cr1[0]);
       cr1[cr1[0]]:=l;
      end;

     For l:=0 to 9 do
      For k:=1 to d2[l] do
      begin
       inc(cr2[0]);
       cr2[cr2[0]]:=l;
      end;

     b1:=cr1;
     b2:=cr2;
   end;
  end;

  For i:=0 to 9 do
  For j:=0 to 9 do
  begin
    cr1[0]:=0;
    d1:=c1;
    d2:=c2;
    nl:=0;
   If (i+j=10) and (c1[i]>0) and (c2[j]>0) then
   begin
    dec(d1[i]);
    dec(d2[j]);
    inc(cr1[0]);
    cr1[cr1[0]]:=i;
    cr2[cr1[0]]:=j;

    For k:=0 to 9 do
     For l:=0 to 9 do
      If (k+l=9) then
      begin
       For f:=1 to min(d1[k],d2[l]) do
       begin
        inc(cr1[0]);
        cr1[cr1[0]]:=k;
        cr2[cr1[0]]:=l;
        inc(nl);
       end;
       z:=min(d1[k],d2[l]);
       d1[k]:=d1[k]-z;
       d2[l]:=d2[l]-z;
      end;
   end;

   If nl>mx then
    begin
      mx:=nl;
      cr2[0]:=cr1[0];

      For l:=0 to 9 do
       For k:=1 to d1[l] do
       begin
        inc(cr1[0]);
        cr1[cr1[0]]:=l;
       end;

      For l:=0 to 9 do
       For k:=1 to d2[l] do
       begin
        inc(cr2[0]);
        cr2[cr2[0]]:=l;
       end;

      b1:=cr1;
      b2:=cr2;
    end;
  end;

  If mx=-1 then
  begin
   b1:=a;
   b2:=a;
  end;

 For i:=b1[0] downto 1 do write(b1[i]);
 writeln;

 For i:=b2[0] downto 1 do write(b2[i]);
 writeln;

end.

{$APPTYPE CONSOLE}
uses math;
var
  s:string;
  a,b1,b2,cr1,cr2:array[0..100001] of integer;
  c1,d1,c2,d2:array[0..9] of integer;
  z,sm,nl,mx,f,j,l,k,error,i,n:integer;

begin
 {reset(input,'Input.txt');
 rewrite(output,'Output.txt'); }

 readln(s);

 n:=length(s);

 Fillchar(c1,sizeof(c1),0);
 Fillchar(c2,sizeof(c2),0);

 For i:=1 to n do
 begin
  val(s[i],a[i],error);
  inc(c1[a[i]]);
  inc(c2[a[i]]);
 end;

  mx:=-1;

 For i:=1 to c1[0] do
 begin
  inc(cr1[0]);
  cr1[cr1[0]]:=0;
  cr2[cr1[0]]:=0;
 end;

 For i:=0 to 9 do
  For j:=0 to 9 do If (i+j=10) and (c1[i]>0) and (c2[j]>0) then
  begin
   cr1[0]:=c1[0];
   d1:=c1;
   d2:=c2;
   nl:=c2[0];
   d1[0]:=0;
   d2[0]:=0;
   dec(d1[i]);
   dec(d2[j]);
   inc(cr1[0]);
   cr1[cr1[0]]:=i;
   cr2[cr1[0]]:=j;

   For k:=0 to 9 do
    For l:=0 to 9 do
     If (k+l=9) then
     begin
      For f:=1 to min(d1[k],d2[l]) do
      begin
       inc(cr1[0]);
       cr1[cr1[0]]:=k;
       cr2[cr1[0]]:=l;
       inc(nl);
      end;
      z:=min(d1[k],d2[l]);
      d1[k]:=d1[k]-z;
      d2[l]:=d2[l]-z;
     end;
   If nl>mx then
   begin
     mx:=nl;
     cr2[0]:=cr1[0];

     For l:=0 to 9 do
      For k:=1 to d1[l] do
      begin
       inc(cr1[0]);
       cr1[cr1[0]]:=l;
      end;

     For l:=0 to 9 do
      For k:=1 to d2[l] do
      begin
       inc(cr2[0]);
       cr2[cr2[0]]:=l;
      end;

     b1:=cr1;
     b2:=cr2;
   end;
  end;

  For i:=0 to 9 do
  For j:=0 to 9 do If (i+j=10) and (c1[i]>0) and (c2[j]>0) then
  begin
   cr1[0]:=0;
   d1:=c1;
   d2:=c2;
   nl:=0;
   dec(d1[i]);
   dec(d2[j]);
   inc(cr1[0]);
   cr1[cr1[0]]:=i;
   cr2[cr1[0]]:=j;

   For k:=0 to 9 do
    For l:=0 to 9 do
     If (k+l=9) then
     begin
      For f:=1 to min(d1[k],d2[l]) do
      begin
       inc(cr1[0]);
       cr1[cr1[0]]:=k;
       cr2[cr1[0]]:=l;
       inc(nl);
      end;
      z:=min(d1[k],d2[l]);
      d1[k]:=d1[k]-z;
      d2[l]:=d2[l]-z;
     end;
   If nl>mx then
   begin
     mx:=nl;
     cr2[0]:=cr1[0];

     For l:=0 to 9 do
      For k:=1 to d1[l] do
      begin
       inc(cr1[0]);
       cr1[cr1[0]]:=l;
      end;

     For l:=0 to 9 do
      For k:=1 to d2[l] do
      begin
       inc(cr2[0]);
       cr2[cr2[0]]:=l;
      end;

     b1:=cr1;
     b2:=cr2;
   end;
  end;

 For i:=b1[0] downto 1 do write(b1[i]);
 writeln;

 For i:=b2[0] downto 1 do write(b2[i]);
 writeln;

end.

{$R+,Q+,I+}
{$apptype console}
Uses SysUtils;
Const
   Source='input.txt';
   Target='output.txt';
Var
   x:Array[1..100000] of Integer;
   x1,x2:Array[1..100000] of Boolean;
   s1,s2:String;
   i,j,n,f,k,f0,f9:Integer;
   c:Char;
procedure qSort(l,r:Integer);
var i,j:Integer;
    w,q:Integer;
begin
  i := l; j := r;
  q := x[(l+r) div 2];
  repeat
    while (x[i] < q) do inc(i);
    while (q < x[j]) do dec(j);
    if (i <= j) then
    begin
      w:=x[i]; x[i]:=x[j]; x[j]:=w;
      inc(i); dec(j);
    end;
  until (i > j);
  if (l < j) then qSort(l,j);
  if (i < r) then qSort(i,r);
end;
Begin
   i:=0;
   f0:=0;
   f9:=0;
   While not SeekEof Do Begin
      Read(c);
      i:=i+1;
      x[i]:=strtoint(c);
      If x[i]=0 Then f0:=f0+1;
      If x[i]=9 Then f9:=f9+1;
   End;
   n:=i;
   qSort(1,n);
   s1:='';
   s2:='';
   i:=1;
      While True Do Begin
         If f0=f9-1 Then Break;
         If x[i]<>0 Then Break;
         s1:=inttostr(x[i])+s1;
         x1[i]:=true;
         s2:=inttostr(x[i])+s2;
         x2[i]:=true;
         i:=i+1;
         f0:=f0-1;
      End;
   k:=i;
   j:=k;
   i:=n;
   f:=0;
   While True Do Begin
      If j>i Then Break;
      If x[j]+x[i]=10 Then Begin
         x1[i]:=true;
         s1:=inttostr(x[i])+s1;
         x2[j]:=true;
         s2:=inttostr(x[j])+s2;
         f:=1;
         Break;
      End;
      If x[j]+x[i]<10 Then j:=j+1
                      Else i:=i-1;
   End;
   i:=n;
   j:=k;
   If (f=1) Then Begin
      While True Do Begin
         If i=0 Then Break;
         If j=n+1 Then Break;
         While True Do Begin
            If not(x1[i]) Then Break;
            i:=i-1;
            If i=0 Then Break;
         End;
         If i=0 Then Break;
         While True Do Begin
            If not(x2[j]) Then Break;
            j:=j+1;
            If j=n+1 Then Break;
         End;
         If j=n+1 Then Break;
         If x[i]+x[j]=9 Then Begin
            x1[i]:=true;
            x2[j]:=true;
            s1:=inttostr(x[i])+s1;
            s2:=inttostr(x[j])+s2;
            i:=i-1;
            j:=j+1;
         End
         Else If x[i]+x[j]<9 Then j:=j+1
         Else i:=i-1;
      End;
   End;
   For i:=1 To n Do Begin
      If not(x1[i]) Then s1:=inttostr(x[i])+s1;
      If not(x2[i]) Then s2:=inttostr(x[i])+s2;
   End;
   WriteLn(s1);
   Write(s2);
End.

{$R+,Q+,I+}
{$apptype console}
Uses SysUtils;
Var
   a,b:Array[1..100000] of Integer;
   i,k,d,t,p,j,f,r:Integer;
   n:String;
Begin
   Read(n);
   For i:=1 To length(n) Do Begin
      Val(n[i],a[i],f);
      b[i]:=a[i];
   End;
   k:=length(n);
   d:=0;
   r:=0;
   While d<>k Do Begin
   f:=0;
   For i:=k-d DownTo 1 Do Begin
      t:=a[i];
      For j:=k-d DownTo 1 Do Begin
         If (t+b[j]+r) mod 10=0 Then Break;
      End;
      If j=0 Then Continue;
      f:=1;
      r:=(t+b[j]+r) div 10;
      p:=b[j];
      b[j]:=b[k-d];
      b[k-d]:=p;
      a[i]:=a[k-d];
      a[k-d]:=t;
      d:=d+1;
      Break;
   End;
   If f=0 Then Break;
   End;
   For i:=1 To k Do Write(a[i]);
   WriteLn;
   For i:=1 To k Do Write(b[i]);
End.

{$R+,Q+,I+}
{$apptype console}
Uses SysUtils;
Var
   a,b:Array[1..100000] of Integer;
   i,k,d,t,p,j,f:Integer;
   n:String;
Begin
   Read(n);
   For i:=1 To length(n) Do Begin
      Val(n[i],a[i],f);
      b[i]:=a[i];
   End;
   k:=length(n);
   d:=0;
   While d<>k Do Begin
   f:=0;
   For i:=k-d DownTo 1 Do Begin
      t:=a[i];
      For j:=k-d DownTo 1 Do Begin
         If (t+b[j]+d) mod 10=0 Then Break;
      End;
      If j=0 Then Continue;
      f:=1;
      p:=b[j];
      b[j]:=b[k-d];
      b[k-d]:=p;
      a[i]:=a[k-d];
      a[k-d]:=t;
      d:=d+1;
      Break;
   End;
   If f=0 Then Break;
   End;
   For i:=1 To k Do Write(a[i]);
   WriteLn;
   For i:=1 To k Do Write(b[i]);
End.

{$R+,Q+,I+}
{$apptype console}
Uses SysUtils;
Const
   Source='input.txt';
   Target='output.txt';
Var
   x:Array[1..100000] of Integer;
   x1,x2:Array[1..100000] of Boolean;
   s1,s2:String;
   i,j,n,f,k:Integer;
   c:Char;
procedure qSort(l,r:Integer);
var i,j:Integer;
    w,q:Integer;
begin
  i := l; j := r;
  q := x[(l+r) div 2];
  repeat
    while (x[i] < q) do inc(i);
    while (q < x[j]) do dec(j);
    if (i <= j) then
    begin
      w:=x[i]; x[i]:=x[j]; x[j]:=w;
      inc(i); dec(j);
    end;
  until (i > j);
  if (l < j) then qSort(l,j);
  if (i < r) then qSort(i,r);
end;
Begin
   i:=0;
   While not SeekEof Do Begin
      Read(c);
      i:=i+1;
      x[i]:=strtoint(c);
   End;
   n:=i;
   qSort(1,n);
   s1:='';
   s2:='';
   i:=1;
   While True Do Begin
      If x[i]<>0 Then Break;
      s1:=inttostr(x[i])+s1;
      x1[i]:=true;
      s2:=inttostr(x[i])+s2;
      x2[i]:=true;
      i:=i+1;
   End;
   k:=i;
   j:=k;
   i:=n;
   f:=0;
   While True Do Begin
      If j>i Then Break;
      If x[j]+x[i]=10 Then Begin
         x1[i]:=true;
         s1:=inttostr(x[i])+s1;
         x2[j]:=true;
         s2:=inttostr(x[j])+s2;
         f:=1;
         Break;
      End;
      If x[j]+x[i]<10 Then j:=j+1
                      Else i:=i-1;
   End;
   i:=n;
   j:=k;
   If (f=1) Then Begin
      While True Do Begin
         If i=0 Then Break;
         If j=n+1 Then Break;
         If x1[i] Then Begin
            i:=i-1;
            If i=0 Then Break;
         End;
         If x2[j] Then Begin
            j:=j+1;
            If j=n+1 Then Break;
         End;
         If x[i]+x[j]=9 Then Begin
            x1[i]:=true;
            x2[j]:=true;
            s1:=inttostr(x[i])+s1;
            s2:=inttostr(x[j])+s2;
            i:=i-1;
            j:=j+1;
         End
         Else If x[i]+x[j]<9 Then j:=j+1
         Else i:=i-1;
      End;
   End;
   For i:=1 To n Do Begin
      If not(x1[i]) Then s1:=inttostr(x[i])+s1;
      If not(x2[i]) Then s2:=inttostr(x[i])+s2;
   End;
   WriteLn(s1);
   Write(s2);
End.

{$APPTYPE CONSOLE}
{$R+,S+,Q+,I+,M+,C+,H+,O-}
{R-,S-,Q-,I-,M-,C-,H-,O+}

uses
	SysUtils, Math;

var
	i, ls, n, cur, ans, p0 : longint;
	p, q : array[0..100010] of longint;
	s : string;

procedure solve(s : string);

var
	i, j, t, cur, cx, x, kk, xx : longint;
	a, b : array[0..10] of longint;
	ok : boolean;

begin
	fillchar(a, sizeof(a), 0);
	fillchar(p, sizeof(p), 0);
	fillchar(q, sizeof(q), 0);
	ls := length(s);
	for i := 1 to ls do
		inc(a[ord(s[i]) - 48]);
	b := a;
	cur := 0;
	cx := ord(s[1]) - 48;
	for i := 1 to 9 do begin
		t := 0;
		if (a[i] = 0) or (a[(10 - i) mod 10] = 0) then continue;
		for j := 0 to 9 do
			inc(t, min(a[j], a[9 - j]));
		if cur < t then begin
			cur := t;
			cx := i;
		end;
	end;
	if cur = 0 then begin
		x := 1;
		for i := 1 to a[0] do begin
			p[x] := 0;
			q[x] := 0;
			inc(x);
		end;
		a[0] := 0;
		for i := 1 to a[5] do begin
			p[x] := 5;
			q[x] := 5;
			inc(x);
		end;
		a[5] := 0;
		for i := 1 to 9 do
			for j := 1 to a[i] do begin
				p[x] := i;
				q[x] := i;
				inc(x);
			end;
		exit;
	end;
	p[1] := cx;
	dec(a[cx]);
	if a[(10 - cx) mod 10] > 0 then begin
		q[1] := (10 - cx) mod 10;
		dec(b[(10 - cx) mod 10]);
	end else begin
		q[1] := cx;
		dec(b[cx]);
	end;
	x := 2;
	ok := (p[1] = 0) and (q[1] = 0);
	for i := 0 to 9 do begin
		kk := min(a[i], b[(9 - i + byte(ok)) mod 10]);
		for j := 1 to kk do begin
			p[x] := i;
			q[x] := (9 - i + byte(ok)) mod 10;
			inc(x);
			dec(a[i]);
			dec(b[(9 - i + byte(ok)) mod 10]);
		end;
	end;
	xx := x;
	p0 := min(a[0], b[0]);
	for i := 1 to 9 do
		for j := 1 to a[i] do begin
			p[xx] := i;
			inc(xx);
		end;
	xx := x;
	for i := 1 to 9 do
		for j := 1 to b[i] do begin
			q[xx] := i;
			inc(xx);
		end;
end;

procedure swap(var a, b : char);

var
	t : char;

begin
	t := a;
	a := b;
	b := t;
end;

procedure sort(a : array of char; l, r : longint);

var
	i, j : longint;
	x : char;

begin
	i := l;
	j := r;
	x := a[l + random(r - l + 1)];
	repeat
		while a[i] < x do inc(i);
		while a[j] > x do dec(j);
		if i <= j then begin
			swap(a[i], a[j]);
			inc(i);
			dec(j);
		end;
	until i > j;
	if l < j then sort(a, l, j);
	if i < r then sort(a, i, r);
end;

procedure check(s, a : string);

var
	i, j, ps, r, l, qq : longint;

begin
	ps := 1;
	while ps > 0 do begin
		ps := n - 1;
		qq := byte((ord(s[4]) + ord(a[4]) - 96) mod 10 = 0);
		if a = '0910' then begin
		a := '0910'
		end;
		if qq > 0 then
			for i := 3 downto 1 do
				if ((ord(s[i]) + ord(a[i]) - 96) mod 10 = 0) and (s[i + 1] = '0') and (a[i + 1] = '0') then inc(qq) else
				if ((ord(s[i]) + ord(a[i]) - 96) mod 9 = 0) and (((ord(s[i]) + ord(a[i]) - 96) > 0)) and (s[i + 1] <> '0') then inc(qq) else break;
		ans := max(ans, qq);
		if ans = 3 then begin
			ans := 3;
		end;
		i := n;
		while (ps > 0) and (s[ps] >= s[i]) do begin
			dec(ps);
			dec(i);
		end;
		j := n;
		while (ps > 0) and (j > 0) and (s[ps] >= s[j]) do dec(j);
		if ps > 0 then swap(s[ps], s[j]);
		l := ps + 1;
		r := n;
		while r > l do begin
			swap(s[l], s[r]);
			inc(l);
			dec(r);
		end;
	end;
end;

procedure genPerm(s : string);

var
	i, j, ps, r, l : longint;
	ss : string;

procedure sort(l, r : longint);

var
	i, j : longint;
	x : char;

begin
	i := l;
	j := r;
	x := s[l + random(r - l + 1)];
	repeat
		while s[i] < x do inc(i);
		while s[j] > x do dec(j);
		if i <= j then begin
			swap(s[i], s[j]);
			inc(i);
			dec(j);
		end;
	until i > j;
	if l < j then sort(l, j);
	if i < r then sort(i, r);
end;

begin
	ans := 0;
	sort(1, n); // if ALL permutations are required
	ss := s;
	ps := 1;
	while ps > 0 do begin
		ps := n - 1;
		check(ss, s);
		i := n;
		while (ps > 0) and (s[ps] >= s[i]) do begin
			dec(ps);
			dec(i);
		end;
		j := n;
		while (ps > 0) and (j > 0) and (s[ps] >= s[j]) do dec(j);
		if ps > 0 then swap(s[ps], s[j]);
		l := ps + 1;
		r := n;
		while r > l do begin
			swap(s[l], s[r]);
			inc(l);
			dec(r);
		end;
	end;
end;

var
	tt : longint;

begin
{$IFNDEF ONLINE_JUDGE}
	reset(input,'input.txt');
	rewrite(output,'output.txt');
{$ENDIF}
	readln(s);
{$IFDEF AgsuL}
	N := 4;
for tt := 19 to 9999 do begin
	s := inttostr(tt);
	while length(s) < 4 do s := '0' + s;
	solve(s);
	cur := byte((p[1] + q[1]) mod 10 = 0);
	if cur > 0 then
		for i := 2 to ls do
			if ((p[i] + q[i]) mod 10 = 0) and (p[i - 1] = 0) and (q[i - 1] = 0) then inc(cur) else
			if ((p[i] + q[i]) mod 9 = 0) and (p[i - 1] <> 0) and (p[i] + q[i] > 0) then inc(cur) else break;
	genPerm(s);
	if cur <> ans then begin
		writeln('FAIL ', s, ' ', cur, ' ', ans);
		halt(0);
	end;
end;
{$ENDIF}
	solve(s);
	for i := ls - p0 downto 1 do
		write(p[i]);
	for i := 1 to p0 do
		write(0);
	writeln;
	for i := ls - p0 downto 1 do
		write(q[i]);
	for i := 1 to p0 do
		write(0);
end.

{$APPTYPE CONSOLE}
{$R+,S+,Q+,I+,M+,C+,H+,O-}
{R-,S-,Q-,I-,M-,C-,H-,O+}

uses
	SysUtils, Math;

var
	i, ls, n, cur, ans, p0 : longint;
	p, q : array[0..100010] of longint;
	s : string;

procedure solve(s : string);

var
	i, j, t, cur, cx, x, kk, xx : longint;
	a, b : array[0..10] of longint;
	ok : boolean;

begin
	fillchar(a, sizeof(a), 0);
	fillchar(p, sizeof(p), 0);
	fillchar(q, sizeof(q), 0);
	ls := length(s);
	for i := 1 to ls do
		inc(a[ord(s[i]) - 48]);
	b := a;
	cur := 0;
	cx := ord(s[1]) - 48;
	for i := 1 to 9 do begin
		t := 0;
		if (a[i] = 0) or (a[(10 - i) mod 10] = 0) then continue;
		for j := 0 to 9 do
			if i <> j then inc(t, min(a[j], a[9 - j])) else inc(t, min(a[j] - 1, a[9 - j]));
		if cur < t then begin
			cur := t;
			cx := i;
		end;
	end;
	p[1] := cx;
	dec(a[cx]);
	if a[(10 - cx) mod 10] > 0 then begin
		q[1] := (10 - cx) mod 10;
		dec(b[(10 - cx) mod 10]);
	end else begin
		q[1] := cx;
		dec(b[cx]);
	end;
	x := 2;
	ok := (p[1] = 0) and (q[1] = 0);
	for i := 0 to 9 do begin
		kk := min(a[i], b[(9 - i + byte(ok)) mod 10]);
		for j := 1 to kk do begin
			p[x] := i;
			q[x] := (9 - i + byte(ok)) mod 10;
			inc(x);
			dec(a[i]);
			dec(b[(9 - i + byte(ok)) mod 10]);
		end;
	end;
	xx := x;
	p0 := min(a[0], b[0]);
	for i := 1 to 9 do
		for j := 1 to a[i] do begin
			p[xx] := i;
			inc(xx);
		end;
	xx := x;
	for i := 1 to 9 do
		for j := 1 to b[i] do begin
			q[xx] := i;
			inc(xx);
		end;
end;

procedure swap(var a, b : char);

var
	t : char;

begin
	t := a;
	a := b;
	b := t;
end;

procedure sort(a : array of char; l, r : longint);

var
	i, j : longint;
	x : char;

begin
	i := l;
	j := r;
	x := a[l + random(r - l + 1)];
	repeat
		while a[i] < x do inc(i);
		while a[j] > x do dec(j);
		if i <= j then begin
			swap(a[i], a[j]);
			inc(i);
			dec(j);
		end;
	until i > j;
	if l < j then sort(a, l, j);
	if i < r then sort(a, i, r);
end;

procedure check(s, a : string);

var
	i, j, ps, r, l, qq : longint;

begin
	ps := 1;
	while ps > 0 do begin
		ps := n - 1;
		qq := byte((ord(s[4]) + ord(a[4]) - 96) mod 10 = 0);
		if a = '0910' then begin
		a := '0910'
		end;
		if qq > 0 then
			for i := 3 downto 1 do
				if ((ord(s[i]) + ord(a[i]) - 96) mod 10 = 0) and (s[i + 1] = '0') and (a[i + 1] = '0') then inc(qq) else
				if ((ord(s[i]) + ord(a[i]) - 96) mod 9 = 0) and (((ord(s[i]) + ord(a[i]) - 96) > 0)) and (s[i + 1] <> '0') then inc(qq) else break;
		ans := max(ans, qq);
		if ans = 3 then begin
			ans := 3;
		end;
		i := n;
		while (ps > 0) and (s[ps] >= s[i]) do begin
			dec(ps);
			dec(i);
		end;
		j := n;
		while (ps > 0) and (j > 0) and (s[ps] >= s[j]) do dec(j);
		if ps > 0 then swap(s[ps], s[j]);
		l := ps + 1;
		r := n;
		while r > l do begin
			swap(s[l], s[r]);
			inc(l);
			dec(r);
		end;
	end;
end;

procedure genPerm(s : string);

var
	i, j, ps, r, l : longint;
	ss : string;

procedure sort(l, r : longint);

var
	i, j : longint;
	x : char;

begin
	i := l;
	j := r;
	x := s[l + random(r - l + 1)];
	repeat
		while s[i] < x do inc(i);
		while s[j] > x do dec(j);
		if i <= j then begin
			swap(s[i], s[j]);
			inc(i);
			dec(j);
		end;
	until i > j;
	if l < j then sort(l, j);
	if i < r then sort(i, r);
end;

begin
	ans := 0;
	sort(1, n); // if ALL permutations are required
	ss := s;
	ps := 1;
	while ps > 0 do begin
		ps := n - 1;
		check(ss, s);
		i := n;
		while (ps > 0) and (s[ps] >= s[i]) do begin
			dec(ps);
			dec(i);
		end;
		j := n;
		while (ps > 0) and (j > 0) and (s[ps] >= s[j]) do dec(j);
		if ps > 0 then swap(s[ps], s[j]);
		l := ps + 1;
		r := n;
		while r > l do begin
			swap(s[l], s[r]);
			inc(l);
			dec(r);
		end;
	end;
end;

var
	tt : longint;

begin
{$IFNDEF ONLINE_JUDGE}
	reset(input,'input.txt');
	rewrite(output,'output.txt');
{$ENDIF}
	readln(s);
{$IFDEF AgsuL}
	N := 4;
for tt := 19 to 9999 do begin
	s := inttostr(tt);
	while length(s) < 4 do s := '0' + s;
	solve(s);
	cur := byte((p[1] + q[1]) mod 10 = 0);
	if cur > 0 then
		for i := 2 to ls do
			if ((p[i] + q[i]) mod 10 = 0) and (p[i - 1] = 0) and (q[i - 1] = 0) then inc(cur) else
			if ((p[i] + q[i]) mod 9 = 0) and (p[i - 1] <> 0) and (p[i] + q[i] > 0) then inc(cur) else break;
	genPerm(s);
	if cur <> ans then begin
		writeln('FAIL ', s, ' ', cur, ' ', ans);
		halt(0);
	end;
end;
{$ENDIF}
	solve(s);
	for i := ls - p0 downto 1 do
		write(p[i]);
	for i := 1 to p0 do
		write(0);
	writeln;
	for i := ls - p0 downto 1 do
		write(q[i]);
	for i := 1 to p0 do
		write(0);
end.