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

const MaxN = 5000;
      MaxZ = MaxN shr 5 + 2;


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, k, l, p, q, val : integer;
    s1, s2 : string;
    v : array [1..MaxN, 1..MaxZ] of cardinal;
    t : array [1..MaxZ] of cardinal;
    found : boolean;

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']);
  found := true;
  for i := 1 to n do if s1[i] = '1' then begin found := false; break end;
  if found then begin writeln ('Yes'); halt end;
  l := (n + 31) shr 5;
  for i := 1 to n do begin
    p := i; q := 1; val := 0;
    for j := 1 to n do begin
      val := val shl 1 + ord (s2[p] = '1');
      inc (p); if p > n then p := 1;
      if (j and 31) = 0 then begin
        v[i][q] := val; inc (q);
      end;
    end;
    v[i][q] := val;
  end;
  q := 1; val := 0;
  for j := 1 to n do begin
    val := val shl 1 + ord (s1[j] = '1');
    if (j and 31) = 0 then begin
      t[q] := val; inc (q);
    end;
  end;
  t[q] := val;

  for i := 1 to n - 1 do 
    for j := i + 1 to n do begin
      found := true;
      for k := 1 to l do
        if (v[i][k] xor v[j][k]) <> t[k] then begin
          found := false; break
        end;
      if found then begin
        writeln ('Yes'); halt
      end;
    end;
  writeln ('No');
end.