program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
a:array [1..27] of longint;
b:array [1..27] of longint;
s,I,t,p:longint;
f,f1:text;
st:string;
q:boolean;
begin
assign(f,'ancient.in');
assign(f1,'ancient.out');
reset(f);
rewrite(f1);
for t:=1 to 27 do a[t]:=0;
for t:=1 to 27 do b[t]:=0;

readln(f,st);
for t:=1 to length(st) do inc(a[ord(st[t])-ord('A')+1]);
readln(f,st);
for t:=1 to length(st) do inc(b[ord(st[t])-ord('A')+1]);

for t:=1 to 27 do begin
q:=true;
for p:=1 to 27 do
 if a[p]<>b[p] then q:=false;
if q then begin
write(f1,'YES');
close(f);
close(f1);
halt(0);
end;
s:=a[27];
for i:=26 downto 1 do a[i+1]:=a[i];
a[1]:=s;
end;
write(f1,'NO');
close(f);
close(f1);


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