program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var c1,c2:array['A'..'Z'] of integer;
    n1,n2:array[1..30] of integer;
    s1,s2:string;
    c:char;
    n,k,i,j,t:integer;
    ok:boolean;
begin
   Assign(input,'ancient.in'); reset(input);
   Assign(output,'ancient.out'); rewrite(output);
   readln(s1); readln(s2);
   fillchar(c1,sizeof(c1),0); fillchar(c2,sizeof(c2),0);
   for k:=1 to length(s1) do
      inc(c1[s1[k]]);
   if length(s2)<>length(s1) then begin writeln('NO'); exit; end;
   for k:=1 to length(s2) do
      inc(c2[s2[k]]);
   i:=0; j:=0;
   for c:='A' to 'Z' do
   begin
      if c1[c]>0 then begin i:=i+1; n1[i]:=c1[c]; end;
      if c2[c]>0 then begin j:=j+1; n2[j]:=c2[c]; end;
   end;
   if i<>j then
   begin
      writeln('NO'); exit;
   end;
   repeat
      ok:=true;
      for k:=1 to i-1 do
         if n1[k]>n1[k+1] then
         begin
            ok:=false;
            t:=n1[k]; n1[k]:=n1[k+1];
            n1[k+1]:=t;
         end;
   until ok;
   repeat
      ok:=true;
      for k:=1 to j-1 do
         if n2[k]>n2[k+1] then
         begin
            ok:=false;
            t:=n2[k]; n2[k]:=n2[k+1];
            n2[k+1]:=t;
         end;
   until ok;
   ok:=true;
   for k:=1 to i do
      if n1[k]<>n2[k] then ok:=false;
   if ok then writeln('YES')
   else writeln('NO');
  { TODO -oUser -cConsole Main : Insert code here }
end.
