label 1,2;
var ii,dloch,newdl,i1,j1,k,k1,m,i,j,n:longint; q,pos,koef,ot,t,t1,t2,tt,p3,p4,p1,p2,p,rr,xx,yy,hh:int64;
flag1,flag2,flag:boolean;
b,newoch,och,r,c,z,a,x,y:array[-1000000..2000000] of int64;
marked:array[-1000..10000000] of boolean;
aa,bb,cc:extended;
ch:char;
ss1,ss2:string;
pee,ppe,pe:array[-10..2000] of char;
gr,rrr: array[-100..300,-100..300] of int64;
function max(a,b:int64):int64; begin max:=a; if b>a then max:=b;  end;
function min(a,b:int64):int64; begin min:=a; if b<a then min:=b;  end;

function arcsin(x:extended):extended;
 begin
    if x>=1 then arcsin:=pi/2 else arcsin:=arctan(x/sqrt(1-x*x));

 end;
  function phi(x,y:real):real; var t0,t1,p,s0,s1:real;
 begin
     if (x>0)and(y>=0) then p:=arctan(y/x);
     if x<0 then p:=pi+arctan(y/x);
     if(x>0)and(y<0) then p:=2*pi+arctan(y/x);
     if x=0 then if (y>=0) then p:=pi/2 else p:=3*pi/2;
     phi:=p;
 end;

 function good(i,j:longint):boolean;
  begin  if (i>=1)and(i<=n)and(j>=1)and(j<=m) then good:=true else good:=false; end;

 function right(ii:longint):extended; var al,t,p:extended; i:longint;
  begin  al:=phi(x[ii],y[ii]); t:=x[ii]*x[ii]+y[ii]*y[ii]; t:=sqrt(t);  right:=al+arcsin(t/rr);  end;

function nod(a,b:int64):int64; var p,t:int64;
begin if (a>0)and(b>0) then
   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
    p:=a;
   end else if a=0 then p:=b else p:=a;
nod:=p;
end;

begin

 {  assign(input,'input.txt');reset(input);
   assign(output,'output.txt');rewrite(output);
  }

  readln(pe[1],pe[2]);
  readln(pe[4],pe[3]);
  readln(ppe[1],ppe[2]);
  readln(ppe[4],ppe[3]);

  ss1:=''; for i:=1 to 4 do if pe[i]<>'X' then ss1:=ss1+pe[i];
  ss2:=''; for i:=1 to 4 do if ppe[i]<>'X' then ss2:=ss2+ppe[i];

  ss2:=ss2+ss2;
  {writeln(ss1);
  writeln(ss2);
 } for i:=0 to 3 do
    begin
      flag:=true;
      for j:=1 to 3 do if ss1[j]<>ss2[i+j] then flag:=false;

      if flag then begin write('YES'); goto 1;  end;
    end;
write('NO');

1:
end.

var st1,st2,st3,st4,st12,st34,st5:string;
p:longint;
begin
  readln(st1);
  readln(st2);
  readln(st3);
  readln(st4);
  st12:=st1[1]+st2[1]+st2[2]+st1[2];
  st34:=st3[1]+st4[1]+st4[2]+st3[2];
  p:=pos('X',st12);
  delete(st12,p,1);
  p:=pos('X',st34);
  delete(st34,p,1);
  st5:=st12+st12;
  p:=pos(st34,st5);
  if p<>0 then writeln('YES')
          else writeln('NO');
end.

var i, j, k, l, n,m :longint;
ch, ch1:char;
s, s1:string;
begin
read(ch);
if ch<>'X' then s:=s+ch;
readln(ch);
if ch<>'X' then s:=s+ch;
readln(ch, ch1);
if ch1<>'X' then s:=s+ch1;
if ch<>'X' then s:=s+ch;
read(ch);
if ch<>'X' then s1:=s1+ch;
readln(ch);
if ch<>'X' then s1:=s1+ch;
readln(ch, ch1);
if ch1<>'X' then s1:=s1+ch1;
if ch<>'X' then s1:=s1+ch;
while s[1]<>s1[1]do begin
                     s1:=s1+s1[1];
                     delete(s1,1,1);
                    end;
if s=s1 then write('YES')
        else write('NO');
End.

program p1;
var s1,s2,s3,s4,a,b:string;
  begin
  readln(s1);
  readln(s2);
  readln(s3);
  readln(s4);
  if s1[1]<>'X' then a:=a+s1[1];
  if s1[2]<>'X' then a:=a+s1[2];
  if s2[2]<>'X' then a:=a+s2[2];
  if s2[1]<>'X' then a:=a+s2[1];
  if s3[1]<>'X' then b:=b+s3[1];
  if s3[2]<>'X' then b:=b+s3[2];
  if s4[2]<>'X' then b:=b+s4[2];
  if s4[1]<>'X' then b:=b+s4[1];
  b:=b+b;
  if pos(a,b)<>0 then writeln('YES') else writeln('NO');
  end.

var i,j,k,c:integer;
a,b:array[1..2] of string;
r:boolean;

procedure swap(var q,w:char);
var v:char;
begin
v:=q;
q:=w;
w:=v;
end;

begin
readln(a[1]);
readln(a[2]);
readln(b[1]);
readln(b[2]);
if a[1][1]='X' then c:=1;
if a[1][2]='X' then c:=2;
if a[2][2]='X' then c:=3;
if a[2][1]='X' then c:=4;
for i:=c to 16 do begin
r:=true;
for k:=1 to 2 do
for j:=1 to 2 do
if a[k][j]<>b[k][j] then r:=false;
if r then begin
writeln('YES');
exit;
end;
case i mod 4 of
1: swap(a[1][1],a[1][2]);
2: swap(a[1][2],a[2][2]);
3: swap(a[2][2],a[2][1]);
0: swap(a[2][1],a[1][1]);
end;
end;
writeln('NO');
end.

var n,i,j:longint;
    ans:int64;
    ans1:real;
    s,s1,s2,s3,s4:string;
    a:array[1..200000] of longint;
begin
for i:=1 to 2 do
begin
readln(s);
if i mod 2=0 then s1:=s1+s[2]+s[1] else s1:=s1+s[1]+s[2];
end;
delete(s1,pos('X',s1),1);
for i:=1 to 2 do
begin
readln(s);
if i mod 2=0 then s2:=s2+s[2]+s[1] else s2:=s2+s[1]+s[2];
end;
delete(s2,pos('X',s2),1);
s3:=s2[2]+s2[3]+s2[1];
s4:=s2[3]+s2[1]+s2[2];
if (s1=s2) or (s1=s3) or (s1=s4) then write('YES') else write('NO');
end.

var a,b,i,j,m,n,x,y:longint;
        q,w:array[0..101]of longint;
            c,c1,c2,c3:char;
            s,s2,s3,s4:string;
{procedure qs(l,r:longint);
begin
 i:=l;
 j:=r;
 x:=q[(l+r)div 2];
 repeat
  while q[i]<x do inc(i);
  while q[j]>x do dec(j);
  if i<=j then
  begin
   y:=q[i];
   q[i]:=q[j];
   q[j]:=y;
   y:=w[i];
   w[i]:=w[j];
   w[j]:=y;
   inc(i);
   dec(j);
  end;
 until i>j;
 if i<r then qs(i,r);
 if l<j then qs(l,j);
end; }
begin
 //assign(input,'input.txt');reset(input);
 //assign(output,'output.txt');rewrite(output);
 readln(c,c1);
 readln(c2,c3);
 s:=c+c1+c3+c2;
 readln(c,c1);
 readln(c2,c3);
 s2:=c+c1+c3+c2;
 for i:=1 to 4 do
  if s[i]<>'X' then
   s3:=s3+s[i];
 i:=1;
 while s2[i]<>s3[1] do
  inc(i);
 s4:=s2[i];
 while length(s4)<>length(s3)do
 begin
  if i=length(s2) then
   i:=1 else
   inc(i);
  if s2[i]<>'X' then
   s4:=s4+s2[i];
 end;
 if s3=s4 then
  write('YES')else
  write('NO');
// write(s3 ,' ',s4);
end.

uses strutils;
var ss3,ss4,ss1,ss2,s1,s2,s3,s4:string;
    i,j,n,m:longint;    np:char;

begin
readln(s1);readln(s2);readln(s3);readln(s4);
ss1:=s1+reversestring(s2);
ss2:=s1[1]+s2[1]+s2[2]+s1[2];

ss3:=s3+reversestring(s4);
ss4:=s3[1]+s4[1]+s4[2]+s3[2];

for i:=1 to 4 do
begin
if ss1[i]='X'then delete(ss1,i,1);
if ss2[i]='X'then delete(ss2,i,1);
if ss3[i]='X'then delete(ss3,i,1);
if ss4[i]='X'then delete(ss4,i,1);
end;

if ss1=ss3 then begin writeln('YES');halt;end;
np:=ss1[1];ss1[1]:=ss1[2];ss1[2]:=ss1[3];ss1[3]:=np;
if ss1=ss3 then begin writeln('YES');halt;end;
np:=ss1[1];ss1[1]:=ss1[2];ss1[2]:=ss1[3];ss1[3]:=np;
if ss1=ss3 then begin writeln('YES');halt;end;

if ss2=ss4 then begin writeln('YES');halt;end;
np:=ss2[1];ss2[1]:=ss2[2];ss2[2]:=ss2[3];ss2[3]:=np;
if ss2=ss4 then begin writeln('YES');halt;end;
np:=ss2[1];ss2[1]:=ss2[2];ss2[2]:=ss2[3];ss2[3]:=np;
if ss2=ss4 then begin writeln('YES');halt;end;

writeln('NO');

end.

var    st1,st2,st3,st4:string;
       x:char;
       b,a:array[1..10000] of char;
       s,j, k,i:longint;
begin
readln(st1);
if st1[1]<>'X' then
    begin
    inc(k);
    a[k]:=st1[1];
    end;
if st1[2]<>'X' then
    begin
    inc(k);
    a[k]:=st1[2];
    end;

readln(st2);
    if st2[2]<>'X' then
    begin
    inc(k);
    a[k]:=st2[2];
    end;
if st2[1]<>'X' then
    begin
    inc(k);
    a[k]:=st2[1];
    end;
k:=0;

readln(st3);
if st3[1]<>'X' then
    begin
    inc(k);
    b[k]:=st3[1];
    end;
if st3[2]<>'X' then
    begin
    inc(k);
    b[k]:=st3[2];
    end;
readln(st4);
if st4[2]<>'X' then
    begin
    inc(k);
    b[k]:=st4[2];
    end;
if st4[1]<>'X' then
    begin
    inc(k);
    b[k]:=st4[1];
    end;

for i:=1 to 3 do a[i+3]:=a[i];

for i:=1 to 3 do b[i+3]:=b[i];
for i:=1 to 6 do
if a[1]=b[i] then break;
j:=1;
while (a[j]=b[i]) and (s<3) do
     begin

     inc(s);
     inc(j);
     inc(i);
     end;
if s=3 then write ('YES') else write('NO');
end.

Program Main;

   var temp, One , Two : String;
        i : LongInt;

begin
  readLn ( temp ) ;

  One := temp;

  readLn ( temp ) ;

  One := One + temp[2] + temp[1];

  readLn ( temp ) ;

  Two := temp;

  readLn ( temp ) ;

  Two := Two + temp[2] + temp[1];

  for i := 1 to 4 do
  begin
    if ( One[i] = 'X' ) then
      Delete ( One , i , 1 ) ;
    if ( Two[i] = 'X' ) then
      Delete ( Two , i , 1 ) ;
  end;

   while ( One[1] <> 'A' ) do
   begin
     One := One [ 2 ] + One[3] + One[1];
   end;

   while ( Two[1] <> 'A' ) do
   begin
     Two := Two[2] + Two [ 3 ] + Two [ 1 ] ;
   end;

   if ( One = Two ) then
     writeLn ( 'YES' )
   else
     writeLn ( 'NO' ) ;

end.

procedure replace(var a,b:char);
var
c:char;
begin
c:=a;
a:=b;
b:=c;
end;
procedure make(var s1:string;s:string;d:longint);
var
i,j:longint;
s2:string;
begin
for i:=1 to 4 do
if s[i]='X'
then j:=i;
if s1=s
then begin
writeln('YES');
halt;
end;
s2:=s;
if d=10
then exit;
if j=1
then begin
replace(s[2],s[1]);
make(s1,s,d+1);
s:=s2;
replace(s[3],s[1]);
make(s1,s,d+1);
end;
if j=2
then begin
replace(s[2],s[1]);
make(s1,s,d+1);
s:=s2;
replace(s[4],s[2]);
make(s1,s,d+1);
end;
if j=3
then begin
replace(s[3],s[1]);
make(s1,s,d+1);
s:=s2;
replace(s[4],s[3]);
make(s1,s,d+1);
end;
if j=4
then begin
replace(s[2],s[4]);
make(s1,s,d+1);
s:=s2;
replace(s[3],s[4]);
make(s1,s,d+1);
end;
end;var
s1,s2,s3,s4,s:string;
begin
readln(s1);
readln(s2);
readln(s3);
readln(s4);
s:=s1+s2;
make(s,s3+s4,1);
writeln('NO');
end.

var
ch, ch1: string;
a1, a2, a3, a4, a5, a6, a7, a8: char;
s, s1, s2, s3, s4: string;
begin
readln(s1);
readln(s2);
readln(s3);
readln(s4);
a1:= s1[1];
a2:= s1[2];
a3:= s2[2];
a4:= s2[1];
a5:= s3[1];
a6:= s3[2];
a7:= s4[2];
a8:= s4[1];
if a1 = 'X' then ch:= ch + a2 + a3 + a4;
if a2 = 'X' then ch:= ch + a3 + a4 + a1;
if a3 = 'X' then ch:= ch + a4 + a1 + a2;
if a4 = 'X' then ch:= ch + a1 + a2 + a3;
if a5 = 'X' then ch1:= ch1 + a6 + a7 + a8;
if a6 = 'X' then ch1:= ch1 + a7 + a8 + a5;
if a7 = 'X' then ch1:= ch1 + a8 + a5 + a6;
if a8 = 'X' then ch1:= ch1 + a5 + a6 + a7;
if ((ch = 'CAB') or (ch = 'BCA') or (ch = 'ABC')) and ((ch1 = 'CAB') or (ch1 = 'BCA') or (ch1 = 'ABC'))
then
begin
writeln('YES');
exit;
end;
if ((ch = 'CBA') or (ch = 'BAC') or (ch = 'ACB')) and ((ch1 = 'CBA') or (ch1 = 'BAC') or (ch1 = 'ACB'))
then
begin
writeln('YES');
exit;
end;
writeln('NO');
end.

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  mas1:array[1..4] of string;
  mas2:array[1..4] of string;
  s1,s2:string;
   a,b:Integer;
   f:Boolean;
procedure rotatemas1();
var i:integer;
begin
 for i:=1 to 3 do
  begin
    if mas1[i]='X' then
      begin
        mas1[i]:=mas1[i+1];
        mas1[i+1]:='X';
        Exit;
      end;
  end;

 if mas1[4]='X' then
  begin
        mas1[4]:=mas1[1];
        mas1[1]:='X';
  end;

end;

begin

  Readln(s1);
  mas1[2]:=s1[1]; mas1[3]:=s1[2];
  Readln(s1);
  mas1[1]:=s1[1]; mas1[4]:=s1[2];

  Readln(s1);
  mas2[2]:=s1[1]; mas2[3]:=s1[2];
  Readln(s1);
  mas2[1]:=s1[1]; mas2[4]:=s1[2];

  f:=false;
  for a:=1 to  17 do
   begin
        if (mas1[1]=mas2[1]) and
           (mas1[2]=mas2[2]) and
           (mas1[3]=mas2[3]) and
           (mas1[4]=mas2[4])
         then
            f:=true;
     rotatemas1;

   end;

   if f=True then
   Writeln('YES')
    else
    Writeln('NO');    Readln(a);

end.

{$A8,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O-,P+,Q-,R+,S+,T-,U-,V+,W-,X+,Y+,Z1}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}
{$IMAGEBASE $00400000}
{$APPTYPE CONSOLE}

const filename='a';
      oo=maxlongint div 2;
      eps=1e-6;
      eee=1e-21;

var qq,cc,a,aa:array[0..1000000]of longint;
    qc,he:array[0..2014,0..2014]of longint;
    s,ss,sss,s0,s1,s2,s3:string;
    x,y,z,xx,yy,zz,x0,y0,z0,x1,x2,x3,y1,y2,y3,z1,z2,z3:extended;
    nt,ii,jj,n,m,q,c,q0,c0,q1,c1,q2,c2,q3,c3:longint;
    nn,mm,kk,u,v,res,cur,max,min:longint;
    test,ll,t,tt:longint;
    b,bb,bbb,b0,b1,b2,b3:boolean;

function mx(q,c:longint):longint;
  begin
  if q>c then mx:=q else mx:=c;
  end;

function mn(q,c:longint):longint;
  begin
  if q<c then mn:=q else mn:=c;
  end;

procedure init;
  begin
  assign(input,filename+'.in');
  assign(output,filename+'.out');
  reset(input);
  rewrite(output);
  end;

procedure fin;
  begin
  close(input);
  close(output);
  end;

procedure clear;
var i,j,k:longint;
  begin
  fillchar(qc,sizeof(qc),0);
  end;

procedure load;
var i,j,k:longint;
  begin
  end;

procedure save;
var i,j,k:longint;
  begin
  end;

procedure run;
var i,j,k:longint;
  begin
  //init;
  s1:='';
  s2:='';
  readln(s);
  for i:=1 to 2 do if s[i]<>'X' then s1:=s1+s[i];
  readln(s);
  for i:=2 downto 1 do if s[i]<>'X' then s1:=s1+s[i];
  readln(s);
  for i:=1 to 2 do if s[i]<>'X' then s2:=s2+s[i];
  readln(s);
  for i:=2 downto 1 do if s[i]<>'X' then s2:=s2+s[i];
  q:=0;
  c:=0;
  if (((s1[1]='A')and(s1[2]='B')) or ((s1[2]='A')and(s1[3]='B')) or ((s1[3]='A')and(s1[1]='B')))
  then q:=1 else q:=2;
  if (((s2[1]='A')and(s2[2]='B')) or ((s2[2]='A')and(s2[3]='B')) or ((s2[3]='A')and(s2[1]='B')))
  then c:=1 else c:=2;
  if q=c then writeln('YES') else writeln('NO');
  //fin;
  end;

begin
nt:=1;
//readln(nt);
for test:=1 to nt do
  begin
  clear;
  load;
  run;
  save;
  end;
end.

var
  s1, s2, s3, ans: string;
  i, k: integer;
  c: char;
begin
  ans := 'NO';
  readln(s1);
  readln(s3);
  s1 := s1 + s3[2] + s3[1];
  readln(s2);
  readln(s3);
  s2 := s2 + s3[2] + s3[1];
  k := pos('X', s1);
  delete(s1, k, 1);
  k := pos('X', s2);
  delete(s2, k, 1);
  for i := 1 to 3 do
  begin
    c := s1[1];
    s1[1] := s1[2];
    s1[2] := s1[3];
    s1[3] := c;
    if s1 = s2 then
    begin
      ans := 'YES';
      break;
    end;
  end;
  writeln(ans);
end.

var
     p,a:array[1..4] of char;
     k,s:string;
     c:char;
     i,j,v,n:longint;
begin
   for i:=1 to 2 do
    read(p[i]);
   readln;
   for i:=4 downto 3 do
    read(p[i]);
   readln ;
   for i:=1 to 2 do
    read(a[i]);
   readln ;
   for i:=4 downto 3 do
    read(a[i]);
   s:='';
   for i:=1 to 4 do
    if(p[i]<>'X') then s:=s+p[i];
   v:=0;
   i:=0;
   while(v=0)and(i<10) do
     begin

      k:='';
      for j:=1 to 4 do
         if(a[j]<>'X') then k:=k+a[j];

      if(s<>k) then i:=i+1;
      if(s = k) then v:=1;
    //  writeln(s,' ',k);
      c:=a[4];
      for j:=4 downto 2 do
         a[j]:=a[j-1];
      a[1]:=c;
     end;
   if(v=1) then writeln('YES')
           else writeln('NO');
end.

var
    i: Integer;
    s, p, t: string[4];

begin
    ReadLn (s);
    ReadLn (t);
    s:= s + t[2] + t[1];
    ReadLn (p);
    ReadLn (t);
    p:= p + t[2] + t[1];

    for i:= 1 to 4 do
        if s[i] = 'X' then
        begin
            Delete (s, i, 1);
            break
        end;

    for i:= 1 to 4 do
        if p[i] = 'X' then
        begin
            Delete (p, i, 1);
            break
        end;

    if s = p then
        WriteLn ('YES')
    else if s = p[2] + p[3] + p[1] then
        WriteLn ('YES')
    else if s = p[3] + p[1] + p[2] then
        WriteLn ('YES')
    else
        WriteLn ('NO')
end.

var a,b,c:array[1..2,1..2]of char;
i,j,kl:longint;
s:string;
sim:char;
begin
  readln(s);
  a[1,1]:=s[1];
  a[1,2]:=s[2];
  readln(s);
  a[2,1]:=s[1];
  a[2,2]:=s[2];
  readln(s);
  b[1,1]:=s[1];
  b[1,2]:=s[2];
  readln(s);
  b[2,1]:=s[1];
  b[2,2]:=s[2];
  c:=a;
  while true do
    begin
      for i:=1 to 2 do
        begin
          kl:=0;
          for j:=1 to 2 do
            if c[i,j]='X' then begin
                                 if (i=1)and(j=1)then begin
                                                        sim:=c[2,1];
                                                        c[2,1]:='X';
                                                        c[1,1]:=sim;
                                                        kl:=1;
                                                        break;
                                                      end
                                 else if (i=1)and(j=2)then begin
                                                             sim:=c[1,1];
                                                             c[1,1]:='X';
                                                             c[1,2]:=sim;
                                                             kl:=1;
                                                             break;
                                                           end
                                 else if (i=2)and(j=1)then begin
                                                             sim:=c[2,2];
                                                             c[2,2]:='X';
                                                             c[2,1]:=sim;
                                                             kl:=1;
                                                             break;
                                                           end
                                 else if (i=2)and(j=2)then begin
                                                             sim:=c[1,2];
                                                             c[1,2]:='X';
                                                             c[2,2]:=sim;
                                                             kl:=1;
                                                             break;
                                                           end;
                               end;
          if kl=1 then break;
        end;
      kl:=0;
      for i:=1 to 2 do
        for j:=1 to 2 do
          if a[i,j]<>c[i,j] then kl:=1;
      if kl=0 then begin
                     writeln('NO');
                     halt;
                   end;
      kl:=0;
      for i:=1 to 2 do
        for j:=1 to 2 do
          if b[i,j]<>c[i,j] then kl:=1;
      if kl=0 then begin
                     writeln('YES');
                     halt;
                   end;
    end;
end.

var    st1,st2,st3,st4:string;
       x:char;
       b,a:array[1..10000] of char;
       s,j, k,i:longint;
begin
readln(st1);
if st1[1]<>'X' then
    begin
    inc(k);
    a[k]:=st1[1];
    end;
if st1[2]<>x then
    begin
    inc(k);
    a[k]:=st1[2];
    end;

readln(st2);
    if st2[2]<>'X' then
    begin
    inc(k);
    a[k]:=st2[2];
    end;
if st2[1]<>x then
    begin
    inc(k);
    a[k]:=st2[1];
    end;
k:=0;

readln(st3);
if st3[1]<>'X' then
    begin
    inc(k);
    b[k]:=st3[1];
    end;
if st3[2]<>x then
    begin
    inc(k);
    b[k]:=st3[2];
    end;
readln(st4);
if st4[2]<>'X' then
    begin
    inc(k);
    b[k]:=st4[2];
    end;
if st4[1]<>'X' then
    begin
    inc(k);
    b[k]:=st4[1];
    end;

for i:=1 to 3 do a[i+3]:=a[i];

for i:=1 to 3 do b[i+3]:=b[i];
for i:=1 to 6 do
if a[1]=b[i] then break;
j:=1;
while (a[j]=b[i]) and (s<3) do
     begin

     inc(s);
     inc(j);
     inc(i);
     end;
if s=3 then write ('YES') else write('NO');
end.

var    st1,st2,st3,st4:string;
       x:char;
       b,a:array[1..10000] of char;
       s,j, k,i:longint;
begin
readln(st1);
if st1[1]<>'X' then
    begin
    inc(k);
    a[k]:=st1[1];
    end;
if st1[2]<>x then
    begin
    inc(k);
    a[k]:=st1[2];
    end;

readln(st2);
    if st2[2]<>'X' then
    begin
    inc(k);
    a[k]:=st2[2];
    end;
if st2[1]<>x then
    begin
    inc(k);
    a[k]:=st2[1];
    end;
k:=0;

readln(st3);
if st3[1]<>'X' then
    begin
    inc(k);
    b[k]:=st3[1];
    end;
if st3[2]<>x then
    begin
    inc(k);
    b[k]:=st3[2];
    end;
readln(st4);
if st4[2]<>'X' then
    begin
    inc(k);
    b[k]:=st4[2];
    end;
if st4[1]<>x then
    begin
    inc(k);
    b[k]:=st4[1];
    end;

for i:=1 to 3 do a[i+3]:=a[i];

for i:=1 to 3 do b[i+3]:=b[i];
for i:=1 to 6 do
if a[1]=b[i] then break;
j:=1;
while (a[j]=b[i]) and (s<3) do
     begin

     inc(s);
     inc(j);
     inc(i);
     end;
if s=3 then write ('YES') else write('NO');
end.

label 1,2;
var ii,dloch,newdl,i1,j1,k,k1,m,i,j,n:longint; q,pos,koef,ot,t,t1,t2,tt,p3,p4,p1,p2,p,rr,xx,yy,hh:int64;
flag1,flag2,flag:boolean;
b,newoch,och,r,c,z,a,x,y:array[-1000000..2000000] of int64;
marked:array[-1000..10000000] of boolean;
aa,bb,cc:extended;
ch:char;
ss1,ss2:string;
pee,ppe,pe:array[-10..2000] of char;
gr,rrr: array[-100..300,-100..300] of int64;
function max(a,b:int64):int64; begin max:=a; if b>a then max:=b;  end;
function min(a,b:int64):int64; begin min:=a; if b<a then min:=b;  end;

function arcsin(x:extended):extended;
 begin
    if x>=1 then arcsin:=pi/2 else arcsin:=arctan(x/sqrt(1-x*x));

 end;
  function phi(x,y:real):real; var t0,t1,p,s0,s1:real;
 begin
     if (x>0)and(y>=0) then p:=arctan(y/x);
     if x<0 then p:=pi+arctan(y/x);
     if(x>0)and(y<0) then p:=2*pi+arctan(y/x);
     if x=0 then if (y>=0) then p:=pi/2 else p:=3*pi/2;
     phi:=p;
 end;

 function good(i,j:longint):boolean;
  begin  if (i>=1)and(i<=n)and(j>=1)and(j<=m) then good:=true else good:=false; end;

 function right(ii:longint):extended; var al,t,p:extended; i:longint;
  begin  al:=phi(x[ii],y[ii]); t:=x[ii]*x[ii]+y[ii]*y[ii]; t:=sqrt(t);  right:=al+arcsin(t/rr);  end;

function nod(a,b:int64):int64; var p,t:int64;
begin if (a>0)and(b>0) then
   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
    p:=a;
   end else if a=0 then p:=b else p:=a;
nod:=p;
end;

begin

 {  assign(input,'input.txt');reset(input);
   assign(output,'output.txt');rewrite(output);
  }

  readln(pe[1],pe[2]);
  readln(pe[4],pe[3]);
  readln(ppe[1],ppe[2]);
  readln(ppe[4],ppe[3]);

{  for i:=1 to 4  do write(pe[i]); writeln;
   for i:=1 to 4 do write(ppe[i]); writeln;
 } for i:=1 to 4 do ppe[4+i]:=ppe[i];
   for i:=0 to 3 do
     begin
        flag:=true;
      {  writeln('i= ',i);
       } for j:=1 to 4 do if pe[j]<>ppe[i+j] then
        begin flag:=false;{ writeln('bad j= ',j); } end;

        if flag then begin  writeln('YES'); goto 1;  end;

     end;

   for i:=8 downto 1 do if ppe[i]='X' then ii:=i;
   i:=ii;

   if i>1
   then begin  ch:=ppe[i]; ppe[i]:=ppe[i-1];ppe[i-1]:=ch;  end else
   begin  ch:=ppe[4]; ppe[4]:=ppe[1];ppe[1]:=ch;  end  ;

   for i:=1 to 4 do ppe[4+i]:=ppe[i];

  { for i:=1 to 4  do write(pe[i]); writeln;
   for i:=1 to 4 do write(ppe[i]); writeln;
   }
    for i:=0 to 3 do
     begin
        flag:=true;
       { writeln('i= ',i);
       } for j:=1 to 4 do if pe[j]<>ppe[i+j] then
        begin flag:=false; {writeln('bad j= ',j); } end;

        if flag then begin  writeln('YES'); goto 1;  end;

     end;

   if i<4
   then begin  ch:=ppe[i]; ppe[i]:=ppe[i+1];ppe[i+1]:=ch;  end else
   begin  ch:=ppe[4]; ppe[4]:=ppe[1];ppe[1]:=ch;  end  ;

   for i:=1 to 4 do ppe[4+i]:=ppe[i];

  { for i:=1 to 4  do write(pe[i]); writeln;
   for i:=1 to 4 do write(ppe[i]); writeln;
   }
    for i:=0 to 3 do
     begin
        flag:=true;
     {   writeln('i= ',i);
     }   for j:=1 to 4 do if pe[j]<>ppe[i+j] then
        begin flag:=false; {writeln('bad j= ',j); } end;

        if flag then begin  writeln('YES'); goto 1;  end;

     end;

  write('NO');

1:
end.


var
  n, r, x, y: Int64;
  i: LongInt;
  move: Array[1..6] of Int64;
function min(a, b: Int64): Int64;
begin
  if a < b then
    min := a
  else
    min := b;
end;
begin
  readLn(n);
  r := trunc(sqrt(1/9 + n/3) - 1/3);
  n := n - r * (3 * r + 2);
  for i := 1 to 6 do
    move[i] := r * (r + 1) div 2;
  move[2] := move[2] - r;
  for i := 1 to 6 do
    if i <> 2 then
    begin
      move[i] := move[i] + min(n, r + 1);
      n := n - min(n, r + 1);
    end else
    begin
      move[i] := move[i] + min(n, r);
      n := n - min(n, r);
    end;
  x := move[1] - move[2] + move[5] - move[4] + 2 * (move[6] - move[3]);
  y := 2 * (move[1] + move[2] - move[4] - move[5]);
  writeLn(x, ' ', y);
end.

var
   Dx:array[1..6] of longint = (-1,-2,-1,1,2,1);
   Dy:array[1..6] of longint = (2,0,-2,-2,0,2);
   j,k,n,x,y:int64;
   i:longint;

begin
     read(n);
     k:=trunc(sqrt(n/3));
     while 3*k*(k+1)<n do Inc(k);
     x:=2*k; y:=0; j:=n-3*k*(k-1); i:=1;
     while j>k do
     begin
          Inc(x,Dx[i]*k);
          Inc(y,Dy[i]*k);
          Inc(i); Dec(j,k);
     end;
     Inc(x,Dx[i]*j); Inc(y,Dy[i]*j);
     write(x,' ',y);
end.

var
   Dx:array[1..6] of longint = (-1,-2,-1,1,2,1);
   Dy:array[1..6] of longint = (2,0,-2,-2,0,2);
   j,k,n,x,y:int64;
   i:longint;

begin
     readln(n);
     k:=trunc(sqrt(n/3));
     while 3*k*(k+1)<n do Inc(k);
     x:=2*k; y:=0; j:=n-3*k*(k-1); i:=1;
     while j>k do
     begin
          Inc(x,Dx[i]*k);
          Inc(y,Dy[i]*k);
          Inc(i); Dec(j,k);
     end;
     Inc(x,Dx[i]*j); Inc(y,Dy[i]*j);
     write(x,' ',y);
end.

uses math;
var

 d,kr,o,t,n,x,y,l,r,c:int64;

function calc(z:int64):int64;
begin
 calc:=int64(3)*z*(z+int64(1));
end;

begin
 readln(n);
 if n=0 then
 begin
  writeln('0 0');halt;
 end;
 if n=1 then
 begin
  writeln('1 2');halt;
 end;

 l:=0;
 r:=1000000000;
 while(l<r)do
 begin
  c:=(l+r+int64(1))div int64(2);
  if calc(c)<n then l:=c else r:=c-int64(1);
 end;
 o:=1;
 t:=2;
 kr:=l+o;
 n:=n - calc(kr-1);
 if n=0 then
 begin
  writeln(kr*t,' ',0);halt;
 end;
 x:=t*(kr-o)+o;
 y:=t;
 kr:=kr+o;
 n:=n-o;
 if n>0 then
 begin
  d:=min(n,kr-t);
  d:=max(d,0);
  dec(n,d);
  x:=x-d;
  y:=y+t*d;
 end;
 if n>0 then
 begin
  d:=min(n,kr-o);
  d:=max(d,0);
  dec(n,d);
  x:=x-t*d;
 end;
 if n>0 then
 begin
  d:=min(n,kr-o);
  d:=max(d,0);
  dec(n,d);
  x:=x-d;
  y:=y-t*d;
 end;
 if n>0 then
 begin
  d:=min(n,kr-o);
  d:=max(d,0);
  dec(n,d);
  x:=x+d;
  y:=y-t*d;
 end;
 if n>0 then
 begin
  d:=min(n,kr-o);
  d:=max(d,0);
  dec(n,d);
  x:=x+t*d;
 end;
 if n>0 then
 begin
  d:=min(n,kr-o);
  d:=max(d,0);
  dec(n,d);
  x:=x+d;
  y:=y+t*d;
 end;
 writeln(x,' ',y);

end.

const dx : array[0 .. 5] of longint = (1, -1, -2, -1, 1, 2);
      dy : array[0 .. 5] of longint = (2, 2, 0, -2, -2, 0);

var
  l, r, mid, cur, d, cx, cy, n : int64;
  dir : longint;

begin
  read(n);
  d := 0;
  dir := 0;
  cx := 0;
  cy := 0;
  l := 0;
  r := 1000000000;
  while l < r - 1 do begin
    mid := (l + r) shr 1;
    if (mid * (mid - 1) shr 1) * 6 + mid * 5 < n then l := mid else r := mid;
  end;
  n := n - ((l * (l - 1) shr 1) * 6 + l * 5);
  cx := l;
  cy := -2 * l;
  d := l;
  while n > 0 do begin
    cur := d;
    if (dir = 0) then begin
      inc(cur);
    end else if dir = 1 then begin
      inc(d);
    end;
    if cur >= n then begin
      cur := n;
    end;
    cx := cx + dx[dir] * cur;
    cy := cy + dy[dir] * cur;
    n := n - cur;
    dir := (dir + 1) mod 6;
  end;
  writeln(cx, ' ', cy);
end.

program E1;
var
n,l,r,k,h,m:int64;
begin
read(n);
if n = 0 then write(0,' ',0) else
 begin
  n:=n+1;
  l:=0;
  r:=1000000000;
  while r - l <> 1 do
   begin
    m:=(l+r) div 2;
    if n <= 3*m*(m+1)+1 then r:=m
     else l:=m
   end;
   n:=n-1-3*r*(r-1);
   r:=r+1;
     h:=n div (r-1);
     k:=n mod (r-1);
     if k=0 then
      if h=1 then write(r-1,' ',(r-1)*2) else
      if h=2 then write(-r+1,' ',(r-1)*2) else
      if h=3 then write((1-r)*2,' ',0) else
      if h=4 then write(-r+1,' ',(1-r)*2) else
      if h=5 then write(r-1,' ',(1-r)*2) else
                  write((r-1)*2,' ',0) else
      if h=1 then write(r-1-2*k,' ',(r-1)*2) else
      if h=2 then write(-r+1-k,' ',(r-1)*2-2*k) else
      if h=3 then write((1-r)*2+k,' ',-k*2) else
      if h=4 then write(-r+1+k*2,' ',(1-r)*2) else
      if h=5 then write(r-1+k,' ',(1-r)*2+2*k) else
                  write((r-1)*2-k,' ',k*2)
 end;
end.

    {$APPTYPE CONSOLE}
const nn=1000001; besk=200000000000000;
   nnn=2000000;  eps=1e-11; modul=1000000007;
 label 1,2,3,4;

var step,kt,ppp,god,day,mon,mask,i0,j0,k,i,j,start,finish,kol,m:longint;
t,ii,jj,l,r,p,p3,pos,ll,bb,pp,tt,ot1,ot2,s,kold,n:int64;
xx,yy,q,t1,t2,p4,cc,p1,p2,ot,dist1,avt,zap,ba,by,aa,ay,kk,centr,koef:int64;
flag2,flag1,flag:boolean;
ch1,ch2,ch:char;
prob,ccc1,v,rr,h1,h2,h,r1,r2,aaa,bbb,ccc,hh,po,pt,doltek,dolpred:extended;
d,pp1,pp2,pp3,pp4,f,x,y,fact,c,b,a,prost:array[-100000..1000000] of int64;
oldzan,oldmarked,zan: array[0..330006] of boolean;
agor,aver,ssumgor,ssumver,sgor,sver,udd,dostl,dostr: array[-100..600,-100..600] of int64;
det,ott :double;
dist,palin:array[-100..510,-100..510] of int64;
ss,ss1,ss2:string;
dd:array[-10..6000,-10..6000] of int64;
marked,dost,newdost:array[-10..700000] of boolean;
ssnew:array[-10..1000000] of char;
pole:array[-10..610,-10..600] of char;
name:array[0..2000] of string;
function min (a,b:int64):int64;begin min:=b;if a<b then min:=a;  end;
function max (a,b:int64):int64;begin max:=b;if a>b then max:=a;  end;

 function nod(x,y:int64):int64; var z:int64;
begin   repeat  z:=x mod y;x:=y;y:=z;   until  z=0 ;  nod:=x;end;

function degg(p,deg:int64):int64; var pp,q:int64;
 begin if deg=0 then degg:=1 else begin   if odd(deg) then degg:=degg(p,deg-1)*p mod modul else
 begin q:=(degg(p,deg shr 1)) mod modul; degg:=(q*q) mod modul;   end; end;   end;

function ff(i:int64):int64; begin  ff:=i*(4+3*i);  end;

begin
  {  assign (input,'input.txt');reset(input);
      assign (output,'output.txt'); rewrite(output);
   }
 { for j:=1  to 20  do
}begin
    n:=j;
    read(n);
    if n=0 then begin  write(0,' ',0); goto 1;  end;
    dec(n);
    x[1]:=-2;y[1]:=0;
    x[2]:=-1;y[2]:=-2;
    x[3]:=1;y[3]:=-2;
    x[4]:=2;y[4]:=0;
    x[5]:=1;y[5]:=2;
    x[6]:=-1;y[6]:=2;

 aa:=0; bb:=1000000000;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) div 2;
       if ff(cc)<=n then aa:=cc else bb:=cc;
    end;

  {  writeln(cc);
  }  cc:=max(cc-3,-1);
    repeat inc(cc); until ff(cc)>n;
    dec(cc);
   { writeln(cc);
   } t:=n-ff(cc);
    k:=t div (cc+1)+1;
   { writeln('t= ',t,' k= ',k);
   } xx:=cc+1; yy:=2*cc+2;
   { writeln(xx,' ',yy);
   }  for i:=1 to k-1 do begin  xx:=xx+x[i]*(cc+1); yy:=yy+y[i]*(cc+1); end;
   { writeln(xx,' ',yy);
    }
     p1:=t mod (cc+1);
    { writeln('p1= ',p1);
    } xx:=xx+p1*x[k];
     yy:=yy+p1*y[k];
    { writeln(n,' + ',cc,' <> ',ff(cc+1));
    } if n+cc+1>=ff(cc+1) then xx:=xx+2;

     writeln(xx,' ',yy);

end;

   1:          close(output);
end.

var n,k,x,y:int64;
procedure shuchu;
begin
 if n=0 then
  begin
   writeln(k*2-2,' ',0);
   exit;
  end;
 if n<=k then
  begin
   writeln(k*2-n,' ',n*2);
   exit;
  end;
 dec(n,k);
 if n<=k then
  begin
   writeln(k-n*2,' ',k*2);
   exit;
  end;
 dec(n,k);
 if n<=k then
  begin
   writeln(-k-n,' ',k*2-n*2);
   exit;
  end;
 dec(n,k);
 if n<=k then
  begin
   writeln(-k*2+n,' ',-n*2);
   exit;
  end;
 dec(n,k);
 if n<=k then
  begin
   writeln(-k+n*2,' ',-k*2);
   exit;
  end;
 dec(n,k);
 if n<=k then
  begin
   writeln(k+n,' ',-k*2+n*2);
   exit;
  end;
end;
begin
 read(n);
 if n=0 then writeln('0 0') else
 if n=1 then writeln('1 2') else
 if n=2 then writeln('-1 2') else
begin
 k:=1;
 k:=trunc(sqrt(n/3));
 while n div k div 3 div (k+1)>=1 do
  inc(k);
 dec(k);
 n:=n-k*(k+1)*3;
 inc(k);
 shuchu;
end;
end.

var n,k,x,y:longint;
begin
 read(n);
 k:=1;
 k:=trunc(sqrt(n/3));
 while n div k div 3 div (k+1)>=1 do
  inc(k);
 dec(k);
 n:=n-k*(k+1)*3;
 inc(k);
 x:=k*2-2;
 y:=0;
 if n=0 then writeln(x,' ',y);
 if n=1 then writeln(x+1,' ',y+2) else
 if n<=k then writeln(k*2-n,' ',n*2) else
 if n<=k*2 then writeln(k*3-n*2,k*2) else
 if n<=k*3 then writeln(-k-(n-k*2),k*2-2*(n-k*2)) else
 if n<=k*4 then writeln(-k*2+(n-k*3),-2*(n-k*3)) else
 if n<=k*5 then writeln(-k+2*(n-k*4),-k*2) else
 if n<=k*6 then writeln(k+(n-k*5),-k*2-2*(n-k*5));
end.

var n,k,x,y:int64;
begin
 read(n);
 k:=1;
 k:=trunc(sqrt(n/3));
 while n div k div 3 div (k+1)>=1 do
  inc(k);
 dec(k);
 n:=n-k*(k+1)*3;
 inc(k);
 x:=k*2-2;
 y:=0;
 if n=0 then writeln(x,' ',y) else
 if n=1 then writeln(x+1,' ',y+2) else
 if n<=k then writeln(k*2-n,' ',n*2) else
 if n<=k*2 then writeln(k*3-n*2,' ',k*2) else
 if n<=k*3 then writeln(-k-(n-k*2),' ',k*2-2*(n-k*2)) else
 if n<=k*4 then writeln(-k*2+(n-k*3),' ',-2*(n-k*3)) else
 if n<=k*5 then writeln(-k+2*(n-k*4),' ',-k*2) else
 if n<=k*6 then writeln(k+(n-k*5),' ',-k*2-2*(n-k*5));
end.

var
  n, r, x, y: Int64;
  i: LongInt;
  move: Array[1..6] of Int64;
function min(a, b: Int64): Int64;
begin
  if a < b then
    min := a
  else
    min := b;
end;
begin
  readLn(n);
  r := trunc(sqrt(1/9 + n/3) - 1/3);
  n := n - r * (6 * r - 1);
  for i := 1 to 6 do
    move[i] := r * (r + 1) div 2;
  move[2] := move[2] - r;
  for i := 1 to 6 do
    if i <> 2 then
    begin
      move[i] := move[i] + min(n, r + 1);
      n := n - min(n, r + 1);
    end else
    begin
      move[i] := move[i] + min(n, r);
      n := n - min(n, r);
    end;
  x := move[1] - move[2] + move[5] - move[4] + 2 * (move[6] - move[3]);
  y := 2 * (move[1] + move[2] - move[4] - move[5]);
  writeLn(x, ' ', y);
end.


program theeternalimmortality;
var a,b:int64;
procedure input;
var f:text;
begin
        readln(a,b);
end;
procedure output;
var f:text;
    x,y,i,k:longint;
begin
        if b-a=0 then writeln(1) else
        if b-a>=10 then writeln(0)
        else
        begin
                x:=a mod 10;
                y:=b mod 10;
                if y>x then
                begin
                        k:=1;
                        for i:=x+1 to y do k:=(k*i)mod 10;
                        writeln(k);
                end
                else writeln(0);
        end;
end;
begin
        input;
        output;
end.

program hrn;
 var
  a,b,p,q,x:qword;i:longint;
 begin
  read(a,b);x:=1;
  if b-a>=10 then x:=0
   else begin
    p:=b mod 10;
    q:=a mod 10;
    if p<q then x:=0
     else
      for i:=q+1 to p do begin
       x:=x*i;
       if x>=10 then x:=x mod 10;
      end
   end;
  write(x);
 end.

var a,b,i,kq:int64;
begin
        readln(a,b);
        kq:=1;
        i:=a+1;
        if b>=a+10 then writeln(0) else begin
        while i<=b do begin
                kq:=kq*i;
                kq:=kq mod 10;
                inc(i);
        end;
        writeln(kq);
        end;
end.

program qq;
var a,b,o,n,i:int64;
Begin
 read(a,b); n:=1;i:=a+1;
 while i<=b do begin
 o:=i mod 10;
 n:=(n*o) mod 10;
 if n=0 then break;
 i:=i+1;
 end;
 writeln(n);
end.

program cf1;
//uses crt;
var a,b :int64;
    x,y,i,s :integer;
    f:text;
//--------------------------
begin
//clrscr;
assign(f,'');
reset(f);
readln(f,a,b);
x:=a mod 10;
y:=b mod 10;
s:=1;
if (b-a >=10) or (y<x) then Writeln(0)
else if b=a then Writeln(1)
else  begin
      for i:=x+1 to y do begin
                       s:=s*i;
                       end;
      Writeln(s mod 10);
      end;
//readln;
end.

var
a,b:int64;
col:integer;
start:integer;
finish:integer;
i:integer;
begin
read(a,b);
i:=1;
col:=0;
if(b<6+a)and(b<>a)then begin
col:=1;
start:=(a+1)mod 10;
finish:=(b)mod 10;
if(finish<start)then inc(finish,10);
while(start<=finish)do begin
col:=(col*(start))mod 10; inc(start);
end;     end;
if(b=a)then col:=1;
writeln(col);
end.

var
        a,b,i,sum:int64;
begin
readln(a,b);
if b>=a then
        begin
        if b-a>10 then
                begin
                writeln(0);
                halt;
                end;
        sum:=1;
        inc(a);
        while a<=b do
               begin
               sum:=sum*(a mod 10);
               sum:=sum mod 10;
               inc(a);
               end;
        writeln(sum);
        end
        else writeln(0);
end.

var a,b,i,ans:qword;
begin
 readln(a,b);
 if b-a>10 then writeln(0)
           else begin
                 ans:=1;
                 i:=a+1;
                 while i<=b do begin
                                ans:=(ans*i) mod 10;
                                inc(i);
                               end;
                 writeln(ans);
               end;
readln;
end.

var a,b:int64;
procedure solve;
var j:int64;
    k,i:integer;
begin
  j:=b-a;
  if j>=10 then
    begin
      writeln('0');
      exit;
    end
  else
    begin
      k:=1;
      b:=b mod 10;
      while (b-j)<b do
        begin
          k:=k*(b-j+1);
          dec(j);
        end;
    end;
  k:=k mod 10;
  writeln(abs(k));
end;
begin
  readln(a,b);
  if b<a then
    begin
      writeln('0');
      halt;
    end
  else if b=a then
      begin
        writeln('1');
        halt;
      end;
  solve;
  readln
end.

var n,i,j:integer;
a,b:int64;
begin
read (a,b);
j:=1;
if b-a>=10 then begin write (0); exit; end
else
begin
for i:=1 to b-a do
 begin
  j:=(j*((a+i) mod 10)) mod 10;
 end;
write (j);
end;
end.

 var a,b,k,x:int64;
     i:longint;
begin
 readln(a,b);
 k:=a+1;
 k:=k mod 10;
 x:=(b-a-1) mod 1000;
 if (b-a-1)>x then
   x:=x+1000;
 for i:=1 to x do begin
   k:=k*((i+a+1) mod 10);
   k:=k mod 10;
   if k=0 then
     break;
 end;
 if b=0 then
   k:=1;
 if a=b then
   k:=1;
 writeln(k);
end.

Uses math;
Const
        fin='';
        fon='';
        maxC=1000000000;
        maxN=1000+10;
	module=1000000007;

Type
	re=record
		x,y:longint;
		end;

Var
        fi,fo:text;
	n,kq:longint;
        a,b:int64;

Procedure mo;
Begin
        Assign(fi,fin); Reset(fi);
        Assign(fo,fon); Rewrite(fo);
End;

Procedure dong;
Begin
        Close(fi);
        Close(fo);
End;

Procedure nhap;
Var
	i:longint;
Begin
        Readln(fi,a,b);
End;

Procedure xuly;
Var
        j:longint;
        i:int64;
Begin
        If b-a>4 then
        Begin
                Write(fo,0);
                Exit;
        End;
        kq:=1;
        i:=a+1;
        While i<=b do
        Begin
                kq:=(kq*(i mod 10)) mod 10;
                inc(i);
        End;
        Writeln(fo,kq mod 10);
End;

Procedure xuat;
Begin
End;

BEGIN
        Mo;
        Nhap;
        Xuly;
        Xuat;
        Dong;
END.

{$mode objfpc}
program Fenix;

var
  a, b, c, proizv: int64;

  i: integer;
begin
 readln(a, b);

  c := b - a;

  if c = 0 then
  begin
    Write(1);
  //readln();
    exit;
  end;

  proizv := 1;
  if c >= 10 then
  begin
    Write(0);
    //readln();
    exit;
  end
  else
  begin
    c := c mod 100;
    b := b mod 100;
    for i := (b - c + 1) to b do
      proizv := (proizv * i) mod 10;
  end;

  Write(proizv);
  // readln();
end.

var a,b,o,n,i:int64;
Begin
 read(a,b); n:=1;i:=a+1;
 while i<=b do begin
 o:=i mod 10;
 n:=(n*o) mod 10;
 if n=0 then break;
 i:=i+1;
 end;
 writeln(n);
end.

var ans:longint;
    a,b,i:int64;
   begin
        readln(a,b); ans:=1;
        i:=a+1;   if b-a+1>10 then writeln(0) else begin
        while i<=b do begin
            ans:=ans*(i mod 10) mod 10;
            inc(i);
        end;
         writeln(ans);
        end;
   end.

var
a,b,c,i:qword;

flag: integer;
begin
readln(a,b);
c:=b-a;
flag:=1;
if (c=0) then writeln(1)
else begin
    c:=1;
    i:=a+1;
    while ((i<=b)and(flag=1)) do begin
        c:=c*(i mod 10);
        if (c=0) then flag:=0;
        i:=i+1;
    end;
    writeln(c mod 10);
end;

end.

program a;
var a,b,j,otv: int64;
begin
  read(a);
  read(b);
  j:=a+1;
  otv:=1;
  if(a>b) then otv:=0;

  if((b-a)>10) then begin
    otv:=0;
    j:=b+1;
  end;

  while(j<=b) do begin
    otv := (otv*(j mod 10)) mod 10;
    inc(j);
  end;
  writeln(otv);
end.

const fi = '';
      fo = '';
var f : text;
    a,b,i : int64;
    res : byte;
begin
        assign(f,fi);
        reset(f);
        readln(f,a,b);
        close(f);

        inc(a);
        res:= a mod 10;
        if (b-a+1) >= 10 then res:= 0
        else if (a = b) then res:= b mod 10
        else if (a = b + 1) then res:= 1
        else    repeat
                        inc(a);
                        res:= (res * (a mod 10)) mod 10;
                until a = b;

        assign(f,fo);
        rewrite(f);
        write(f,res);
        close(f);
end.

var a,b,c1,pn :qword;
    kq,i : longint;
BEGIN
  read(a,b);
      kq:=1;
     if b mod 10=0 then kq:=0;
     if b mod 10 <> 0 then
    for i:=1 to b-a do
      begin
          pn:=a+i;
          c1:=pn mod 10;
          kq:=kq * c1;
          kq:=kq mod 10;
          if kq=0 then break;
      end;
    if a=b then kq:=1;
   write(kq);
END.

{$MACRO ON}
{$MODE OBJFPC}
{$COPERATORS ON}
{$DEFINE wait:=readln;readln;}
{$DEFINE maxN:=trunc(5e5)+1}

uses gvector,garrayutils,math;
const	fi='';
		fo='';
type
	TType = int32;   //   <------ TYPE
	vector = specialize TVector<TType>;
    compare = class
    	public
        	class function c(a,b : TType) : boolean;
    end;
    utils = specialize TOrderingArrayUtils<vector,TType,compare>;
class function compare.c(a,b : TType) : boolean;
	begin Result := a<b; end;     //   <------ ORDER

var n : int32;
	a,b : int64;
	_2,_5 : boolean;

procedure readData();
	var i : int32;
    begin
        readln(a,b);
    end;

procedure main();
    var i : int64;
		tmp,tmp2 : int64;
	begin
        readData();
		a := a+1;
        tmp := 1;
		i := a;
        while i<=b do begin
            if i mod 2 = 0 then _2 := true;
			if i mod 5 = 0 then _5 := true;
            tmp := (tmp*(i mod 10)) mod 10;
			if (_2 and _5) then begin
                write(0);
				break;
			end;
			inc(i);
		end;
		if not(_2 and _5) then write(tmp);
		wait;
    end;

begin
    assign(input,fi); reset(input);
    assign(output,fo); rewrite(output);
	main();
    close(input); close(output);
end.

var a,b,so,n:int64;
begin
readln(a,b);
if a=b then writeln(1) else
    begin
        n:=b-a;
        inc(a);
        so:=1;
        repeat
             so:=so*a;
             while so>=10 do
                so:=so mod 10;
             inc(a);
             if so=0 then
                begin
                    writeln(so);
                    halt;
                end;
        until a>b;
        writeln(so);
    end;
end.

{$mode objfpc}
{$coperators on}
{$inline on}
const
        fi='input.txt';
        fo='output.txt';
procedure fileio;
begin
        assign(input,fi); reset(input);
        assign(output,fo); rewrite(output);
end;
var     a,b:int64;
procedure enter;
begin
        readln(a,b);
end;
procedure solve;
var     i:int64;
        tmp:int64;
begin
        tmp:=1;
        if (b-a>=10) then write(0)
        else
         begin
                i:=a+1;
                while i<=b do
                 begin
                        tmp:=(tmp*i) mod 10;
                        inc(i);
                 end;
                writeln(tmp);
         end;
end;
begin
        //fileio;
        enter;
        solve;
end.

var a,b:int64;
    i,j,t1,t,ans:longint;
begin
    readln(a,b);
    if b-a>=5 then
    begin
        writeln('0');
        halt;
    end
    else
    begin
        t1:=a mod 10;t:=b-a;ans:=1;
        for i:=t1+1 to t1+t do
           ans:=ans*i;
        ans:=ans mod 10;
    end;
    writeln(ans);
end.

const
 fi='';
 fo='';
var   a,b: int64;
      i: integer;
      k: int64;
      f: text;
 procedure nhapfile;
  begin
  assign(f,fi); reset(f);
  readln(f,a,b);
  close(f);
  end;

 procedure xuli;
  begin

   k:=1;
   if (b-a) >= 10 then
    k:=0;
   if b-a < 10 then
    if b=a then k:=1 else
    if b mod 10=0 then k:=0
    else
   begin    a:=a mod 10000;
            b:=b mod 10000;
    for i:=a+1 to b do
     begin
      k:=((k  mod 10)*(i mod 10)) mod 10;
       if k=0 then break;
     end;
   end;
  end;

  procedure xuatfile;
   begin
    assign(f,fo); rewrite(f);
    write(f,k);
    close(f);
   end;

BEGIN
 NHAPFILE;
 XULI;
 XUATFILE;
END.

var i,n,a,x,b:int64;
begin
   n:=1;
   read(a,b);
   i:=a;
   if b - a > 10 then write(0)
   else
   begin
   while i <> b do
     begin
        i:=i+1;
        n:=(n * (i mod 10)) mod 10;
     end;
   write(n);
   end;
end.

program test;
var
  a,b,i,ans:qword;
begin
  readln(a,b);
  if b-a>10 then writeln(0)
  else
    begin
      ans:=1;
      i:=a+1;
      while i<=b do
        begin
          ans:=(ans*i) mod 10;
          inc(i);
        end;
      writeln(ans);
    end;
  readln;
end.

var
i,a,b,f:int64;
begin
read(a,b);
if b-a>9 then begin writeln('0');exit;end
else begin
i:=a+1;
     f:=1;
     while i<=b do begin
     f:=(f*(i mod 10)mod 10);
     inc(i);
     end;
     end;
     writeln(f);
     end.

var a,b,d,k:int64; i,k1:integer;
begin
d:=1;
read(a,b);
if (b-a)<10 then
begin
 k:=b-a; k1:=round(k);
for i:=1 to k1 do
begin
k:=a+i mod 10;
d:=d*k;
d:=d mod 10;
end;
end else d:=0;
write(d);
end.

var a, b, i, s: int64;
Begin;
 readln (a, b);
 if b-a>4 then begin;
  writeln (0);
  exit;
 end;
 s:=1;
 i:=(a mod 10)+1;
 if i<=b mod 10 then Begin;
   while i<=(b mod 10) do begin;
    s:=s*i;
    i:=i+1;
   end;
 end
 else Begin;
  if a=b then writeln (1) else writeln(0);
  exit;
 end;
 writeln (s mod 10);
end.

Program CodeF_439_B;
var a,b:int64;
    i,k:longint;

begin
read(a,b);
k:=1;

  if ((b div 10)>(a div 10)) then write(0) else
    begin
    for i:=(a mod 10)+1 to (b mod 10) do
      begin
      k:=(k*i) mod 10;
      end;
    write(k);
    end;

end.

const   fi='';
var     f:text;
        n,m,s:int64;
        i,t1,t2:longint;
procedure print(s:longint);
begin
        write(s);
        readln;
        halt;
end;
begin
        assign(f,fi);reset(f);
        readln(f,n,m);
        if m-n>=10 then print(0);
        t1:=m mod 10;
        t2:=n mod 10;
        if t1<t2 then t1:=t1+10;
        s:=1;
        for i:=t2+1 to t1 do s:=(s*i) mod 10;print(s);
end.

program EternalImmortality;
var a,b,i,last:int64;
BEGIN
readln(a,b);
last:=(a+1) mod 10;
i:=a+2;
if (a=b) then begin
 writeln(1);
 exit;
end;
while (i<=b) do begin
 last:=(last*(i mod 10)) mod 10;
 if (last=0) then begin
  writeln(0);
  exit;
 end;
 i:=i+1;
end;
writeln(last);
END.

var a,b,x,n:qword;
begin
    //write('nhap a',' : ');
    readln(a,b);
    //write('nhap b',' : ');
   // readln(b);
    x:=1;
    if (b-a) >= 2 then
       begin
           n:=b;
           repeat
               if (n mod 5 <> 0) then
               begin
                    x:=x*n;
                    x:=x mod 10;
               end
               else begin x:=0; break; end;
               dec(n);
           until (n=a) ;
       end
    ELSE if b-a=1 then x:=b mod 10;
    writeln(x);
    //readln;
end.

const
        fi      ='';
        fo      ='';

var
        ff, gg: text;
        A, B, C: int64;
        i, j, t, kq: longint;

begin
        assign(ff, fi); reset(ff);
        assign(gg, fo); rewrite(gg);
        readln(ff, A, B);
        C:= B- A;
        if C > 9 then write(0) else
          begin
                A:= A mod 10;
                t:= A;
                t:=(t+1) mod 10;
                j:= C;
                kq:= 1;
                for i:= 1 to j do
                   begin
                        kq:= kq*(t mod 10);
                        t:= (t+1) mod 10;
                   end;
                write(gg, kq mod 10);
          end;
        close(ff);
        close(gg);
end.

program fenix;
var a,b,c,i:int64;
begin
readln(a,b);
c:=1;
if b-a>=10 then c:=0
else
for i:=a+1 to b do
c:=(c*i mod 10)mod 10;
writeln(c);
end.

program z1;
var a,b,c,i,n:int64;
function min(a,b:int64):int64;
begin
if a>b then min:=b
else min:=a;end;
begin
read(a,b);
c:=1;if b-a =1 then begin write (b mod 10);exit;end;
if a=0 then a:=1;if b=0 then b:=1;
if b-a>10 then begin write(0);exit;end;
i:=a+1;
while i<=b do begin
c:=c*(i mod 10);Inc(i);end;
write(c mod 10);
end.

var i,n,m,k: int64;
begin
 read(n,k);
 if k-n>9 then write (0) else if n=k then
 begin

 write(1)
 end else begin
  m:=(n+1) mod  10; n:=n+2;
  while n<k+1  do begin
  m:=m*(n mod 10)mod 10;n:=n+1;
  end;write(m);
 end;
end.

program vechbessm;
  var   a,b: int64;
    k,l,i:integer;
begin
  k:=1 ;
  read(a,b);
if abs(a-b)>=5 then write('0')
  else
  begin
    for i:=1 to abs(a-b)
do
begin
  l:=((a+i) mod 10);
  K:=K*l;
  end;
 write(k mod 10)
   end;

   end.

var i,ans,a,b:int64;
begin
 readln(a,b);

 if (b - a <= 10) then begin
  ans:=1;
  for i:=a+1 to b do begin
   ans:=ans * i;
   if (ans >= 10) then
    ans:=ans mod 10;
  end;
  writeln(ans);
  end
 else
  writeln(0);
end.

   const eps=0.0000000001;    nn=200000; besk=8000000000;
   label 1,2;
    type   { real=double;}  {string=ansistring;}
    mas=array [0..nn] of longint;   point=record x,y,z:real;end;
    zap=record p1,p2,p3 :int64;end; zap1=^zap;
    mass=array[0..nn] of longint;mass1=^mass;
    var ot,sum1,sum2,ost,kol,zapas,dist,r,ll,rr,sum,q,h,pos,t1,t2,pp,modul,t,tt,time,p,gr,qq,pmax,imax,p1,p2,p3,p4,l,nm,n,s1,s2,m,s,smin,cen,dl,i1:int64;
    ii,jj,step, k,i,j:longint;
     aa,bb,cc:int64;
     fast,slow,z,pr,next,d1,d2,aold,b,a,x,y:array[-1000..2000000] of int64;
     dd:array[-10..2000,-10..200] of extended;
   zanx,zany:array[-10..20000000] of boolean;
    marked,zan:array[-10..10000000] of boolean;
    ss, ss1,ss2:string;
     fl:array[0..200] of boolean;
    ch:char;
    d :array [0..100,-10..100,-10..100] of extended;
    dda:array [0..201,-10..30] of int64;
    sss:array[0..nn] of string;
    st2:array[0..nn] of string;
     pr1,pr2,v0,v1,s0,t0:extended;
     zv:point;
     newx,newy,xx,yy:array[-1..200000] of int64;
     prob:array[-1..200,-1..200] of extended;

     yot:double;
       flag,flag1:boolean;
    function al(x,y:extended):extended; var t0,t1,p,s0,s1:extended;
 begin
     if (x>0)and(y>=0) then p:=arctan(y/x);
     if x<0 then p:=pi+arctan(y/x);
     if(x>0)and(y<0) then p:=2*pi+arctan(y/x);
     if x=0 then if (y>=0) then p:=pi/2 else p:=3*pi/2;
     al:=p/pi*180;
 end;
  function min(x,y:int64):int64;begin min:=x;if y<x then min:=y; end;
  function max(x,y:int64):int64;begin max:=x;if y>x then max:=y; end;

  function nod(x,y:int64):int64; var z:int64;
begin   repeat  z:=x mod y;x:=y;y:=z;   until  z=0 ;  nod:=x;end;

function degg(a,k:int64):int64; var p:int64;
begin
 if k<=0 then degg:=1 else if odd(k) then degg:=degg(a,k-1)*a mod modul else
   begin  p:=degg(a,k div 2); degg:=p*p mod modul;   end;

end;

begin
  {  assign (input,'input.txt');reset(input);
      assign (output,'output.txt'); rewrite(output);
   }
      read(p1,p2);
         if p2>p1+5 then begin  write(0); goto 1;   end;
     p1:=p1 mod 10;
     p2:=p2 mod 10;
     if p2<p1 then p2:=p2+10;
     ot:=1;
     for i:=p1+1 to p2 do ot:=ot*i mod 10;
     writeln(ot);

   1:          close(output);
end.

program EternalImmortality;
var a,b,i,last:int64;
BEGIN
readln(a,b);
last:=(a+1) mod 10;
i:=a+2;
while (i<=b) do begin
 last:=(last*(i mod 10)) mod 10;
 if (last=0) then begin
  writeln(0);
  exit;
 end;
 i:=i+1;
end;
writeln(last);
END.

const
        fi      ='';
        fo      ='';

var
        ff, gg: text;
        A, B, C: int64;
        i, j, t, kq: longint;

begin
        assign(ff, fi); reset(ff);
        readln(ff, A, B);
        C:= B- A;
        if C > 9 then write(0) else
          begin
                A:= A mod 10;
                t:= A;
                t:=(t+1) mod 10;
                j:= C;
                kq:= 1;
                for i:= 1 to j do
                   begin
                        kq:= kq*t;
                        inc(t);
                   end;
                write(kq mod 10);
          end;
        readln;
end.

program z1;
var a,b,c:int64;i,m:longint;n:int64;
function min(a,b:int64):int64;
begin
if a>b then min:=b
else min:=a;end;
begin
read(a,b);
c:=1;if b-a =1 then begin write (b mod 10);exit;end;
if a=0 then a:=1;if b=0 then b:=1;
if b-a>10 then begin write(0);exit;end;
for i:= a+1 to b do
c:=c*(i mod 10);
write(c mod 10);
end.

program z1;
var a,b,c:int64;i,m:longint;n:byte;
function min(a,b:longint):longint;
begin
if a>b then min:=b
else min:=a;end;
begin
read(a,b);
c:=1;if b-a =1 then begin write (b mod 10);exit;end;
if a=0 then a:=1;if b=0 then b:=1;n:=min(b-a,10);
if n=10 then begin write(0);exit;end;
for i:= a+1 to b do
c:=c*(i mod 10);
write(c mod 10);
end.

program z1;
var a,b,c:int64;i,m:longint;n:byte;
function min(a,b:longint):longint;
begin
if a>b then min:=b
else min:=a;end;
begin
read(a,b);
c:=1;
if a=0 then a:=1;if b=0 then b:=1;n:=min(b-a,10);
if n=10 then begin write(0);exit;end;
for i:= a+1 to b do
c:=c*(i mod 10);
write(c mod 10);
end.

var i,n,m,k: int64;
begin
 read(n,k);
 if k-n>9 then write (0) else if n=k then
 begin

 write(1)
 end else begin
  m:=(n+1) mod  10;
  while n<k  do begin
  n:=n+1; m:=m*(n mod 10)mod 10;
  end;write(m);
 end;
end.

program vechbessm;
  var   a,b,l,k,i: longint;
begin
  k:=1 ;
  read(a,b);
if abs(a-b)>=5 then write('0')
  else
  begin
    for i:=1 to abs(a-b)
do
begin
  l:=(a+i mod 10);
  K:=K*l;
  end;
 write(k mod 10)
   end;

   end.

var a,b,i,kq:int64;
begin
        readln(a,b);
        kq:=(a+1)mod 10;
        i:=a+2;
        while i<=b do begin
                kq:=(kq*i) mod 10;
                if kq=0 then break;
                inc(i);
        end;
        writeln(kq);
end.

program qq;
var a,b,o,n,i:int64;
Begin
 read(a,b); n:=1;i:=a+1;
 while a<=b do begin
 o:=i mod 10;
 n:=(n*o) mod 10;
 if n=0 then break;
 i:=i+1;
 end;
 writeln(n);
end.

var
a,b:int64;
col:integer;
start:integer;
finish:integer;
i:integer;
begin
read(a,b);
i:=1;
col:=0;
if(b<6+a)then begin
col:=1;
start:=(a+1)mod 10;
finish:=(b)mod 10;
if(finish<start)then inc(finish,10);
while(start<=finish)do begin
col:=(col*(start))mod 10; inc(start);
end;     end;
writeln(col);
end.

var a,b,i,ans:longint;
begin
readln(a,b);
if b-a>10 then writeln(0)
         else if a=b then write(1)
                       else begin
                               ans:=1;
                               i:=a+1;
                               while i<=b do begin
                               ans:=(ans*i) mod 10;
                               inc(i);
                               end;
                               writeln(ans);
                               end;
                               end.

var i,a,a1,b,b1:longint;
begin
readln(a,b);
if b-a>10 then writeln(0)
          else begin
                 a:=a mod 10;
                 b:=b mod 10;
                 a1:=1;
                for i:=2 to a do
                a1:=a1*i;
                b1:=1;
                for i:=2 to b do
                b1:=b1*i;
                b1:=b1 div a1;
                write(b1 mod 10);
                end;
                end.

var i,a,a1,b,b1:longint;
begin
readln(a,b);
if b-a>=10 then writeln(0)
          else begin
                 a:=a mod 10;
                 inc(a);
                 b:=b mod 10;
                 inc(b);
                 a1:=1;
                for i:=2 to a do
                a1:=a1*i;
                b1:=1;
                for i:=2 to b do
                b1:=b1*i;
                b1:=b1 div a1;
                write(b1 mod 10);
                end;
                end.

var i,a,a1,b,b1:longint;
begin
readln(a,b);
if b-a>=10 then writeln(0)
          else begin
                   if a>10 then begin
                 a:=a mod 10;
                 inc(a);
                 b:=b mod 10;
                 inc(b);
                 end;
                 a1:=1;
                for i:=2 to a do
                a1:=a1*i;
                b1:=1;
                for i:=2 to b do
                b1:=b1*i;
                b1:=b1 div a1;
                write(b1 mod 10);
                end;
                end.

var a,b,i,ans:longint;
begin
 readln(a,b);
 if b-a>10 then writeln(0)
           else begin
                 ans:=1;
                 i:=a+1;
                 while i<=b do begin
                                ans:=(ans*i) mod 10;
                                inc(i);
                               end;
                 writeln(ans);
               end;
readln;
end.

var a,b,n,i,j:integer;
d:array [1..9] of integer;
begin
read (a,b);
n:=b-a;
j:=1;
if n>=10 then begin write (0); exit; end
else
begin
for i:=1 to n do
 begin
  j:=(j*(a+i)) mod 10;
 end;
write (j);
end;
end.

var a,b:int64;c:byte;
Begin
    readln(a,b);
    b:=b-a;a:=1;
    if(b<5) then begin
    for c:=1 to b do a:=(a*c)mod 10
    end
    else a:=0;
    write(a);
end.

var a,b:int64;c,z:byte;
Begin
    readln(a,b);
    z:=1;
    if(b-a<5) then begin
    for c:=a+1 to b do z:=(z*c)mod 10
    end
    else z:=0;
    write(z);
end.

var ans,i:longint;
    a,b:int64;
   begin
        readln(a,b); ans:=1;
        for i:=a+1 to b do
            ans:=ans*(i mod 10) mod 10;
         writeln(ans);
   end.

var
a,b,c,i:qword;

flag: integer;
begin
readln(a,b);
c:=b-a;
flag:=1;
if (c=0) then writeln(1)
else begin
    c:=1;
    i:=a+1;
    while ((i<=b)and(flag=1)) do begin
        c:=c*(i mod 10);
        if (c=0) then flag:=0;
        i:=i+1;
    end;
end;
writeln(c mod 10);
end.

var a,b,c1,pn :qword;
    kq,i : longint;
BEGIN
  read(a,b);
      kq:=1;

     if b mod 10=0 then kq:=0;
     if b mod 10 <> 0 then
    for i:=1 to b-a do
      begin
          pn:=a+i;
          c1:=pn mod 10;
          kq:=kq * c1;
          kq:=kq mod 10;
          if kq=0 then break;
      end;

   write(kq);
END.

 var a,b,k:int64;
     i:longint;
begin
 readln(a,b);
 k:=a+1;
 k:=k mod 10;
 for i:=1 to (b-a-1) do begin
   k:=k*((i+a+1) mod 10);
   k:=k mod 10;
   if k=0 then
     break;
 end;
 if b=0 then
   k:=1;
   if a=b then
     k:=1;
 writeln(k);
end.

 var a,b,k:int64;
     i:longint;
begin
 readln(a,b);
 k:=a+1;
 for i:=a+2 to b do begin
   k:=k*i;
   k:=k mod 10;
 end;
 if b=0 then
   k:=1;
 writeln(k);
end.

 var a,b,k:int64;
     i:longint;
begin
 readln(a,b);
 k:=a+1;
 k:=k mod 10;
 for i:=1 to (b-a-1) mod 100 do begin
   k:=k*((i+a+1) mod 10);
   k:=k mod 10;
   if k=0 then
     break;
 end;
 if b=0 then
   k:=1;
 if a=b then
   k:=1;
 writeln(k);
end.

 var a,b,k:int64;
     i:longint;
begin
 readln(a,b);
 k:=a+1;
 for i:=1 to (b-a-1) do begin
   k:=k*((i+a+1) mod 10);
   k:=k mod 10;
   if k=0 then
     break;
 end;
 if b=0 then
   k:=1;
 writeln(k);
end.

   const eps=0.0000000001;    nn=200000; besk=8000000000;
   label 1,2;
    type   { real=double;}  {string=ansistring;}
    mas=array [0..nn] of longint;   point=record x,y,z:real;end;
    zap=record p1,p2,p3 :int64;end; zap1=^zap;
    mass=array[0..nn] of longint;mass1=^mass;
    var ot,sum1,sum2,ost,kol,zapas,dist,r,ll,rr,sum,q,h,pos,t1,t2,pp,modul,t,tt,time,p,gr,qq,pmax,imax,p1,p2,p3,p4,l,nm,n,s1,s2,m,s,smin,cen,dl,i1:int64;
    ii,jj,step, k,i,j:longint;
     aa,bb,cc:int64;
     fast,slow,z,pr,next,d1,d2,aold,b,a,x,y:array[-1000..2000000] of int64;
     dd:array[-10..2000,-10..200] of extended;
   zanx,zany:array[-10..20000000] of boolean;
    marked,zan:array[-10..10000000] of boolean;
    ss, ss1,ss2:string;
     fl:array[0..200] of boolean;
    ch:char;
    d :array [0..100,-10..100,-10..100] of extended;
    dda:array [0..201,-10..30] of int64;
    sss:array[0..nn] of string;
    st2:array[0..nn] of string;
     pr1,pr2,v0,v1,s0,t0:extended;
     zv:point;
     newx,newy,xx,yy:array[-1..200000] of int64;
     prob:array[-1..200,-1..200] of extended;

     yot:double;
       flag,flag1:boolean;
    function al(x,y:extended):extended; var t0,t1,p,s0,s1:extended;
 begin
     if (x>0)and(y>=0) then p:=arctan(y/x);
     if x<0 then p:=pi+arctan(y/x);
     if(x>0)and(y<0) then p:=2*pi+arctan(y/x);
     if x=0 then if (y>=0) then p:=pi/2 else p:=3*pi/2;
     al:=p/pi*180;
 end;
  function min(x,y:int64):int64;begin min:=x;if y<x then min:=y; end;
  function max(x,y:int64):int64;begin max:=x;if y>x then max:=y; end;

  function nod(x,y:int64):int64; var z:int64;
begin   repeat  z:=x mod y;x:=y;y:=z;   until  z=0 ;  nod:=x;end;

function degg(a,k:int64):int64; var p:int64;
begin
 if k<=0 then degg:=1 else if odd(k) then degg:=degg(a,k-1)*a mod modul else
   begin  p:=degg(a,k div 2); degg:=p*p mod modul;   end;

end;

begin
  {  assign (input,'input.txt');reset(input);
      assign (output,'output.txt'); rewrite(output);
   }
      read(p1,p2);

     p1:=p1 mod 10;
     p2:=p2 mod 10;
     if p2>p1+5 then begin  write(0); goto 1;   end;
     if p2<p1 then p2:=p2+10;
     ot:=1;
     for i:=p1+1 to p2 do ot:=ot*i mod 10;
     writeln(ot);

   1:          close(output);
end.

 var a,b,k:int64;
     i:longint;
begin
 readln(a,b);
 k:=a+1;
 k:=k mod 10;
 for i:=a+2 to b do begin
   k:=k*(i mod 10);
   k:=k mod 10;
   if k=0 then
     break;
 end;
 if b=0 then
   k:=1;
 if a=b then
   k:=1;
 writeln(k);
end.

 var a,b,k:int64;
     i:longint;
begin
 readln(a,b);
 k:=a+1;
 k:=k mod 10;
 for i:=1 to (b-a-1) do begin
   k:=k*((i+a+1) mod 10);
   k:=k mod 10;
   if k=0 then
     break;
 end;
 if b=0 then
   k:=1;
 writeln(k);
end.

 var a,b,k,i:longint;
begin
 readln(a,b);
 k:=a+1;
 for i:=a+2 to b do begin
   k:=k*i;
   k:=k mod 10;
 end;
 if b=0 then
   k:=1;
 writeln(k);
end.

 var a,b,k:int64;
     i:longint;
begin
 readln(a,b);
 k:=a+1;
 k:=k mod 10;
 for i:=1 to (b-a-1) mod 1000 do begin
   k:=k*((i+a+1) mod 10);
   k:=k mod 10;
   if k=0 then
     break;
 end;
 if b=0 then
   k:=1;
 if a=b then
   k:=1;
 writeln(k);
end.

{$mode objfpc}
program Fenix;

var
  a, b, c, proizv: int64;

  i: integer;
begin
  readln(a, b);

  c := b - a;

  if c = 0 then
  begin
    Write(1);
  //readln();
    exit;
  end;

  proizv := 1;
  if c >= 10 then
  begin
    Write(0);
    //readln();
    exit;
  end
  else
  begin
    for i := (b - c + 1) to b do
      proizv := (proizv * i) mod 10;
  end;

  Write(proizv);
  // readln();
end.

{$mode objfpc}
program Fenix;
var
  a, b, c, proizv: int64;
  s: string;
  i: integer;
begin
  readln(a, b);

  c := b - a;

  if c = 0 then
  begin
    write(1);
    //readln();
    exit;
  end;

  proizv := 1;
  for i := 1 to b - ((b - c)) do
    proizv := proizv * (i + (b - c));

  str(proizv, s);

  write(s[length(s)]);
  //readln();
end.

{$mode objfpc}
program Fenix;
var
  a, b, c, proizv: int64;
  s: string;
  i: integer;
begin
  readln(a, b);

  c := b - a;

  if c = 0 then
  begin
    write(1);
  //  readln();
    exit;
  end;

  proizv := 1;
  if (c div 10) >= 1 then
   begin
     write(0);
     //readln();
     exit;
   end
  else
  begin
    for i := (b - c + 1) to b do
    proizv := proizv * i;
  end;

  str(proizv, s);

  write(s[length(s)]);

 // readln();
end.

{$mode objfpc}
program Fenix;
var
  a, b, c, proizv: int64;
  s: string;
  i: integer;
begin
  readln(a, b);

  c := b - a;

  if c = 0 then
  begin
    write(1);
  //  readln();
    exit;
  end;

  proizv := 1;
  if (c div 10) >= 1 then
   begin
     write(0);
     //readln();
     exit;
   end
  else
  begin
    for i := (b - c + 1) to b do
    proizv := (proizv * i) mod 10 ;
  end;

  str(proizv, s);

  write(s[length(s)]);

 // readln();
end.

const
 fi='';
 fo='';
var   a,b: int64;
      i: integer;
      k: int64;
      f: text;
 procedure nhapfile;
  begin
  assign(f,fi); reset(f);
  readln(f,a,b);
  close(f);
  end;

 procedure xuli;
  begin
   k:=1;
   if (b-a) >= 10 then
    k:=0;
   if b-a < 10 then
   for i:=a+1 to b do
   begin
    k:=((k  mod 10)*(i mod 10)) mod 10;
    if k=0 then break;
   end;

  end;

  procedure xuatfile;
   begin
    assign(f,fo); rewrite(f);
    write(f,k);
    close(f);
   end;

BEGIN
 NHAPFILE;
 XULI;
 XUATFILE;
END.

const
 fi='';
 fo='';
var   a,b: int64;
      i: integer;
      k: int64;
      f: text;
 procedure nhapfile;
  begin
  assign(f,fi); reset(f);
  readln(f,a,b);
  close(f);
  end;

 procedure xuli;
  begin
   k:=1;
   for i:=a+1 to b do
   begin
    k:=((k  mod 10)*(i mod 10)) mod 10;
    if k=0 then break;
   end;

  end;

  procedure xuatfile;
   begin
    assign(f,fo); rewrite(f);
    write(f,k);
    close(f);
   end;

BEGIN
 NHAPFILE;
 XULI;
 XUATFILE;
END.

const
 fi='';
 fo='';
var   a,b: int64;
      i: integer;
      k: int64;
      f: text;
 procedure nhapfile;
  begin
  assign(f,fi); reset(f);
  readln(f,a,b);
  close(f);
  end;

 procedure xuli;
  begin

   k:=1;
   if (b-a) >= 10 then
    k:=0;
   if b-a < 10 then
    if b mod 10=0 then k:=0
    else
   begin    a:=a mod 10000;
            b:=b mod 10000;
    for i:=a+1 to b do
     begin
      k:=((k  mod 10)*(i mod 10)) mod 10;
       if k=0 then break;
     end;
   end;
  end;

  procedure xuatfile;
   begin
    assign(f,fo); rewrite(f);
    write(f,k);
    close(f);
   end;

BEGIN
 NHAPFILE;
 XULI;
 XUATFILE;
END.

const
 fi='';
 fo='';
var   a,b: int64;
      i: integer;
      k: int64;
      f: text;
 procedure nhapfile;
  begin
  assign(f,fi); reset(f);
  readln(f,a,b);
  close(f);
  end;

 procedure xuli;
  begin
   a:=a mod 10000;
   b:=b mod 10000;
   k:=1;
   if (b-a) >= 10 then
    k:=0;
   if b-a < 10 then
   for i:=a+1 to b do
   begin
    k:=((k  mod 10)*(i mod 10)) mod 10;
    if k=0 then break;
   end;

  end;

  procedure xuatfile;
   begin
    assign(f,fo); rewrite(f);
    write(f,k);
    close(f);
   end;

BEGIN
 NHAPFILE;
 XULI;
 XUATFILE;
END.

const
 fi='';
 fo='';
var   a,b: int64;
      i: integer;
      k: int64;
      f: text;
 procedure nhapfile;
  begin
  assign(f,fi); reset(f);
  readln(f,a,b);
  close(f);
  end;

 procedure xuli;
  begin

   k:=1;
   if (b-a) >= 10 then
    k:=0;
   if b-a < 10 then
   begin    a:=a mod 10000;
            b:=b mod 10000;
    for i:=a+1 to b do
     begin
      k:=((k  mod 10)*(i mod 10)) mod 10;
       if k=0 then break;
     end;
   end;
  end;

  procedure xuatfile;
   begin
    assign(f,fo); rewrite(f);
    write(f,k);
    close(f);
   end;

BEGIN
 NHAPFILE;
 XULI;
 XUATFILE;
END.

var n,a,b:int64;
i:longint;
begin
   n:=1;
   read(a,b);
   for i:=a+1 to b do
     begin
        if n * (i mod 10) > 9 then n:=(n*i mod 10) mod 10
        else n:=(i mod 10) *n;
     end;
   write(n);
end.

var a,b,d:int64; i:integer;
begin
d:=1;
read(a,b);
if (b-a)<10 then
for i:=a+1 to b do
begin
d:=d*(i mod 10);
d:=d mod 10;
end else d:=0;
write(d mod 10);
end.

var a,b,i:longint; d:int64;
begin
d:=1;
read(a,b);
for i:=a+1 to b do
d:=d*i;
write(d mod 10);
end.

var a, b, i, s: int64;
Begin;
 readln (a, b);
 if b-a>4 then begin;
  writeln (0);
  exit;
 end;
 s:=1;
 i:=(a+1)mod 10;
 if i<=b mod 10 then Begin;
   while i<=(b mod 10) do begin;
    s:=s*i;
    i:=i+1;
   end;
 end
 else Begin;
  writeln(0);
  exit;
 end;
 writeln (s mod 10);
end.

var a, b, i, s: int64;
Begin;
 readln (a, b);
 if b-a>4 then begin;
  writeln (0);
  exit;
 end;
 s:=1;
 i:=(a+1)mod 10;
 while i<=(b mod 10) do begin;
  s:=s*i;
  i:=i+1;
 end;
 writeln (s mod 10);
end.

Program CodeF_439_B;
var a,b:int64;
    i,k:longint;

begin
read(a,b);
k:=1;
if a=0 then write(0) else
  begin
  if ((b div 10)>(a div 10)) then write(0) else
    begin
    for i:=(a mod 10)+1 to (b mod 10) do
      begin
      k:=(k*i) mod 10;
      end;
    write(k);
    end;
  end;

end.

const   fi='';
var     f:text;
        n,m,s:int64;
        i:longint;
procedure print(s:longint);
begin
        write(s);
        readln;
        halt;
end;
begin
        assign(f,fi);reset(f);
        readln(f,n,m);
        if m-n>=10 then print(0);
        s:=1;
        for i:=n+1 to m do s:=((i mod 10)*s) mod 10;print(s);
end.

const   fi='';
var     f:text;
        n,m,s:int64;
        i:longint;
procedure print(s:longint);
begin
        write(s);
        readln;
        halt;
end;
begin
        assign(f,fi);reset(f);
        readln(f,n,m);
        if m-n>=10 then print(0);
        s:=1;
        for i:=n+1 to m do s:=(s*i) mod 10;print(s);
end.

program theeternalimmortality;
var a,b:int64;
procedure input;
var f:text;
begin
        readln(a,b);
end;
procedure output;
var f:text;
    x,y,i,k:longint;
begin
        if b-a>=10 then writeln(0)
        else
        begin
                x:=a mod 10;
                y:=b mod 10;
                if y>x then
                begin
                        k:=1;
                        for i:=x+1 to y do k:=(k*i)mod 10;
                        writeln(k);
                end
                else
        end;
end;
begin
        input;
        output;
end.