const
  maxl = 1000000;

var
  s, t : string;
  n, m, k, i : integer;

function gcd(a, b : integer) : integer;
var
  t : integer;
begin
  while (a <> 0) do begin
    t := b mod a;
    b := a;
    a := t;
  end;
  gcd := b;
end;

begin
  reset(input, 'basestring.in');
  rewrite(output, 'basestring.out');
  readln(s);
  readln(t);
  n := length(s);
  m := length(t);
  assert((1 <= n) and (n <= maxl));
  assert((1 <= m) and (m <= maxl));
  for i := 1 to n do begin
    assert((s[i] >= 'a') and (s[i] <= 'z'));
  end;
  for i := 1 to m do begin
    assert((t[i] >= 'a') and (t[i] <= 'z'));
  end;
  k := gcd(n, m);
  for i := 1 to n do begin
    if (s[i] <> t[(i - 1) mod k + 1]) then begin
      writeln('NO');
      halt;
    end;
  end;
  for i := 1 to m do begin
    if (t[i] <> s[(i - 1) mod k + 1]) then begin
      writeln('NO');
      halt;
    end;
  end;
  for i := 1 to k do begin
    write(s[i]);
  end;
  writeln;
end.