const maxn=100;
      readfile='ancient.in';
      writefile='ancient.out';

Var n:longint;
    s,s1:string;
    a,b:array[1..maxn] of integer;
    c:array[1..maxn] of boolean;
    kol:integer;
{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-}
Procedure Rfile;
Var i1,j1:longint;
begin
     assign(input,readfile);
     reset(input);
     readln(s);
     readln(s1);
     n:=length(s);
     close(input);
end;
{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-}
Procedure Prov1;
var i1,j1:integer;
begin
     for i1:=1 to n-1 do
         if not c[i1] then
         begin
              kol:=1;
              for j1:=i1+1 to n do
                  if s[i1]=s[j1] then
                  begin
                       inc(kol);
                       c[j1]:=true;
                  end;
              inc(a[kol]);
         end;
     if not c[n] then
        inc(a[1]);
end;
{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-}
Procedure Prov2;
var i1,j1:integer;
begin
     Fillchar(c,sizeof(c),false);
     for i1:=1 to n-1 do
         if not c[i1] then
         begin
              kol:=1;
              for j1:=i1+1 to n do
                  if s1[i1]=s1[j1] then
                  begin
                       inc(kol);
                       c[j1]:=true;
                  end;
              inc(b[kol]);
         end;
     if not c[n] then
        inc(b[1]);
end;
{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-}

Procedure Main;
var i1,j1:longint;
begin
     Prov1;
     Prov2;
end;
{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-}
Procedure Wfile;
var i1,j1:integer;
begin
     assign(output,writefile);
     rewrite(output);
     for i1:=1 to maxn do
         if a[i1]<>b[i1] then
         begin
              writeln('NO');
              Exit;
         end;
     writeln('YES');
     close(output);
end;
{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-}
begin
     Rfile;
     Main;
     Wfile;
end.