<Problem>
http://ntucoder.net/Problem/Details/4481
Uses Crt;
Var str_a,str_b,str_c,str_d,str_e,str_res,temp:ansistring;
i,j,longueur,umi:longint;
Begin
readln(str_a);
readln(str_b);
if length(str_a)>length(str_b) then
begin
temp:=str_a;
str_a:=str_b;
str_b:=temp;
end;
longueur:=length(str_a);
umi:=length(str_b);
str_res:='';
for i:=1 to longueur do
begin
if (longueur mod i=0) and (umi mod i=0) then
begin
str_c:=copy(str_a,1,i);
for j:=1 to longueur div i do str_d:=str_d+str_c;
for j:=1 to umi div i do str_e:=str_e+str_c;
if (str_d=str_a) and (str_e=str_b) then str_res:=str_c;
str_c:=''; str_d:=''; str_e:='';
end;
end;
if str_res='' then writeln('NO') else
writeln(str_res);
readln;
End.