program Project1;

{$APPTYPE CONSOLE}

function PosChange(ASourse:String):String;
 var
  ss:String;
  i,j:Integer;
begin
  ss:=ASourse;
 for i:=1 to Length(ASourse) div 5 do
 begin
  ss[(i-1)*5+1]:=ASourse[(i-1)*5+2];
  ss[(i-1)*5+2]:=ASourse[(i-1)*5+1];
  ss[(i-1)*5+3]:=ASourse[(i-1)*5+1+4];
  ss[(i-1)*5+4]:=ASourse[(i-1)*5+1+3];
  ss[(i-1)*5+5]:=ASourse[(i-1)*5+1+2];
 end;
 case Length(ASourse) mod 5 of
 2: begin
    ss[(Length(ASourse) div 5)*5+1]:=ASourse[(Length(ASourse) div 5)*5+2];
    ss[(Length(ASourse) div 5)*5+2]:=ASourse[(Length(ASourse) div 5)*5+1];
    end;

 3: begin
    ss[(Length(ASourse) div 5)*5+1]:=ASourse[(Length(ASourse) div 5)*5+2];
    ss[(Length(ASourse) div 5)*5+2]:=ASourse[(Length(ASourse) div 5)*5+1];
    ss[(Length(ASourse) div 5)*5+3]:=ASourse[(Length(ASourse) div 5)*5+3];
    end;

 4: begin
    ss[(Length(ASourse) div 5)*5+1]:=ASourse[(Length(ASourse) div 5)*5+2];
    ss[(Length(ASourse) div 5)*5+2]:=ASourse[(Length(ASourse) div 5)*5+1];
    ss[(Length(ASourse) div 5)*5+3]:=ASourse[(Length(ASourse) div 5)*5+4];
    ss[(Length(ASourse) div 5)*5+4]:=ASourse[(Length(ASourse) div 5)*5+3];
    end;
  end;

  Result :=  ss;
end;
var
  str22,str1, str2: string;
  i,j:Integer;

begin
  AssignFile(Input, 'ancient.in');
  AssignFile(Output, 'ancient.out');
  reset(Input);
  rewrite(Output);
  readln(str1);
  readln(str2);
  str22:='                            ';

  str1:=PosChange(str1);
  for i:=1 to length(str1) do
  begin
   if (str22[ord(str1[i])-62] <> ' ') and  (str22[ord(str1[i])-62] <> Str2[i]) then
   begin
   write('NO');
   halt;
   end;
   if str22[ord(str1[i])-62] = ' '  then str22[ord(str1[i])-62]:=Str2[i];
  end;
  write('YES');
  close(Input);
  close(Output);
end.
