program zadi;
 label 1;
 var c1,c2,sum,k1,k2,i: longint;
     ch1,ch2: array[1..10000] of char;
     sim: char;
procedure pechat;
 var j: integer;
     pred,s: string;
 begin
  write('{');
  pred:='{}'; s:='';
  for j:=1 to sum-1 do
   begin
    s:=pred+','+'{'+pred+'}';
    pred:=s;
    if not(j=1) then
   end;
  write(s);
  write('}')
 end;
begin
 assign(input,'input.txt');
 assign(output,'output.txt');
 reset(input); rewrite(output);
 k1:=1; k2:=1;
 repeat
 read(sim);
  case sim of
  '{': begin ch1[k1]:=sim; inc(k1); end;
  '}': begin ch1[k1]:=sim; inc(k1); end;
  ',': begin ch1[k1]:=sim; inc(k1); end;
  end;
 until eoln;
 repeat
   read(sim);
  case sim of
  '{': begin ch2[k2]:=sim; inc(k2); end;
  '}': begin ch2[k2]:=sim; inc(k2); end;
  ',': begin ch2[k2]:=sim; inc(k2); end;
  end;
 until eoln;
 dec(k1); dec(k2);
 case k1 of
 2: c1:=0;
 4: c1:=1;
 9: c1:=2;
 19: c1:=3;
 39: c1:=4;
 79: c1:=5;
 159: c1:=6;
 319: c1:=7;
 638: c1:=8;
 1277: c1:=9;
 2555: c1:=10;
 5111: c1:=11;
 10223: c1:=12;
 20447: c1:=13;
 end;
 if k1=40895 then c1:=14;
 if k1=81791 then c1:=15;
 case k2 of
 2: c2:=0;
 4: c2:=1;
 9: c2:=2;
 19: c2:=3;
 39: c2:=4;
 79: c2:=5;
 159: c2:=6;
 319: c2:=7;
 638: c2:=8;
 1277: c2:=9;
 2555: c2:=10;
 5111: c2:=11;
 10223: c2:=12;
 20447: c2:=13;
 end;
 if k2=40895 then c2:=14;
 if k2=81791 then c2:=15;
 sum:=c1+c2;
 if c1=0 then begin for i:=1 to k1 do write(ch2[i]); goto 1; end;
 if c2=0 then begin for i:=1 to k2 do write(ch1[i]); goto 1; end;
 pechat;
 1:close(input); close(output);
end.