{$O-,Q+,R+}
uses SysUtils, Math;

const MaxN = 5000;

var n : integer;

function sxor (const x, y : string) : string;
var i : integer;
begin
  setlength (Result, n);
  for i := 1 to n do Result [i] := chr (ord (x[i] <> y[i]) + 48);
end;

var i, j, y : integer;
    s1, s2, x : string;
    p : array [0..MaxN * 3 + 1] of integer;

begin
  readln (s1); readln (s2); 
  assert (length (s1) = length (s2));
  assert (eof);
  n := length (s1);
  assert ((n >= 1) and (n <= MaxN));
  for i := 1 to n do assert (s1[i] in ['0', '1']);
  for i := 1 to n do assert (s2[i] in ['0', '1']);
  for i := 1 to n do begin
    x := sxor (s1, copy (s2, i, n) + copy (s2, 1, i - 1)) + '$' + s2 + s2;
    p[0] := -1; y := -1;
    for j := 1 to 3 * n + 1 do begin
      while (y >= 0) and (x[y + 1] <> x[j]) do y := p[y];
      inc (y); p[j] := y;
      if y >= n then begin
        writeln ('Yes'); halt
      end;
    end;
  end;
  writeln ('No');
end.