var a:array['0'..'9']of boolean;
    i:longint;
    s:string;
begin
  readln(i);
  readln(s);
  for i:=1 to length(s) do
    a[s[i]]:=true;
  if (a['1']or a['2']or a['3']) and (a['7']or a['0']or a['9']) and ((a['1']or a['4']or a['7'])and(a['3']or a['6']or a['9'])or a['0']) then writeln('YES')
  else writeln('NO');
end.

program Project3;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var n, i, cur : longint;
    u, d, l, r, o, z : boolean;
    c : char;

begin
//  assign(input, 'input.txt'); assign(output, 'output.txt');
  readln(n);
  for i := 1 to n do
  begin
    read(c);
    cur := ord(c) - ord('0');
    if (cur > 0) and (cur < 4) then
      begin
        u := True;
        o := True;
      end;
    if (cur = 7) or (cur = 0) or (cur = 9) then
      d := True;
    if (cur = 1) or (cur = 4) or (cur = 7) then
      l := True;
    if (cur = 3) or (cur = 6) or (cur = 9) then
      r := True;
    if cur = 0 then
      z := True;
  end;

  if ((u and d) and (l and r)) or (o and z) then
    write('YES')
  else
    write('NO');
end.

var n,i,j,x,y:longint;s:string;
a:array[-11..11,-11..11] of longint;
b,c,h,l:array[0..11] of longint;
function pd(x:longint):boolean;
var a1,b1,i:longint;
begin
a1:=b[x];b1:=c[x];
for i:=2 to n do
  begin
  a1:=a1+h[i];b1:=b1+l[i];
  if a[a1,b1]=-1 then exit(false);
  end;
exit(true);
end;
begin
//assign(input,'mphone.in');reset(input);
//assign(output,'mphone.out');rewrite(output);
readln(n);readln(s);
fillchar(a,sizeof(a),255);
a[4,2]:=0;b[0]:=4;c[0]:=2;
for i:=1 to 3 do
  begin
  for j:=1 to 3 do
    begin
    a[i,j]:=(i-1)*3+j;b[(i-1)*3+j]:=i;c[(i-1)*3+j]:=j;
    end;
  end;
for i:=2 to n do
  begin
  x:=ord(s[i-1])-48;
  y:=ord(s[i])-48;
  h[i]:=b[y]-b[x];
  l[i]:=c[y]-c[x];
  end;
for i:=0 to 9 do
  if(chr(i+48)<>s[1])and(pd(i))then
    begin
    writeln('NO');close(input);close(output);halt;
    end;
writeln('YES');
close(input);close(output);
end.

var c:char;
    n,i:longint;
    l,r,u,d,z:boolean;
begin
readln(n);
for i:=1 to n do
  begin
  read(c);
  if (c='1') or (c='4') or (c='7') then
    l:=true;
  if (c='3') or (c='6') or (c='9') then
    r:=true;
  if (c='1') or (c='2') or (c='3') then
    u:=true;
  if (c='7') or (c='9') then
    d:=true;
  if (c='0') then
    z:=true;
  end;
if (z and u) or (l and r and u and d) then
  writeln('YES')
else
  writeln('NO');
end.

var x1,y1,i,n,j:longint;flag:boolean;c:char;
x,y,a:array[0..1000000] of longint;
f:array[-1001..1001,-1001..1001] of boolean;
begin
//assign(input,'mphone.in');reset(input);
//assign(output,'mphone.out');rewrite(output);
x[1]:=1;y[1]:=1;
x[2]:=1;y[2]:=2;
x[3]:=1;y[3]:=3;
x[4]:=2;y[4]:=1;
x[5]:=2;y[5]:=2;
x[6]:=2;y[6]:=3;
x[7]:=3;y[7]:=1;
x[8]:=3;y[8]:=2;
x[9]:=3;y[9]:=3;
x[0]:=4;y[0]:=2;
readln(n);
for i:=1 to n do
  begin
  read(c);
  a[i]:=ord(c)-48;
  end;
for i:=0 to 9 do f[x[i],y[i]]:=true;
for i:=0 to 9 do
  begin
  if i=a[1] then continue;
  x1:=x[i];y1:=y[i];flag:=true;
  for j:=2 to n do
    begin
    x1:=x1+(x[a[j]]-x[a[j-1]]);
    y1:=y1+(y[a[j]]-y[a[j-1]]);
    if f[x1,y1]=false then
      begin flag:=false;break;end;
    end;
  if flag then
    begin
    writeln('NO');
    close(input);close(output);
    halt;
    end;
  end;
writeln('YES');
close(input);close(output);
end.

   const eps=0.0000000001;  besk=8000000000000000000;  nn=200000;
   modul=1000000007;
   label 1,2;
    type
    mas=array [-10000..nn] of int64;  { point=record x,y,z:real;end; }
    zap=record p1,p2,p3 :int64;end; zap1=^zap;
    mass=array[0..5] of int64;mass1=^mass;
    var imax,imin,jmax,jmin,koln,kfin,distmin,ii,jj,kk,zn,razmax,pmin,pmax,sch,iistart,xmax,ymin,n,qq,ot,q,pos,left,right,amax,ost,h,tt,t1,pp,p,p1,p2,p3,p4,t,nm,s1,s2,m,s,cen,t2,i1:int64;
    stepp,iii,mask,newug,newdl,dloch,dugol,ist,jst,ifin,jfin,fin,newnapx,newnapy,step, k,i,j:longint;
    oldnap, napr,alpha,prmax,v,aaa,bbb,ccc:extended; hhh:zap;
    napx,napy,x,first,next,prev,l,r, dl,ochnewi,ochnewj,ochj,c,y,z,newoch,och,aold,b,a:array[-100000..2000000] of int64;
   stpr,stoim,blup,bldown, blright, blleft, ppole,vol:array[-10..1200,-10..1200] of int64;
   marked:array[-10..1100000] of boolean;
    yyy,xx:mass;
    ss, ss1,ss2:string;
    point:array[0..200000] of mass;
    sa,sb,pra,prb,suma,sumb,ota,otb,mmax,mmin,smax,smin:array[-100..200000] of extended;
     zan:array[-10..20,010..200] of boolean;
    sss: array[-10..100000] of string;ch3,ch,ch1,ch2:char;
    dp:array[-1..500,-1..500,-1..500]of boolean;
    clav:array[-10..300,-10..300] of int64;
    ugol:array[0..5000,0..5000] of double;

  ddmax,ddmin :array[-1..300000,-1..20] of extended;
    chh,pole :array [-10..200,-10..200] of char;
    maxpr:array[0..nn] of string;
    str:array[0..nn] of string;
     nap,tt1,tt2,disk,v0,v1,s0,t0:extended;
     newx,newy,yy:array[-100..200000] of int64;

     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;

function good(ii,jj:longint):boolean;   var fl:boolean;
i,j:longint;
  begin
     fl:=false;
     if clav[ii,jj]>=0 then fl:=true;
     good:=fl;
  end;

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

   readln(n);
   readln(ss);
   napx[1]:=1;  napy[1]:=0;
   napx[2]:=-1;  napy[2]:=0;
   napx[3]:=0;  napy[3]:=1;
   napx[4]:=0;  napy[4]:=-1;

   for i:=-10 to 100 do for j:=-10 to 100 do clav[i,j]:=-1;
   clav[1,1]:=1;
   clav[1,2]:=2;
   clav[1,3]:=3;
   clav[2,1]:=4;
   clav[2,2]:=5;
   clav[2,3]:=6;
   clav[3,1]:=7;
   clav[3,2]:=8;
   clav[3,3]:=9;
   clav[4,2]:=0;
   for step:=1 to n do
     begin
        t:=ord(ss[step])-48;
        for i:=0 to 4 do for j:=0 to 4 do
        if clav[i,j]=t then zan[i,j]:=true;

     end;

   { for i:=0 to 5 do for j:=0 to 5 do if good(i,j) then writeln(i,' good ',j);
    }
    for step:=1 to 4 do
      begin
         flag:=true;
         for i:=1 to 4 do for j:=1 to 4 do if zan[i,j] then
           begin
               if not good(i+napx[step],j+napy[step]) then flag:=false;

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

      end;
       writeln('YES');

   1:          close(output);
end.

var n,i,vmin,vmax,gmin,gmax,e,x,y,l7,l9:longint;
c:char;
begin
y:=0; vmax:=-1; gmax:=-1; vmin:=100; gmin:=100;
l7:=0; l9:=0;
readln(n);
for i:=1 to n do
begin
read(c);
val(c,x,e);
if (x=0) then begin y:=1; vmax:=3; if (1<gmin) then gmin:=1; if (1>gmax) then gmax:=1; if (3<vmin) then vmin:=3; end else
begin
if (x=7) then l7:=1 else if (x=9) then l9:=1;
if ((x-1) div 3>vmax) then vmax:=(x-1) div 3;
if ((x-1) div 3<vmin) then vmin:=(x-1) div 3;
if ((x-1) mod 3>gmax) then gmax:=(x-1) mod 3;
if ((x-1) mod 3<gmin) then gmin:=(x-1) mod 3;
end;
end;
if ((y=1) and (vmax-vmin+1>=4)) or ((y=0) and ((vmax-vmin+1>=3) and ((l7=1) or (l9=1))) and (gmax-gmin+1>=3)) then write('YES') else write('NO');
end.

var
 a,b,aa:array[-1..10,-1..10]of longint;
 res:array[0..10000]of string;
 n,m,k,l,j,i,p1,p2,p3,p4:longint;
 s:string;
begin
 readln(n);
 readln(s);
 b[1,1]:=1;b[1,2]:=1;b[1,3]:=1;b[2,1]:=1;b[2,2]:=1;
 b[2,3]:=1;b[3,1]:=1;b[3,2]:=1;b[3,3]:=1;b[4,2]:=1;

 for i:=1 to n do
 begin
  if s[i]='1' then a[1,1]:=1;
  if s[i]='2' then a[1,2]:=1;
  if s[i]='3' then a[1,3]:=1;
  if s[i]='4' then a[2,1]:=1;
  if s[i]='5' then a[2,2]:=1;
  if s[i]='6' then a[2,3]:=1;
  if s[i]='7' then a[3,1]:=1;
  if s[i]='8' then a[3,2]:=1;
  if s[i]='9' then a[3,3]:=1;
  if s[i]='0' then a[4,2]:=1;
 end;

 aa:=a;
 for i:=4 downto 1 do
 begin
  for j:=4 downto 1 do if a[i,j]=1 then begin a[i,j]:=0; a[i+1,j]:=1; end;
 end;
 p1:=1; p2:=1; p3:=1; p4:=1;
 for i:=0 to 5 do
 begin
  for j:=0 to 5 do if (a[i,j]=1)and(b[i,j]=0) then p1:=0;
 end;

 a:=aa;
 for i:=1 to 4 do
 begin
  for j:=1 to 4 do if a[i,j]=1 then begin a[i,j]:=0; a[i-1,j]:=1; end;
 end;
 for i:=0 to 5 do
 begin
  for j:=0 to 5 do if (a[i,j]=1)and(b[i,j]=0) then p2:=0;
 end;

 a:=aa;
 for i:=5 downto 0 do
 begin
  for j:=5 downto 0 do if a[i,j]=1 then begin a[i,j]:=0; a[i,j+1]:=1; end;
 end;
 for i:=0 to 5 do
 begin
  for j:=0 to 5 do if (a[i,j]=1)and(b[i,j]=0) then p3:=0;
 end;

 a:=aa;
 for i:=1 to 5 do
 begin
  for j:=1 to 5 do if a[i,j]=1 then begin a[i,j]:=0; a[i,j-1]:=1; end;
 end;
 for i:=0 to 5 do
 begin
  for j:=0 to 5 do if (a[i,j]=1)and(b[i,j]=0) then p4:=0;
 end;

 if (p1+p2+p3+p4>0) then writeln('NO') else writeln('YES');
end.

Var n,i,j,ff1:longint;
    s:string;
    f,a,b:array[0..9] of longint;
    const x:array[0..10] of longint =(4,1,1,1,2,2,2,3,3,3,4);
    const y:array[0..10] of longint =(2,1,2,3,1,2,3,1,2,3,2);
    Begin
    readln(n);
    readln(s);
    for i:=0 to 9 do
     begin
     a[i]:=x[i];
     b[i]:=y[i];
     end;
    f[ord(s[1])-48]:=1;
    for i:=2 to n do
     begin
      for j:=0 to 9 do
       begin
        a[j]:=a[j]-(x[ord(s[i-1])-48]-x[ord(s[i])-48]);
        b[j]:=b[j]-(y[ord(s[i-1])-48]-y[ord(s[i])-48]);
        if (b[j]<>2) and (a[j]=4) then f[j]:=1;
        if (a[j]<1) then f[j]:=1;
        if (b[j]>3) then f[j]:=1;
        if (b[j]<1) then f[j]:=1;
        if (a[j]>4) then f[j]:=1;

       end;
     end;
     ff1:=0;
     for i:=0 to 9 do
      if f[i]=0 then ff1:=1;
     if ff1=1 then writeln('NO')
      else writeln('YES');
     end.

{$MODE OBJFPC}

Const
  Input= '';
  Output= '';

Var
  Fi, fo: text;
  n, i, j: integer;
  res, ks: boolean;
  d, ng, fd, fn, cd, cn, a: array[0..10] of integer;

Procedure Enter;
  var x: char;
  Begin
    readln(Fi, n);
    for i:=1 to n do
      begin
        read(fi, x);
        a[i]:= ord(x)-48
      end;
  End;

Procedure init;
  begin
    for i:= 1 to 9 do
      begin
        d[i]:= i mod 3;
        ng[i]:= i div 3;
        if d[i]<>0 then inc(ng[i])
        else d[i]:= 3;
      end;
    d[0]:= 2; ng[0]:= 4;
    for i:=2 to n do
      begin
        fd[i]:= d[a[i]]-d[a[i-1]];
        fn[i]:= ng[a[i]]- ng[a[i-1]];
      end;
  end;

Procedure Solve;
  Begin
    i:= 0;
    res:= true;
    while (i<= 9) do
      begin
        if i<>a[1] then
          begin
            ks:= true;
            cd[1]:= d[i];
            cn[1]:= ng[i];
            for j:= 2 to n do
              begin
                cd[j]:= cd[j-1]+fd[j];
                cn[j]:= cn[j-1]+fn[j];
                if ((cd[j]=1) or (cd[j]= 3)) and (cn[j]=4) then ks:= false
                else
                if (cd[j]<1) or (cd[j]>3) or (cn[j]<1) or (cn[j]>4) then ks:= false;
              end;
            if ks then
              begin
                res:= false;
                break;
              end;
          end;
        inc(i);
      end;
  End;

Procedure Finish;
  Begin
    if not res then write(fo, 'NO')
    else write(fo, 'YES');
  End;

Begin
  Assign(Fi, Input); Reset(Fi);
  Assign(Fo, Output); Rewrite(Fo);
  Enter;
  Init;
  Solve;
  Finish;
  Close(Fi); Close(Fo);
End.

Const Finp='';
      Fout='';
      res:array[1..2] of string=('YES','NO');
Var n:longint;
    a:array[0..5,0..4] of longint;
    num:array[1..10] of longint;
//Nhap
Procedure Nhap;
Var f:Text;
    i:longint;
    c:char;
Begin
    assign(f,finp); reset(f);
    readln(f,n);
    for i:=1 to n do
        begin
            read(f,c);
            num[i]:=ord(c)-48;
            if num[i]=0 then
                num[i]:=11;
        end;
    close(f);
End;
Procedure Init;
Var i,j:longint;
Begin
    for i:=0 to 5 do
        for j:=0 to 4 do
            a[i,j]:=-1;
    a[1,1]:=1; a[1,2]:=2; a[1,3]:=3;
    a[2,1]:=4; a[2,2]:=5; a[2,3]:=6;
    a[3,1]:=7; a[3,2]:=8; a[3,3]:=9;
    a[4,2]:=11;
End;
Function Left:boolean;
Var i,x,y,m,j,t:longint;
Begin
    for i:=1 to n do
        begin
            for j:=1 to 4 do
                for t:=1 to 3 do
                    if a[j,t]=num[i] then
                        begin
                            x:=j; y:=t;
                            break;
                        end;
            m:=a[x,y-1];
            if m<0 then
                exit(false);
        end;
    exit(true);
End;
Function Right:boolean;
Var i,x,y,m,j,t:longint;
Begin
    for i:=1 to n do
        begin
            for j:=1 to 4 do
                for t:=1 to 3 do
                    if a[j,t]=num[i] then
                        begin
                            x:=j; y:=t;
                            break;
                        end;
            m:=a[x,y+1];
            if m<0 then
                exit(false);
        end;
    exit(true);
End;
Function Up:boolean;
Var i,x,y,m,j,t:longint;
Begin
    for i:=1 to n do
        begin
            for j:=1 to 4 do
                for t:=1 to 3 do
                    if a[j,t]=num[i] then
                        begin
                            x:=j; y:=t;
                            break;
                        end;
            m:=a[x-1,y];
            if m<0 then
                exit(false);
        end;
    exit(true);
End;
Function Down:boolean;
Var i,x,y,m,j,t:longint;
Begin
    for i:=1 to n do
        begin
            for j:=1 to 4 do
                for t:=1 to 3 do
                    if a[j,t]=num[i] then
                        begin
                            x:=j; y:=t;
                            break;
                        end;
            m:=a[x+1,y];
            if m<0 then
                exit(false);
        end;
    exit(true);
End;
Function Solve:longint;
Begin
    if (left=true) or (right=true) or (up=true) or (down=true)  then
        exit(2);
    exit(1);
End;
Procedure Xuat;
Var f:Text;
    k:longint;
Begin
    assign(f,fout); rewrite(f);
    k:=solve;
    write(f,res[k]);
    close(f);
End;

Begin
    nhap;
    init;
    xuat;
End.

var kt:boolean;
s:ansistring;
        x,y,i,n,j,xx,yy,k:longint;
        a:array[-10..10,-10..10]of char;
                l,r:array[0..100000] of longint;
function th1(x,y:longint):boolean;
var i:longint;
begin
        for i:=2 to n do
        begin
                x:=x+l[i];
                y:=y+r[i];
                if a[x,y]='?' then exit(false);
        end;
        exit(true);
end;
begin
        readln(n);
        kt:=false;
        readln(s);
        for i:=-10 to  10 do
                for j:=-10  to 10 do a[i,j]:='?';
        a[1,1]:='1';
        a[1,2]:='2';
        a[1,3]:='3';
        a[2,1]:='4';
        a[2,2]:='5';
        a[2,3]:='6';
        a[3,1]:='7';
        a[3,2]:='8';
        a[3,3]:='9';
        a[4,2]:='0';
        xx:=0;
        yy:=0;
        for i:=1 to n do
        begin
                if s[i]='0' then
                begin
                        x:=4;
                        y:=2;
                end else
                begin
                        k:=ord(s[i])-ord('0');
                        if k mod  3 =0 then x:=k div 3 else x:=k div 3+1;
                        if k mod  3 =0 then y:=3 else y:=k mod 3;
                       // writeln(x,y);
                end;
                l[i]:=x-xx;
                r[i]:=y-yy;
               // writeln(l[i],' ',r[i]);
                xx:=x;
                yy:=y;
        end;
        for i:=1 to 3 do
                for j:=1 to 3 do
                        if a[i,j]<>s[1] then
                begin
                        if th1(i,j) then kt:=true;
                end;

        if s[1]<>'0' then if th1(4,2) then kt:=true;
        if not kt then write('YES') else write('NO');
end.

const
   tfi='';
   tfo='';

type info= record
   x, y: longint; end;

var
   fi, fo: text;
   n: longint;
   a: array[0..4,0..4] of longint;
   x: array[0..100] of longint;
   pos: array[0..100] of info;

procedure Init;
var
   i, j, w: longint;
begin
   w := 0;
   for i:=1 to 3 do
      for j:=1 to 3 do
         begin
            inc(w);
            a[i, j] := w;
            pos[w].x :=i; pos[w].y := j;
         end;
   a[4, 1] := -1; a[4, 3] := -1;
   a[4, 2] := 0; pos[0].x := 4; pos[0].y := 2;
end;

procedure __;
var
   i: longint;
   c: char;
begin
   assign(fi, tfi); reset(fi);
   assign(fo, tfo); rewrite(fo);
   readln(fi, n);
   for i:=1 to n do
      begin
         read(fi, c);
         x[i] := ord(c)-48;
      end;
end;

function check(u, v, k1, k2: longint): boolean;
var
   x, y: longint;
begin
   x := u+k1;
   y := v+k2;
   if (x<1) or (y<1)  or (y>3) or (x>4) then exit(false);
   if a[x, y]=-1 then exit(false);
   exit(true);
end;

procedure xuly;
var
   i, j, k, k1, k2: longint;
   ok: boolean;
begin
   if n=1 then
      begin
         writeln(fo,'NO'); exit;
      end;

   for i:=1 to 4 do
      for j:=1 to 3 do
         if ((i<>pos[x[1]].x) or (j<>pos[x[1]].y)) and (a[i, j]<>-1) then
            begin
               ok := true;
               for k:=2 to n do
                  begin
                     k1 := pos[x[k]].x-pos[x[1]].x;
                     k2 := pos[x[k]].y-pos[x[1]].y;
                     if not check(i, j, k1, k2) then
                        begin
                           ok := false; break;
                        end;
                  end;
               if ok then
                  begin
                     writeln(fo,'NO'); exit;
                  end;
            end;
   writeln(fo,'YES');
end;

procedure _;
begin
   close(fi); close(fo);
end;

BEGIN
   Init;
   __;
   xuly;
   _;
END.

Const Finp='';
      Fout='';
      ans:array[1..2] of string=('YES','NO');
Var n:Integer;
    a:array[0..5,0..4] of Integer;
    number:array[1..10] of Integer;

Procedure Input;
Var f:Text;
    i:Integer;
    c:char;
Begin
    Assign(f,finp); Reset(f);
    readln(f,n);
    for i:=1 to n do
        begin
            read(f,c);
            number[i]:=ord(c)-48;
            If number[i]=0 then
                number[i]:=11;
        end;
    close(f);
End;
Procedure Init;
Var i,j:Integer;
Begin
    for i:=0 to 5 do
        for j:=0 to 4 do
            a[i,j]:=-1;
    a[1,1]:=1; a[1,2]:=2; a[1,3]:=3;
    a[2,1]:=4; a[2,2]:=5; a[2,3]:=6;
    a[3,1]:=7; a[3,2]:=8; a[3,3]:=9;
    a[4,2]:=11;
End;
Function Left:boolean;
Var i,x,y,m,j,t:Integer;
Begin
    for i:=1 to n do
        begin
            for j:=1 to 4 do
                for t:=1 to 3 do
                    If a[j,t]=number[i] then
                        begin
                            x:=j; y:=t;
                            break;
                        end;
            m:=a[x,y-1];
            If m<0 then
                Exit(false);
        end;
    Exit(true);
End;
Function Right:boolean;
Var i,x,y,m,j,t:Integer;
Begin
    for i:=1 to n do
        begin
            for j:=1 to 4 do
                for t:=1 to 3 do
                    If a[j,t]=number[i] then
                        begin
                            x:=j; y:=t;
                            break;
                        end;
            m:=a[x,y+1];
            If m<0 then
                Exit(false);
        end;
    Exit(true);
End;
Function Up:boolean;
Var i,x,y,m,j,t:Integer;
Begin
    for i:=1 to n do
        begin
            for j:=1 to 4 do
                for t:=1 to 3 do
                    If a[j,t]=number[i] then
                        begin
                            x:=j; y:=t;
                            break;
                        end;
            m:=a[x-1,y];
            If m<0 then
                Exit(false);
        end;
    Exit(true);
End;
Function Down:boolean;
Var i,x,y,m,j,t:Integer;
Begin
    for i:=1 to n do
        begin
            for j:=1 to 4 do
                for t:=1 to 3 do
                    If a[j,t]=number[i] then
                        begin
                            x:=j; y:=t;
                            break;
                        end;
            m:=a[x+1,y];
            If m<0 then
                Exit(false);
        end;
    Exit(true);
End;
Function Solve:Integer;
Begin
    If (left=true) or (right=true) or (up=true) or (down=true)  then
        Exit(2);
    Exit(1);
End;
Procedure Output;
Var f:Text;
    k:Integer;
Begin
    Assign(f,fout); rewrite(f);
    k:=solve;
    write(f,ans[k]);
    close(f);
End;

Begin
    Input;
    init;
    Output;
End.

{$MODE OBJFPC}
program dream_hyojoo;
uses sysutils;
var
    xx,n,i,j:integer;
    s:char;
    a,movex,movey:array[0..10] of integer;
    st:boolean;

function hang(i:integer):integer;
begin
    if i=0 then exit(4) else
    if i mod 3=0 then exit(i div 3) else exit(i div 3+1)
end;

function cot(i:integer):integer;
begin
    if i=0 then exit(2) else
    if i mod 3=0 then exit(3) else exit(i mod 3)
end;

function solve(i,j,k:integer):integer;
var x,y:integer;
begin
    y:=cot(i);
    x:=hang(i);
    x:=x+j;
    y:=y+k;
    if (x>4) or (x<1) or (y<1) or (y>3) then
       begin
        st:=true;
        exit
       end;
    if x=4 then
       if y=2 then exit(0) else
          begin
            st:=true;
            exit
          end;
    exit((x-1)*3+y)
end;

begin
    //assign(input,'dream_hyojoo.inp');
    //reset(input);
    readln(n);
    for i:=1 to n do
        begin
            read(s);
            a[i]:=strtoint(s);
            movey[i]:=cot(a[i])-cot(a[i-1]);
            movex[i]:=hang(a[i])-hang(a[i-1])
        end;
    for i:=0 to 9 do
    if i<>a[1] then
        begin
             xx:=i;
             st:=false;
             for j:=2 to n do
                 begin

                     xx:=solve(xx,movex[j],movey[j]);
                     if st then break
                 end;
             if not st then
                begin
                 writeln('NO');
                 halt
                end;
        end;
    writeln('YES')
end.

var
 j1,ij,w,y,i1,f,k,q,r,h,i,j:longint;
 a:array[0..5,0..5]of integer;
 s:string;
begin
 //assign (input,'cinema.in');reset(input);
 //assign(output,'cinema.out');rewrite(output);
  readln(w);
  readln(s);
  for i:=1 to w do
  begin
   val(s[i],y);
   r:=(2+y) div 3;
   if r=0 then r:=4;
   h:=y mod 3 ;
   if h=0 then h:=3;
   if y=0 then h:=2;
   a[r,h]:=1;
  end;
  for i:=0 to 4 do a[0,i]:=2;
  for i:=0 to 4 do a[i,0]:=2;
  for i:=0 to 4 do a[i,4]:=2;
  for i:=0 to 4 do a[5,i]:=2;
  a[4,1]:=2;
  a[4,3]:=2;
   f:=0;

  for i:=0 to 5 do for j:=0 to 5 do if f=0 then if a[i,j]=1 then if a[i-1,j]=2 then f:=1;
  if f=0 then begin writeln('NO'); halt; end;
  f:=0;
  for i:=1 to 4 do for j:=1 to 3 do if f=0 then if a[i,j]=1 then if a[i+1,j]=2 then f:=1;
  if f=0 then begin writeln('NO'); halt; end;
   f:=0;
  for i:=1 to 4 do for j:=1 to 3 do if f=0 then if a[i,j]=1 then if a[i,j-1]=2 then f:=1;
  if f=0 then begin writeln('NO'); halt; end;
  f:=0;
  for i:=1 to 4 do for j:=1 to 3 do if f=0 then if a[i,j]=1 then if a[i,j+1]=2 then f:=1;
  if f=0 then begin writeln('NO'); halt; end;

  writeln('YES');
end.

const fi = '';

var  s: string;
     n, i: longint;
     res, co0, co: boolean;
     f: text;

begin
     assign(f, fi); reset(f);
     readln(f, n);
     readln(f, s);
     close(f);

     for i:= 1 to n do if s[i] = '0' then begin co0:= true; break; end;
     res:= false;
     if co0 then
        begin
           for i:= 1 to n do
              if ('1' <= s[i]) and (s[i] <= '3') then res:= true;
        end
     else
        begin
           res:= true; co:= false;
           for i:= 1 to n do
              if ('1' <= s[i]) and (s[i] <= '3') then co:= true;
           res:= res and co;
           co:= false;
           for i:= 1 to n do
              if ('7' <= s[i]) and (s[i] <= '9') then co:= true;
           res:= res and co;
           co:= false;
           for i:= 1 to n do
              if (s[i] = '1') or (s[i] = '4') or (s[i] = '7') then co:= true;
           res:= res and co;
           co:= false;
           for i:= 1 to n do
              if (s[i] = '3') or (s[i] = '6') or (s[i] = '9') then co:= true;
           res:= res and co;
           co:= false;
           for i:= 1 to n do
              if (s[i] = '7') or (s[i] = '9') then co:= true;
           if not(co) then res:= false;
        end;
     if res then writeln('YES') else writeln('NO');
     readln;
end.

program O_O;
 var
  i,j,k,n,m:longint;
  s:string;
  pd:array[1..4] of boolean;
  b:array[0..10] of boolean;
begin
  readln(n);
  readln(s);
  for i:=1 to n do
   b[ord(s[i])-48]:=true;
  for i:=0 to 9 do
   if b[i] then
    begin
     if (i=1)or(i=2)or(i=3) then
      pd[1]:=true;
     if (i=3)or(i=6)or(i=9)or(i=0) then
      pd[2]:=true;
     if (i=1)or(i=4)or(i=7)or(i=0) then
      pd[3]:=true;
     if (i=7)or(i=0)or(i=9) then
      pd[4]:=true;
    end;
  if (pd[1])and(pd[2])and(pd[3])and(pd[4]) then
   writeln('YES')
  else
   writeln('NO');
  readln;
end.

const   fi      ='';
        fo      ='';

var     n,i,j,k,x,y     :longint;
        ch      :char;
        ok,ok1  :boolean;
        a       :array[0..10] of longint;
        b       :array[0..9,1..2] of longint=((3,1),(0,0),(0,1),(0,2),(1,0),(1,1),(1,2),(2,0),(2,1),(2,2));

begin
        assign(input,fi);       reset(input);
        readln(n);
        for i:=1 to n do
        begin
                read(ch);
                a[i]:=ord(ch)-48;
        end;
        for i:=0 to 9 do
                if i<>a[1] then
                begin
                        ok:=true;
                        x:=b[i,1];
                        y:=b[i,2];
                        for j:=1 to n-1 do
                        begin
                                x:=x-(b[a[j],1]-b[a[j+1],1]);
                                y:=y-(b[a[j],2]-b[a[j+1],2]);
                                ok1:=false;
                                for k:=0 to 9 do
                                        if (x=b[k,1]) and (y=b[k,2]) then ok1:=true;
                                if not ok1 then ok:=false;
                        end;
                        if ok then
                        begin
                                write('NO');
                                halt;
                        end;
                end;
        write('YES');
end.

const
 xx:array[0..9]of longint=(4,1,1,1,2,2,2,3,3,3);
 yy:array[0..9]of longint=(2,1,2,3,1,2,3,1,2,3);

procedure ans(x:string);
begin
 writeln(x);
 halt;
end;

var
 x,y,a:array[1..10]of longint;
 f,f2:boolean;
 n,i,j,l,px,py:longint;
 c:char;

begin
 readln(n);
 for i:=1 to n do
 begin
  read(c);
  a[i]:=ord(c)-48;
 end;
 for i:=1 to n-1 do
 begin
  x[i]:=xx[a[i+1]]-xx[a[i]];
  y[i]:=yy[a[i+1]]-yy[a[i]];
 end;
 for i:=0 to 9 do if i<>a[1] then
 begin
  px:=xx[i];py:=yy[i];f2:=true;
  for j:=1 to n-1 do
  begin
   inc(px,x[j]);
   inc(py,y[j]);
   f:=false;
   for l:=0 to 9 do if (px=xx[l])and(py=yy[l]) then f:=true;
   if not f then
   begin
    f2:=false;
    break;
   end;
  end;
  if f2 then ans('NO');
 end;
 ans('YES');
end.
end.

var
   n,i,minb,minc,maxb,maxc,q,k,j,curi,curj,count:longint;
     a,b,c,x,y:array[1..1000] of longint;
     s,sd:string;
  begin
    readln(n);
       readln(s);
         for i:=1 to n do begin
          sd:=copy(s,i,1);
          val(sd,a[i],q);
          end;
        for i:=1 to n do begin
          if a[i]=1 then begin b[i]:=1; c[i]:=1; end;
          if a[i]=2 then begin b[i]:=1; c[i]:=2; end;
          if a[i]=3 then begin b[i]:=1; c[i]:=3; end;
          if a[i]=4 then begin b[i]:=2; c[i]:=1; end;
          if a[i]=5 then begin b[i]:=2; c[i]:=2; end;
          if a[i]=6 then begin b[i]:=2; c[i]:=3; end;
          if a[i]=7 then begin b[i]:=3; c[i]:=1; end;
          if a[i]=8 then begin b[i]:=3; c[i]:=2; end;
          if a[i]=9 then begin b[i]:=3; c[i]:=3; end;
          if a[i]=0 then begin b[i]:=4; c[i]:=2; end;
            end;
          for i:=1 to n-1 do x[i]:=b[i+1]-b[i];
            for i:=1 to n-1 do y[i]:=c[i+1]-c[i];
               count:=0;

               curi:=4;
                  curj:=2;
                    q:=0;

                  for k:=1 to n-1 do begin
                    if ((curi+x[k]=4) and (curi+x[k]=4))
                    and
                    ((curj+y[k]=2)  and (curj+y[k]=2))
                      then begin inc(q); curi:=4; curj:=2; continue; end;

                if ((curi+x[k]>=1) and (curi+x[k]<=3))
                    and
                    ((curj+y[k]>=1)  and (curj+y[k]<=3))
                      then begin inc(q); curi:=curi+x[k]; curj:=curj+y[k]; end;

                end;
                  if q=n-1 then inc(count);

              for i:=1 to 3 do begin
                for j:=1 to 3 do begin
                  curi:=i;
                  curj:=j;
                    q:=0;

                  for k:=1 to n-1 do begin
                    if ((curi+x[k]=4) and (curi+x[k]=4))
                    and
                    ((curj+y[k]=2)  and (curj+y[k]=2))
                      then begin inc(q); curi:=4; curj:=2; continue; end;

                if ((curi+x[k]>=1) and (curi+x[k]<=3))
                    and
                    ((curj+y[k]>=1)  and (curj+y[k]<=3))
                      then begin inc(q); curi:=curi+x[k]; curj:=curj+y[k]; end;

                end;
                  if q=n-1 then inc(count);
                end;
                end;

                 if count>1 then
                write('NO')
                  else write('YES');

        end.

{$MODE OBJFPC}
const
  ip = '';//'689A.inp';
  op = '';//'689A.out';

var
  n : integer;
  s : ansistring;
  fi, fo : text;

procedure enter;
begin
  readln(fi, n);
  readln(fi, s);
end;

procedure process;
begin
  if (pos('1', s) > 0) and (pos('9', s) > 0) then writeln(fo, 'YES')
  else if (pos('3', s) > 0) and (pos('7', s) > 0) then writeln(fo, 'YES')
  else if (pos('4', s) > 0) and (pos('3', s) > 0) and (pos('9', s) > 0) then writeln(fo, 'YES')
  else if (pos('1', s) > 0) and (pos('6', s) > 0) and (pos('7', s) > 0) then writeln(fo, 'YES')
  else if (pos('2', s) > 0) and (pos('7', s) > 0) and (pos('9', s) > 0) then writeln(fo, 'YES')
  else if (pos('2', s) > 0) and (pos('4', s) > 0) and (pos('9', s) > 0) then writeln(fo, 'YES')
  else if (pos('2', s) > 0) and (pos('7', s) > 0) and (pos('6', s) > 0) then writeln(fo, 'YES')
  else if (pos('2', s) > 0) and (pos('0', s) > 0) then writeln(fo, 'YES')
  else if (pos('1', s) > 0) and (pos('0', s) > 0) then writeln(fo, 'YES')
  else if (pos('3', s) > 0) and (pos('0', s) > 0) then writeln(fo, 'YES')
  else writeln(fo, 'NO');
end;

begin
  assign(fi, ip); reset(fi);
  assign(fo, op); rewrite(fo);

  enter;
  process;

  close(fi); close(fo);
end.

var n, i:longint;
    str: ansistring;

function Left(n: longint): boolean;
begin
  for i := 1 to n do if ((str[i] = '1') or ((str[i] = '4') or ((str[i] = '7') or (str[i] = '0')))) then exit(false);
  exit(true);
end;
function Right(n: longint): boolean;
begin
  for i := 1 to n do if ((str[i] = '3') or ((str[i] = '6') or ((str[i] = '9') or (str[i] = '0')))) then exit(false);
  exit(true);
end;
function Up(n: longint): boolean;
begin
  for i := 1 to n do if ((str[i] = '1') or ((str[i] = '2') or ((str[i] = '3')))) then exit(false);
  exit(true);
end;
function Down(n: longint): boolean;
begin
  for i := 1 to n do if ((str[i] = '7') or ((str[i] = '0') or ((str[i] = '9')))) then exit(false);
  exit(true);
end;
begin
  readln(n);
  read(str);
  if (Left(n) or (Right(n) or (Up(n) or Down(n)))) then write('NO') else write('YES');
end.

{$mode objfpc}
program  fafa;
const
     inp  = '';
     outp = '';
var
     fi, fo : text;
     F : array[0..9] of boolean;
     n : integer;
     ok : boolean;

procedure Enter;
var  i, p : integer;
     c : char;
begin
     readln(fi, n);
     Fillchar(F,sizeof(F),false);
     for i:= 1 to n do
        begin
             read(fi, c);
             val(c,p);
             F[p]  := true;
        end;

     //for i := 0 to 9 do if F[i] then write(fo, i,' ');
     ok := false;
     if F[0] then
         begin
              if F[1] or F[2] or F[3] then writeln(fo, 'YES')
              else writeln(fo, 'NO');
         end
     else
         begin
              if (not F[1]) and (not F[2]) and (not F[3]) then
                  begin
                       writeln(fo, 'NO');
                       exit;
                  end;
              if (not F[1]) and (not F[4]) and (not F[7]) then
                  begin
                       writeln(fo, 'NO');
                       exit;
                  end;
              if (not F[3]) and (not F[6]) and (not F[9]) then
                  begin
                       writeln(fo, 'NO');
                       exit;
                  end;
              if (not F[7]) and (not F[8]) and (not F[9]) then
                  begin
                       writeln(fo, 'NO');
                       exit;
                  end;
              if (F[8]) and (not F[7]) and (not F[9]) then
                  begin
                       writeln(fo, 'NO');
                       exit;
                  end;
              writeln(fo, 'YES');
         end;
end;

begin
  Assign(fi, inp);   reset(fi);
  Assign(fo, outp); rewrite(fo);
       Enter;
  Close(fi); CLose(fo);
end.

const maxn=100;
var n:longint;
    x,y,o,p:array[0..maxn] of longint;
    kt:array[0..maxn,0..maxn] of boolean;

procedure mo;
	begin
		assign(input,'a.INP');
		reset(input);
		assign(output,'a.OUT');
		rewrite(output);
	end;

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

procedure doc;
    var
        i,w:longint;
        q:char;
	begin
	    readln(n);
        for i:=1 to n do
        begin
            read(q);
           val(q,w);
           if w=0 then
           begin
               x[i]:=4;
               y[i]:=2;
           end
           else
           begin
               x[i]:=w div 3;
               inc(x[i]);
               y[i]:=w mod 3;
               if y[i]=0 then
               begin
                   y[i]:=3;
                   dec(x[i]);
               end;
           end;
        end;
	end;

procedure xuli;
    var
        i,j,q,w:longint;
        kt1:boolean;
	begin
        o[1]:=-1;
        o[2]:=0;
        o[3]:=1;
        o[4]:=0;
        p[1]:=0;
        p[2]:=1;
        p[3]:=0;
        p[4]:=-1;
        for i:=1 to 3 do
            for j:=1 to 3 do
                kt[i,j]:=true;
        kt[4,2]:=true;
        for i:=1 to 4 do
        begin
            kt1:=true;
            for j:=1 to n do
            begin
                q:=x[j]+o[i];
                w:=y[j]+p[i];
                if kt[q,w]=false then
                begin
                    kt1:=false;
                    break;
                end;
            end;
            if kt1=true then
            begin
                writeln('NO');
                exit;
            end;
        end;
        writeln('YES');
	end;

procedure xuat;
	begin

	end;

begin
	//mo;
	doc;
	xuli;
	xuat;
	//dong;
end.

program cf689A;
var board:array[0..5,0..5] of longint;
    flag,can:array[0..5,0..5] of boolean;
    ch:char;
    poss,ans:boolean;
    i,j,di,dj,n,tmp,x,y:longint;
begin
  readln(n);
  for i:=1 to 3 do board[1,i]:=i;
  for i:=4 to 6 do board[2,i-3]:=i;
  for i:=7 to 9 do board[3,i-6]:=i;
  board[4,2]:=10;
  for i:=1 to 4 do
    for j:=1 to 4 do
      if board[i,j]>0 then can[i,j]:=true
        else can[i,j]:=false;
  fillchar(flag,sizeof(flag),0);
  for i:=1 to n do
    begin
      read(ch);
      if ch='0' then tmp:=10 else tmp:=ord(ch)-48;
      for x:=1 to 4 do
        for y:=1 to 4 do
          if board[x,y]=tmp then flag[x,y]:=true;
    end;
  ans:=false;
  for di:=-1 to 1 do
    for dj:=-1 to 1 do
      if (di<>0)or(dj<>0) then
        begin
          poss:=true;
          for i:=1 to 4 do
            for j:=1 to 4 do
              if flag[i,j] then
                if not can[i+di,j+dj] then poss:=false;
          ans:=ans or poss;
        end;
  if ans then writeln('NO') else writeln('YES');
end.

const
   fin='mac.inp';fon='mac.out';
var t,i,n,d1,d2,d3,d4:longint; s:string; kt:boolean;
   a:array[1..10] of longint;

procedure solve;
begin
readln(n); read(s);
for i:=1 to n do
   a[i]:=ord(s[i])-48;
d1:=0; d2:=0; d3:=0; d4:=0;
for i:=1 to n do
   begin
   if (a[i]+3=11) or ((a[i]+3<=9) and (a[i]<>0)) then
      begin
      inc(d1);
      end;
   end;
for i:=1 to n do
   begin
   if (a[i]-3=-3) or (a[i]-3>=1) then
      begin
      inc(d2);
      end;
   end;
for i:=1 to n do
   begin
   if (a[i]+1<=9) and (a[i]<>3) and (a[i]<>6) and (a[i]<>0) then
      begin
      inc(d3);
      end;
   end;
for i:=1 to n do
   begin
   if (a[i]-1>=1) and (a[i]<>4) and (a[i]<>7) and (a[i]<>0) then
      begin
      inc(d4);
      end;
   end;
kt:=true;
if (d1=n) or (d2=n) or (d3=n) or (d4=n) then
   kt:=false;
if kt=false then
   write('NO')
else
   write('YES');
end;

begin
//assign(input,fin);reset(input);
//assign(output,fon);rewrite(output);
solve;
end.

var
s:array[0..4] of string;
ss:string;
i,j,k,n,ans:integer;
flag:boolean;
begin
s[0]:='1234567890';
s[1]:='---1234568';
s[2]:='456789-0--';
s[3]:='-12-45-78-';
s[4]:='23-56-89--';
 readln(n);
 readln(ss);
 ans:=0;
        for j:=1 to 4 do
        begin
        flag:=false;
                for i:=1 to n do
                begin
                        for k:=1 to 10 do
                        if (s[0][k]=ss[i]) and (s[j][k]='-')
                        then flag:=true;
                end;
        if not flag then
                begin
                writeln('NO');
                halt(0);
                end;
        end;
writeln('YES');

end.

Program ioh;
Type gan=record
     x,y:longint;
     end;
Var n,i,j,k:longint;

    a,road:array[0..10] of gan;
    s:array[1..10] of longint;
    b:array[-5..15,-5..15] of longint;
    x,y:longint;
    res:boolean;
    ch:char;
Begin
  Readln(n);
  for i:=1 to n do begin
    Read(ch);
    s[i]:=ord(ch)-48;
  End;
  a[0].x:=2;
  a[0].y:=1;
  a[1].x:=1;
  a[1].y:=4;
  a[2].x:=2;
  a[2].y:=4;
  a[3].x:=3;
  a[3].y:=4;
  a[4].x:=1;
  a[4].y:=3;
  a[5].x:=2;
  a[5].y:=3;
  a[6].x:=3;
  a[6].y:=3;
  a[7].x:=1;
  a[7].y:=2;
  a[8].x:=2;
  a[8].y:=2;
  a[9].x:=3;
  a[9].y:=2;

  for i:=2 to n do begin
    road[i].x:=a[s[i]].x-a[s[i-1]].x;
    road[i].y:=a[s[i]].y-a[s[i-1]].y;
    //Writeln(road[i].x,road[i].y);
  End;
  for i:=-5 to 15 do
    for j:=-5 to 15 do b[i,j]:=-1;
  k:=1;
  for i:=4 downto 2 do begin

    for j:=1 to 3 do begin
      b[i,j]:=k;
      inc(k);

    end;

  End;
  b[1,2]:=0;
  For i:=4 downto 1 do begin
    for j:=1 to 3 do begin
      y:=i;
      x:=j;
         res:=true;
         if b[y,x]<>s[1] then begin
         if b[y,x]=-1 then begin
            res:=false;
          end;
        for k:=2 to n do begin
          //Writeln(x,y,' ',i,j);
          if b[y,x]=-1 then begin
            res:=false;
            Break;
          end;
          inc(x,road[k].x);
          inc(y,road[k].y);
        End;
        if b[y,x]=-1 then begin
            res:=false;
        end;
        if res=true then begin
          Writeln('NO');
          //Writeln(j,' ',i);
          Halt;
        End;
        end;
    End;
  End;

  Writeln('YES')
End.

Var
s:string;
n,l,d,r,u,z,i,f:longint;
begin
 readln(n);
 readln(s);
 for i:=1 to length(s) do
  begin
   if s[i]='0' then z:=1;
   if (s[i]='1') or (s[i]='2') or (s[i]='3') then u:=1;
   if (s[i]='3') or (s[i]='6') or (s[i]='9') then r:=1;
   if (s[i]='7') or (s[i]='8') or (s[i]='9') then d:=1;
   if (s[i]='1') or (s[i]='4') or (s[i]='7') then l:=1;
   if (s[i]='7') or (s[i]='9') then
    f:=1;
  end;
if (((u=1) and (r=1) and (d=1) and (l=1)) and (f=1)) or ((z=1) and (u=1)) then
 write('YES')
else
 write('NO');
end.

Const Finp='';
      Fout='';
      res:array[1..2] of string=('YES','NO');
Var n:longint;
    a:array[0..5,0..4] of longint;
    num:array[1..10] of longint;

Procedure Nhap;
Var f:Text;
    i:longint;
    c:char;
Begin
    assign(f,finp); reset(f);
    readln(f,n);
    for i:=1 to n do
        begin
            read(f,c);
            num[i]:=ord(c)-48;
            if num[i]=0 then
                num[i]:=11;
        end;
    close(f);
End;
Procedure Init;
Var i,j:longint;
Begin
    for i:=0 to 5 do
        for j:=0 to 4 do
            a[i,j]:=-1;
    a[1,1]:=1; a[1,2]:=2; a[1,3]:=3;
    a[2,1]:=4; a[2,2]:=5; a[2,3]:=6;
    a[3,1]:=7; a[3,2]:=8; a[3,3]:=9;
    a[4,2]:=11;
End;
Function Left:boolean;
Var i,x,y,m,j,t:longint;
Begin
    for i:=1 to n do
        begin
            for j:=1 to 4 do
                for t:=1 to 3 do
                    if a[j,t]=num[i] then
                        begin
                            x:=j; y:=t;
                            break;
                        end;
            m:=a[x,y-1];
            if m<0 then
                exit(false);
        end;
    exit(true);
End;
Function Right:boolean;
Var i,x,y,m,j,t:longint;
Begin
    for i:=1 to n do
        begin
            for j:=1 to 4 do
                for t:=1 to 3 do
                    if a[j,t]=num[i] then
                        begin
                            x:=j; y:=t;
                            break;
                        end;
            m:=a[x,y+1];
            if m<0 then
                exit(false);
        end;
    exit(true);
End;
Function Up:boolean;
Var i,x,y,m,j,t:longint;
Begin
    for i:=1 to n do
        begin
            for j:=1 to 4 do
                for t:=1 to 3 do
                    if a[j,t]=num[i] then
                        begin
                            x:=j; y:=t;
                            break;
                        end;
            m:=a[x-1,y];
            if m<0 then
                exit(false);
        end;
    exit(true);
End;
Function Down:boolean;
Var i,x,y,m,j,t:longint;
Begin
    for i:=1 to n do
        begin
            for j:=1 to 4 do
                for t:=1 to 3 do
                    if a[j,t]=num[i] then
                        begin
                            x:=j; y:=t;
                            break;
                        end;
            m:=a[x+1,y];
            if m<0 then
                exit(false);
        end;
    exit(true);
End;
Function Solve:longint;
Begin
    if (left=true) or (right=true) or (up=true) or (down=true)  then
        exit(2);
    exit(1);
End;
Procedure Xuat;
Var f:Text;
    k:longint;
Begin
    assign(f,fout); rewrite(f);
    k:=solve;
    write(f,res[k]);
    close(f);
End;

Begin
    nhap;
    init;
    xuat;
End.

uses math;
const
        maxc=1000000000+69;
        modulo=1000000000+7;
        d:array[0..9,1..4] of longint=((1,0,0,0),(0,1,1,0),(0,1,1,1),(0,0,1,1),(1,1,1,0),(1,1,1,1),(1,0,1,1),(1,1,0,0),(1,1,1,1),(1,0,0,1));

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

var
        n:longint;
        s:string;
        a:array[0..10] of longint;

procedure mofile;
begin
        assign(input,'');
        reset(input);
        assign(output,'');
        rewrite(output);
end;

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

procedure xuli;
var
        i,j:longint;
        ok:boolean;
begin
        readln(n);
        readln(s);
        for i:=1 to n do a[i]:=ord(s[i])-ord('0');

        for i:=1 to 4 do
        begin
                ok:=true;
                for j:=1 to n do
                begin
                        if d[a[j],i]=0 then
                        begin
                                ok:=false;
                                break;
                        end;
                end;
                if ok then break;
        end;

        if ok then writeln('NO') else writeln('YES');
end;

begin
        mofile;
        xuli;
        dongfile;
end.

{$Mode objfpc}

var
  n,i,j,o,kq:integer;
  s:char;
  check:boolean;
  a:array[0..10] of boolean;

begin
  readln(n);
  for i:=1 to n do
    begin
      read(s);
      a[ord(s)-48]:=true;
    end;
  if a[1] or a[2] or a[3] then inc(kq);
  if a[1] or a[4] or a[7] then inc(kq);
  if a[3] or a[6] or a[9] then inc(kq);
  if a[7] or a[0] or a[9] then inc(kq);
  if a[0] and (a[1] or a[2] or a[3]) then write('YES')
  else
  if kq < 4 then write('NO')
  else write('YES');
end.

var
  i, j, a, a1, n,f1: integer;
  x: array [1..6, 1..6] of integer;
  y: array [1..10] of integer;
  f:integer;

begin
f1:=0;
  f := 0;
  read(n);
  for i := 1 to 6 do
    for j := 1 to 5  do
      x[i, j] := 0;
  for i := 2 to 4 do
    for j := 2 to 4 do
      x[i, j] := 1;
  x[5,3] := 1;
  read(a1);
  for i := 1 to n  do
  begin
    a := a1 mod 10;
    a1 := a1 div 10;
    if a <4 then y[i]:=20 else if a < 7 then y[i]:= 30 else y[i]:=40;
    if (a=1)or (a=4) or (a=7) then y[i]:=y[i]+2;
    if (a=2)or (a=5) or (a=8)then y[i]:=y[i]+3;
    if (a=3)or (a=6) or (a=9) then y[i]:=y[i]+4;
    if a=0 then y[i]:=53;
    {    x[a div 4 + 2, a mod 4 + 1] := 2;
    y[i] := (a div 4 + 2) * 10 + a mod 4 + 1;}
  end;
  for i:=1 to n do
  x[y[i] div 10 , y[i] mod 10]:=2;
  f:=0;
  for i := 1 to n do
    if x[y[i] div 10 + 1, y[i] mod 10] < 1 then begin f := f+1; break; end else f1:=1;

  {if f then }for i := 1 to n do
      if x[y[i] div 10 - 1, y[i] mod 10] < 1 then begin f := f+1; break; end else f1:=1;

 { if f then} for i := 1 to n do
      if x[y[i] div 10, y[i] mod 10 + 1] < 1 then begin f := f+1; break; end else f1:=1;

  {if f then} for i := 1 to n do
      if x[y[i] div 10, y[i] mod 10 - 1] < 1 then begin f := f+1; break; end else f1:=1;

  {if f then} for i := 1 to n do
      if x[y[i] div 10 + 1, y[i] mod 10 + 1] < 1 then begin f := f+1; break; end else f1:=1;

  {if f then} for i := 1 to n do
      if x[y[i] div 10 + 1, y[i] mod 10 - 1] < 1 then begin f := f+1;  break; end else f1:=1;

  {if f then} for i := 1 to n do
      if x[y[i] div 10 - 1, y[i] mod 10 - 1] < 1 then begin f := f+1; break; end else f1:=1;

  {if f then} for i := 1 to n do
      if x[y[i] div 10 - 1, y[i] mod 10 + 1] < 1 then begin f := f+1; break; end else f1:=1;

  if f< 8 then writeln('NO') else writeln('YES');
  //if f1>0 then writeln ('no') else writeln('yes');
  {for i:=1 to 6 do
  begin
   {for j:=1 to 6 do
   write(x[i,j],' ');
   writeln;
  end;}
end.

{$OPTIMIZATION LEVEL2}
{$INLINE ON}
uses math;
const log=18;
      ms=1e-9;
      oo=round(1e9);
      modulo=1000000007;
      fi='';
      fo='';
      maxn=100010;
      move:array[0..9,1..4]of longint=((8,-1,-1,-1),(-1,2,4,-1),(-1,3,5,1),(-1,-1,6,2),(1,5,7,-1),(2,6,8,4),(3,-1,9,5),(4,8,-1,-1),(5,9,0,7),(6,-1,-1,8));

var f1,f2:text;
    a,b:array[0..10]of longint;
    n:longint;

procedure openfile;
 begin
  assign(f1,fi);
  reset(f1);
  assign(f2,fo);
  rewrite(f2);
 end;

procedure closefile;
 begin
  close(f1);
  close(f2);
 end;

procedure input;
 var i:longint;
     ch:char;
 begin
  readln(f1,n);
  for i:=1 to n do
   begin
    read(f1,ch);
    a[i]:=ord(ch)-ord('0');
   end;
 end;

procedure init;
  var i,j:longint;
      check:boolean;
  begin
   for i:=1 to 4 do
    begin
     check:=true;
     for j:=1 to n do
      b[j]:=move[a[j],i];
     for j:=1 to n do
      if b[j]=-1 then check:=false;
     if check then
      begin
       writeln(f2,'NO');
       closefile;
       halt;
      end;
    end;
  end;

procedure solve;
  var i,j:longint;
  begin
   writeln(f2,'YES');
  end;

procedure output;
  var i:longint;
  begin

  end;

begin
 openfile;
 input;
 init;
 solve;
 output;
 closefile;
end.

var n,i,x:longint;
    a:array[1..9] of longint;
    sl:string; bl:boolean;
begin
 readln(n);
 readln(sl);
 for i:=1 to n do
  begin
   val(sl[i],x);
   a[i]:=x;
  end;
 bl:=false;
 for i:=1 to n do
  if a[i] <> 0 then
   if a[i] - 3 <= 0 then
    begin
     bl:=true;
     break;
    end;
 if bl = false then begin write('NO'); exit; end;
 bl:=false;
 for i:=1 to n do
  if a[i] <> 8 then
   if (a[i] + 3 >= 10) or (a[i] = 0) then
    begin
     bl:=true;
     break;
    end;
 if bl = false then begin write('NO'); exit; end;
 bl:=false;
 for i:=1 to n do
   if (a[i] = 0) or (a[i] = 3) or (a[i] = 6) or (a[i] = 9) then
    begin
     bl:=true;
     break;
    end;
 if bl = false then begin write('NO'); exit; end;
 bl:=false;
 for i:=1 to n do
   if (a[i] = 0) or (a[i] = 1) or (a[i] = 4) or (a[i] = 7) then
    begin
     bl:=true;
     break;
    end;
 if bl = false then begin write('NO'); exit; end;
 write('YES');
end.

const
  d:array[1..4,'0'..'9'] of longint= //wsad
    ((8,-1,-1,-1,1,2,3,4,5,6),
     (-1,4,5,6,7,8,9,-1,0,-1),
     (-1,-1,1,2,-1,4,5,-1,7,8),
     (-1,2,3,-1,5,6,-1,8,9,-1));
var
  st:string;
  len,i,j:longint;
  flag:boolean;
begin
  readln(len);
  readln(st);
  for j:=1 to 4 do
    begin
      flag:=true;
	  for i:=1 to len do
		if d[j][st[i]]=-1 then
		  begin
			flag:=false;
			break;
		  end;
	  if flag then
		begin
		  writeln('NO');
		  halt;
		end;
	end;
  writeln('YES');
end.

type vector = record
                x,y:longint;
              end;
const tmp:Array[0..9,1..2] of longint = ((1,0),(0,3),(1,3),(2,3),(0,2),(1,2),(2,2),(0,1),(1,1),(2,1));
{operator + (a,b:vector) c:vector;
  begin c.x:=a.x+b.x; c.y:=a.y+b.y; end;
operator - (a,b:vector) c:vector;
  begin c.x:=a.x-b.x; c.y:=a.y-b.y; end; }
function plus(a,b:vector):vector;
  begin plus.x:=a.x+b.x; plus.y:=a.y+b.y; end;
function minus(a,b:vector):vector;
  begin minus.x:=a.x-b.x; minus.y:=a.y-b.y; end;
var a:array[0..9] of vector;
    route:array[0..9] of vector;
    flag:boolean;
    ppp:vector;
    num,i,j,n,x,now:longint;
    s:string;
begin
  readln(n);
  for i:=0 to 9 do
    with a[i] do begin
      x:=tmp[i,1]; y:=tmp[i,2];
    end;
  readln(s); val(s[1],x);
  for i:=2 to n do begin
    val(s[i],now); route[i-1]:=minus(a[now],a[x]); x:=now;
  end;
  for i:=0 to 9 do begin
    ppp:=a[i]; flag:=true;
    for j:=1 to n-1 do begin
      ppp:=plus(ppp,route[j]);
      with ppp do begin
        if (x<0) or (x>2) then begin flag:=false; break; end;
        if (y<0) or (y>3) then begin flag:=false; break; end;
        if (x=0) and (y=0) then begin flag:=false; break; end;
        if (x=2) and (y=0) then begin flag:=false; break; end;
      end;
    end;
    if flag then inc(num);
  end;
  if num>1 then writeln('NO') else writeln('YES');
end.

var
a:array[1..109]of longint;
s:string;
n,i,q:longint;
e,b,c,d:boolean;
begin
readln(n);
e:=true;
b:=true;
c:=true;
d:=true;
readln(S);
for i:=1 to n do begin
val(s[i],a[i],q);
if (a[i]<4) and(a[i]<>0)
then e:=false;
if (a[i]=1)or(a[i]=4)or(a[i]=7)or(a[i]=0)
then b:=false;
if(a[i]=3)or(a[i]=6)or(a[i]=9)or(A[i]=0)
then c:=false;
if (a[i]=7)or(a[i]=0)or(a[i]=9)
then d:=false;
end;
if e or b or  c or d
then writeln('NO')
else writeln('YES');
end.

 {$mode objfpc}
        {$coperators on}
uses math;
const
        {$ifdef online_judge}  ifstream=''; ofstream='';
        {$else} ifstream='inp.inp'; ofstream='out.out';
        {$endif}
        x : array[0..9] of integer = (4, 1, 1, 1, 2, 2, 2, 3, 3, 3);
        y : array[0..9] of integer = (2, 1, 2, 3, 1, 2, 3, 1, 2, 3);
var
        n: longint;
        f:array[-100..100, -100..100] of boolean;
        a, b:array[1..100] of record x,y:longint; end;
        s:string;
procedure enter;
var i, j : longint;
        begin
                for i:=0 to 9 do f[x[i],y[i]]:=true;
                readln(n);
                readln(s);
                for i:=1 to length(s) do begin a[i].x:=x[ord(s[i])-48]; a[i].y:=y[ord(s[i])-48]; b[i]:=a[i]; end;
        end;
procedure solve;
var i, j : longint;  ok:boolean;
        begin
                ok:=false;
                for i:=1 to n do
                begin
                        b[i].x:=a[i].x+1;
                        if (not f[b[i].x][b[i].y]) then
                         begin
                                ok:=true;
                                break;
                         end;
                end;
                if not ok then
                 begin
                        writeln('NO');
                        halt;
                 end;
                for i:=1 to length(s) do begin a[i].x:=x[ord(s[i])-48]; a[i].y:=y[ord(s[i])-48]; b[i]:=a[i]; end;
                ok:=false;
                for i:=1 to n do
                begin
                        b[i].x:=a[i].x-1;
                        if (not f[b[i].x][b[i].y]) then
                         begin
                                ok:=true;
                                break;
                         end;
                end;
                if not ok then
                 begin
                        writeln('NO');
                        halt;
                 end;
                for i:=1 to length(s) do begin a[i].x:=x[ord(s[i])-48]; a[i].y:=y[ord(s[i])-48]; b[i]:=a[i]; end;
                ok:=false;
                for i:=1 to n do
                begin
                        b[i].y:=a[i].y+1;
                        if (not f[b[i].x][b[i].y]) then
                         begin
                                ok:=true;
                                break;
                         end;
                end;
                if not ok then
                 begin
                        writeln('NO');
                        halt;
                 end;
                for i:=1 to length(s) do begin a[i].x:=x[ord(s[i])-48]; a[i].y:=y[ord(s[i])-48]; b[i]:=a[i]; end;
                ok:=false;
                for i:=1 to n do
                begin
                        b[i].y:=a[i].y-1;
                        if (not f[b[i].x][b[i].y]) then
                         begin
                                ok:=true;
                                break;
                         end;
                end;
                if not ok then
                 begin
                        writeln('NO');
                        halt;
                 end;
                writeln('YES');
        end;
begin

        assign(input, ifstream); reset(input);
        assign(output, ofstream); rewrite(output);
        enter;
        Solve;
        close(input);
        close(output);
end.

Type small = -1..9;
  rec = Record
    digit,x,y: small;
  End;
  marray = array[1..100] Of rec;

Procedure order(Var mat:marray;k:byte;xi,yi:small);
Begin
  mat[k].x := xi;
  mat[k].y := yi;
End;

Procedure modify(rat:marray;k:byte;mx,my:small; Var cunt:byte);
Begin
  rat[k].x := rat[k].x+mx;
  rat[k].y := rat[k].y+my;
  If (rat[k].x In [1..3]) And (rat[k].y In [1..3]) Then cunt := cunt+1
  Else If (rat[k].x=4) And (rat[k].y=2) Then cunt := cunt+1;
End;

Var n,i,j,valid: byte;
  s: string;
  a: small;
  r: marray;
  validity: boolean;
Begin
  validity := true;
  readln(n);
  readln(s);
  For i:=1 To n Do
    Begin
      a := ord(s[i])-48;
      r[i].digit := a;
      Case a Of
        1: order(r,i,1,1);
        2: order(r,i,1,2);
        3: order(r,i,1,3);
        4: order(r,i,2,1);
        5: order(r,i,2,2);
        6: order(r,i,2,3);
        7: order(r,i,3,1);
        8: order(r,i,3,2);
        9: order(r,i,3,3);
        0: order(r,i,4,2);
      End;
    End;
  For i:=1 To 8 Do
    Begin
      valid := 0;
      Case i Of
        1: For j:=1 To n Do
             modify(r,j,-1,0, valid);
        2: For j:=1 To n Do
             modify(r,j,-1,1,valid);
        3: For j:=1 To n Do
             modify(r,j,0,1, valid);
        4: For j:=1 To n Do
             modify(r,j,1,1, valid);
        5: For j:=1 To n Do
             modify(r,j,1,0, valid);
        6: For j:=1 To n Do
             modify(r,j,1,-1, valid);
        7: For j:=1 To n Do
             modify(r,j,0,-1, valid);
        8: For j:=1 To n Do
             modify(r,j,-1,-1, valid);
      End;

      If valid=n Then
        Begin
          validity := false;
          break;
        End;
    End;
  If validity=true Then writeln('Yes')
  Else writeln('No');
End.

var s:string;
n,i,j,k,l,r,u,d,z,m:longint;
begin
readln(n);
readln(s);
for i:=1 to n do begin
if (s[i]='0') then z:=1;
if (s[i]='1') or (s[i]='4') or (s[i]='7') then l:=1;
if (s[i]='3') or (s[i]='6') or (s[i]='9') then r:=1;
if (s[i]='1') or (s[i]='2') or (s[i]='3') then u:=1;
if (s[i]='7') or (s[i]='9') then d:=1;
end;
if ((l=1) and (r=1) and (u=1) and (d=1)) or ((z=1) and (u=1)) then writeln('YES') else writeln('NO');
end.

var
  a, b, i, k: int64;
  c, c1: char;
  ar: array [0..100] of char;
  arr: array [1..10, 1..10] of int64;
  q, q1, q2, q3: boolean;

begin
  readln(a);
  i := 0;
  while i < a do begin
    read(ar[i]);
    inc(i);
  end;
  i := 0;
  while i < a do begin
    k := ord(ar[i]) - 48;
    if (k < 4) and (k <> 0) then q := true;
    if (k = 1) or (k = 4) or (k = 7) or (k = 0) then q1 := true;
    if (k = 7) or (k = 0) or (k = 9) then q2 := true;
    if (k = 3) or (k = 6) or (k = 9) or (k = 0) then q3 := true;
    inc(i);
  end;
  if (q) and (q1) and (q2) and (q3) then writeln('YES')
    else writeln('NO');
end.

program yan;
  var ar:array[1..9]of char;
      ax:array[0..5,0..5]of char;
      i,j,x,y,b,a,n,m:longint; x1,x2,x3,x4:longint;     c:char;
begin
  for i:=0 to 5 do
    for j:=0 to 5 do ax[i,j]:='a';
  c:='1';
  for i:=1 to 3 do
    for j:=1 to 3 do
      begin
        ax[i,j]:=c; inc(c);
      end;
  ax[4,2]:='0';
  readln(n);
  for i:=1 to n do
    read(ar[i]);
  for i:=1 to n do
    for a:=1 to 4 do
      for b:=1 to 4 do
        begin
          if (ar[i]=ax[a,b]) then
            begin
              if ax[a+1,b]<>'a' then inc(x1);
              if ax[a-1,b]<>'a' then inc(x2);
              if ax[a,b+1]<>'a' then inc(x3);
              if ax[a,b-1]<>'a' then inc(x4);
            end;
        end;
  if (x1=n)or(x2=n)or(x3=n)or(x4=n) then write('NO') else write('YES');
end.

var n, i : integer;
    c : char;
    up, down, left, rigth : boolean;
begin
    readln(n);
    for i := 1 to n do begin
        read(c);
        if c = '0' then begin
            down := true;
            left := true;
            rigth := true;
        end;
        if c = '1' then begin
            up := true;
            left := true;
        end;
        if c = '2' then
            up := true;
        if c = '3' then begin
            rigth := true;
            up := true;
        end;
        if c = '4' then
            left := true;
        if c = '6' then
            rigth := true;
        if c = '7' then begin
            left := true;
            down := true;
        end;
        if c = '9' then begin
            down := true;
            rigth := true;
        end;
    end;
    if up  and down and left and rigth then
        writeln('YES')
    else
        writeln('NO');
end.

var ch:char;
    n,i:longint;
    left,right,up,down,zero:boolean;
begin
readln(n);
for i:=1 to n do
  begin
  read(ch);
  if (ch='1') or (ch='4') or (ch='7') then
    left:=true;
  if (ch='3') or (ch='6') or (ch='9') then
    right:=true;
  if (ch='1') or (ch='2') or (ch='3') then
    up:=true;
  if (ch='7') or (ch='9') then
    down:=true;
  if (ch='0') then
    zero:=true;
  end;
if (zero and up) or (left and right and up and down) then
  writeln('YES')
else
  writeln('NO');
end.

var
  f,fk : array[-50..50,-50..50] of longint;
  x,y : array[0..15] of longint;
  n,i,j,xx,yy,q,a,x1,y1,k,aa : longint;
  c : char;
  ff : boolean;

begin
  readln(n);
  fillchar(f,sizeof(f),62);
  f[1,1]:=1; f[1,2]:=2; f[1,3]:=3;
  f[2,1]:=4; f[2,2]:=5; f[2,3]:=6;
  f[3,1]:=7; f[3,2]:=8; f[3,3]:=9;
  f[4,2]:=0;
  for i:=0 to 5 do for j:=0 to 5 do if f[i,j] in [0..9] then fk[i,j]:=1;
  read(c); a:=ord(c)-48; aa:=a;
  for i:=1 to 4 do for j:=1 to 3 do if f[i,j] = a then begin xx:=i; yy:=j; break; end;
  for q:=2 to n do begin
    read(c);
    a:=ord(c)-48;
    inc(k);
    for i:=1 to 4 do for j:=1 to 3 do if f[i,j] = a then begin x1:=i; y1:=j; break; end;
    x[k]:=x1-xx; y[k]:=y1-yy;
    xx:=x1; yy:=y1;
  end;
  readln;
  for q:=0 to 9 do begin
    if q = aa then continue;
    for i:=1 to 4 do for j:=1 to 3 do if f[i,j] = q then begin xx:=i; yy:=j; break; end;
    ff:=false;
    for i:=1 to k do begin
      x1:=xx+x[i]; y1:=yy+y[i];
      if fk[x1,y1] = 0 then begin ff:=true; break; end;
      xx:=x1; yy:=y1;
    end;
    if not ff then begin writeln('NO'); halt; end;
  end;
  writeln('YES');
end.

var
  ok:boolean;
  i,j,k,c,x,y,d:integer;
  s:string;
  w: char;
begin
 readln(s);
 readln(s);
 c:=0;
 ok:=false;
 x:=0;
 y:=0;
 d:=0;
 for i:=-3 to 3 do
 begin
  for j:=-3 to 2 do
  begin
   ok:=true;
   for k:=1 to length(s) do
   begin
    d:=ord(s[k]);
    if d=48 then
    begin
     x:=1;
     y:=3;
    end else
    begin
     if d <=51 then begin
      x:=d-49;
      y:=0;
     end else
     begin
      if d <=54 then begin
       x:=d-52;
       y:=1;
      end else begin
       x:=d-55;
       y:=2;
      end;
     end;
    end;
    x:=x+j;
    y:=y+i;
    if (not (((x>=0) and (y>=0) and (x <=2) and (y <=2)) or ((x=1) and (y=3)))) then ok :=false;
   end;
   if ok then c:=c+1;
  end;
 end;
 if c =1 then begin s:='YES'; end else s:='NO';
 writeln(s);
end.

program z1;
var a,b,c,d,i,j,k,l,m,n,ans:longint; Z,f1,f2,f3,f4:array[0..5,0..4] of byte;
ch:char;
begin
//assign(input,'d:\input.txt'); reset(input);
//assign(output,'d:\output.txt'); rewrite(output);
readln(n);
for k:=1 to n do
 begin
 read(ch);
 i:=0; j:=0;
 a:=ord(ch)-48;
 if a=0 then begin i:=4; j:=2; end
 else
 begin
 if a mod 3=0 then i:=i-1; i:=i+(a div 3)+1;
 j:=(a mod 3); if j=0 then j:=3;
 end;
 Z[i,j]:=1;
 end;
if Z[4,2]=1 then ans:=ans+1 else
for i:=1 to 3 do
if Z[i,1]=1 then begin ans:=ans+1; break; end;
if Z[4,2]=1 then ans:=ans+1 else
for i:=1 to 3 do
if Z[i,3]=1 then begin ans:=ans+1; break; end;
for j:=1 to 3 do
if Z[1,j]=1 then begin ans:=ans+1; break; end;
if (Z[3,1]=1) or (Z[4,2]=1) or (Z[3,3]=1) then ans:=ans+1;
if ans=4 then write('YES') else write('NO');
end.

var n,u,d,l,r:longint;
    a:ansistring;
begin
  readln(n);
  readln(a);
  for n:=1 to n do
  begin
    if a[n]='0' then begin l:=1;r:=1;d:=1;end;
    if a[n]in['1','2','3'] then u:=1;
    if a[n]in['1','4','7'] then l:=1;
    if a[n]in['3','6','9'] then r:=1;
    if a[n]in['7','9']     then d:=1;
  end;
  if u*l*r*d=1 then writeln('YES') else
  writeln('NO');
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
const
  x:array[1..10] of integer=(0,1,2,0,1,2,0,1,2,1);
  y:array[1..10] of integer=(0,0,0,1,1,1,2,2,2,3);
var
  n,i,j:integer;
  a:array[1..10] of integer;
  pr_x:array[1..9] of integer;
  pr_y:array[1..9] of integer;
   pr_x2:array[1..9] of integer;
  pr_y2:array[1..9] of integer;
  xc,yc:integer;
  dx,dy:integer;
  can:boolean;
  h,v:integer;
  s:string;
begin
  //reset(input,'input.txt');
  //rewrite(output,'output.txt');
  readln(n);
  readln(s);
  fillchar(pr_x,sizeof(pr_x),0);
  fillchar(pr_y,sizeof(pr_x),0);
  fillchar(pr_x2,sizeof(pr_x),0);
  fillchar(pr_y2,sizeof(pr_x),0);
  for i:=1 to n  do
    a[i]:=strtoint(s[i]);
  for i:=1 to n-1 do
  begin
    if a[i+1]=0 then
        h:=10
    else
     h:=a[i+1];
    if a[i]=0 then
        v:=10
    else
     v:=a[i];
    pr_x[i]:=x[h]-x[v];
    pr_y[i]:=y[h]-y[v];
  end;
  for i:=1 to 10 do
  begin
  if(a[1]=0) and (i=10) then
    continue;
   if(a[1]=i) then
    continue;
    xc:=x[i];
    yc:=y[i];
    can:=true;
    for j:=1 to n-1 do
    begin
      xc:=xc+pr_x[j];
      yc:=yc+pr_y[j];
      if (((xc<0) or (xc>2) or (yc>2) or (yc<0) ) and not ((xc=1) and (yc=3))) then
      begin
        can:=false
      end;
    end;
    if can then
    begin
      writeln('NO');
      halt;
    end;
  end;
  writeln('YES');
  //close(input);
  //close(output);
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
const
  x:array[1..10] of integer=(0,1,2,0,1,2,0,1,2,1);
  y:array[1..10] of integer=(0,0,0,1,1,1,2,2,2,3);
var
  n,i,j:integer;
  a:array[1..10] of integer;
  pr_x:array[1..9] of integer;
  pr_y:array[1..9] of integer;
   pr_x2:array[1..9] of integer;
  pr_y2:array[1..9] of integer;
  xc,yc:integer;
  dx,dy:integer;
  can:boolean;
  h,v:integer;
  s:string;
begin
  //reset(input,'input.txt');
  //rewrite(output,'output.txt');
  readln(n);
  readln(s);
  fillchar(pr_x,sizeof(pr_x),0);
  fillchar(pr_y,sizeof(pr_x),0);
  fillchar(pr_x2,sizeof(pr_x),0);
  fillchar(pr_y2,sizeof(pr_x),0);
  for i:=1 to n  do
    a[i]:=strtoint(s[i]);
  for i:=1 to n-1 do
  begin
    if a[i+1]=0 then
        h:=10
    else
     h:=a[i+1];
    if a[i]=0 then
        v:=10
    else
     v:=a[i];
    pr_x[i]:=x[h]-x[a[v]];
    pr_y[i]:=y[a[h]]-y[a[v]];
  end;
  for i:=1 to 10 do
  begin
  if(a[1]=0) and (i=10) then
    continue;
   if(a[1]=i) then
    continue;
    xc:=x[i];
    yc:=y[i];
    can:=true;
    for j:=1 to n-1 do
    begin
      xc:=xc+pr_x[j];
      yc:=yc+pr_y[j];
      if (((xc<0) or (xc>2) or (yc>2) or (yc<0) ) and not ((xc=1) and (yc=3))) then
      begin
        can:=false
      end;
    end;
    if can then
    begin
      writeln('NO');
      halt;
    end;
  end;
  writeln('YES');
  //close(input);
  //close(output);
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
const
  x:array[1..10] of integer=(0,1,2,0,1,2,0,1,2,1);
  y:array[1..10] of integer=(0,0,0,1,1,1,2,2,2,3);
var
  n,i,j:integer;
  a:array[1..10] of integer;
  pr_x:array[1..9] of integer;
  pr_y:array[1..9] of integer;
   pr_x2:array[1..9] of integer;
  pr_y2:array[1..9] of integer;
  xc,yc:integer;
  dx,dy:integer;
  can:boolean;
  s:string;
begin
  //reset(input,'input.txt');
  //rewrite(output,'output.txt');
  readln(n);
  readln(s);
  fillchar(pr_x,sizeof(pr_x),0);
  fillchar(pr_y,sizeof(pr_x),0);
  fillchar(pr_x2,sizeof(pr_x),0);
  fillchar(pr_y2,sizeof(pr_x),0);
  for i:=1 to n  do
    a[i]:=strtoint(s[i]);
  for i:=1 to n-1 do
  begin
    pr_x[i]:=x[a[i+1]]-x[a[i]];
    pr_y[i]:=y[a[i+1]]-y[a[i]];
  end;
  for i:=1 to 10 do
  begin
   if(a[1]=i) then
    continue;
    xc:=x[i];
    yc:=y[i];
    can:=true;
    for j:=1 to n-1 do
    begin
      xc:=xc+pr_x[j];
      yc:=yc+pr_y[j];
      if (((xc<0) or (xc>2) or (yc>2) or (yc<0) ) and not ((xc=1) and (yc=3))) then
      begin
        can:=false
      end;
    end;
    if can then
    begin
      writeln('NO');
      halt;
    end;
  end;
  writeln('YES');
  //close(input);
  //close(output);
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
const
  x:array[1..10] of integer=(0,1,2,0,1,2,0,1,2,1);
  y:array[1..10] of integer=(0,0,0,1,1,1,2,2,2,3);
var
  n,i,j:integer;
  a:array[1..10] of integer;
  pr_x:array[1..9] of integer;
  pr_y:array[1..9] of integer;
   pr_x2:array[1..9] of integer;
  pr_y2:array[1..9] of integer;
  xc,yc:integer;
  dx,dy:integer;
  can:boolean;
  s:string;
begin
  //reset(input,'input.txt');
  //rewrite(output,'output.txt');
  readln(n);
  readln(s);
  fillchar(pr_x,sizeof(pr_x),0);
  fillchar(pr_y,sizeof(pr_x),0);
  fillchar(pr_x2,sizeof(pr_x),0);
  fillchar(pr_y2,sizeof(pr_x),0);
  for i:=1 to n  do
    a[i]:=strtoint(s[i]);
  for i:=1 to n-1 do
  begin
    pr_x[i]:=x[a[i+1]]-x[a[i]];
    pr_y[i]:=y[a[i+1]]-y[a[i]];
  end;
  for i:=1 to 9 do
  begin
   if(a[1]=i) then
    continue;
    xc:=x[i];
    yc:=y[i];
    can:=true;
    for j:=1 to n-1 do
    begin
      xc:=xc+pr_x[j];
      yc:=yc+pr_y[j];
      if (((xc<0) or (xc>2) or (yc>2) or (yc<0) ) and not ((xc=1) and (yc=3))) then
      begin
        can:=false
      end;
    end;
    if can then
    begin
      writeln('NO');
      halt;
    end;
  end;
  writeln('YES');
  //close(input);
  //close(output);
end.

program Project3;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var n, i, cur : longint;
    u, d, l, r : boolean;
    c : char;

begin
//  assign(input, 'input.txt'); assign(output, 'output.txt');
  readln(n);
  for i := 1 to n do
  begin
    read(c);
    cur := ord(c) - ord('0');
    if (cur > 0) and (cur < 4) then
      u := True;
    if (cur = 7) or (cur = 0) or (cur = 9) then
      d := True;
    if (cur = 1) or (cur = 4) or (cur = 7) then
      l := True;
    if (cur = 3) or (cur = 6) or (cur = 9) then
      r := True;
  end;

  if (u and d) or (l and r) then
    write('YES')
  else
    write('NO');
end.

program Project3;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var n, i, cur : longint;
    u, d, l, r : boolean;
    c : char;

begin
//  assign(input, 'input.txt'); assign(output, 'output.txt');
  readln(n);
  for i := 1 to n do
  begin
    read(c);
    cur := ord(c) - ord('0');
    if (cur > 0) and (cur < 4) then
      u := True;
    if (cur = 7) or (cur = 0) or (cur = 9) then
      d := True;
    if (cur = 1) or (cur = 4) or (cur = 7) then
      l := True;
    if (cur = 3) or (cur = 6) or (cur = 9) then
      r := True;
  end;

  if (u and d) and (l and r) then
    write('YES')
  else
    write('NO');
end.

   const eps=0.0000000001;  besk=8000000000000000000;  nn=200000;
   modul=1000000007;
   label 1,2;
    type
    mas=array [-10000..nn] of int64;  { point=record x,y,z:real;end; }
    zap=record p1,p2,p3 :int64;end; zap1=^zap;
    mass=array[0..5] of int64;mass1=^mass;
    var imax,imin,jmax,jmin,koln,kfin,distmin,ii,jj,kk,zn,razmax,pmin,pmax,sch,iistart,xmax,ymin,n,qq,ot,q,pos,left,right,amax,ost,h,tt,t1,pp,p,p1,p2,p3,p4,t,nm,s1,s2,m,s,cen,t2,i1:int64;
    stepp,iii,mask,newug,newdl,dloch,dugol,ist,jst,ifin,jfin,fin,newnapx,newnapy,step, k,i,j:longint;
    oldnap, napr,alpha,prmax,v,aaa,bbb,ccc:extended; hhh:zap;
    napx,napy,x,first,next,prev,l,r, dl,ochnewi,ochnewj,ochj,c,y,z,newoch,och,aold,b,a:array[-100000..2000000] of int64;
   stpr,stoim,blup,bldown, blright, blleft, ppole,vol:array[-10..1200,-10..1200] of int64;
   marked:array[-10..1100000] of boolean;
    yyy,xx:mass;
    ss, ss1,ss2:string;
    point:array[0..200000] of mass;
    sa,sb,pra,prb,suma,sumb,ota,otb,mmax,mmin,smax,smin:array[-100..200000] of extended;
     zan:array[-10..20,010..200] of boolean;
    sss: array[-10..100000] of string;ch3,ch,ch1,ch2:char;
    dp:array[-1..500,-1..500,-1..500]of boolean;
    clav:array[-10..300,-10..300] of int64;
    ugol:array[0..5000,0..5000] of double;

  ddmax,ddmin :array[-1..300000,-1..20] of extended;
    chh,pole :array [-10..200,-10..200] of char;
    maxpr:array[0..nn] of string;
    str:array[0..nn] of string;
     nap,tt1,tt2,disk,v0,v1,s0,t0:extended;
     newx,newy,yy:array[-100..200000] of int64;

     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;

function good(ii,jj:longint):boolean;   var fl:boolean;
i,j:longint;
  begin
     fl:=false;
     if clav[ii,jj]>=0 then fl:=true;
     good:=fl;
  end;

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

   readln(n);
   readln(ss);
   napx[1]:=1;  napy[1]:=0;
   napx[1]:=-1;  napy[1]:=0;
   napx[1]:=0;  napy[1]:=1;
   napx[1]:=0;  napy[1]:=-1;

   for i:=-10 to 100 do for j:=-10 to 100 do clav[i,j]:=-1;
   clav[1,1]:=1;
   clav[1,2]:=2;
   clav[1,3]:=3;
   clav[2,1]:=4;
   clav[2,2]:=5;
   clav[2,3]:=6;
   clav[3,1]:=7;
   clav[3,2]:=8;
   clav[3,3]:=9;
   clav[4,2]:=0;
   for step:=1 to n do
     begin
        t:=ord(ss[step])-48;
        for i:=0 to 4 do for j:=0 to 4 do
        if clav[i,j]=t then zan[i,j]:=true;

     end;

    for step:=1 to 4 do
      begin
         flag:=true;
         for i:=1 to 4 do for j:=1 to 4 do if zan[i,j] then
           begin
               if not good(i+napx[step],j+napy[step]) then flag:=false;

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

      end;
       writeln('YES');

   1:          close(output);
end.

   const eps=0.0000000001;  besk=8000000000000000000;  nn=200000;
   modul=1000000007;
   label 1,2;
    type
    mas=array [-10000..nn] of int64;  { point=record x,y,z:real;end; }
    zap=record p1,p2,p3 :int64;end; zap1=^zap;
    mass=array[0..5] of int64;mass1=^mass;
    var imax,imin,jmax,jmin,koln,kfin,distmin,ii,jj,kk,zn,razmax,pmin,pmax,sch,iistart,xmax,ymin,n,qq,ot,q,pos,left,right,amax,ost,h,tt,t1,pp,p,p1,p2,p3,p4,t,nm,s1,s2,m,s,cen,t2,i1:int64;
    stepp,iii,mask,newug,newdl,dloch,dugol,ist,jst,ifin,jfin,fin,newnapx,newnapy,napx,napy,step, k,i,j:longint;
    oldnap, napr,alpha,prmax,v,aaa,bbb,ccc:extended; hhh:zap;
    x,first,next,prev,l,r, dl,ochnewi,ochnewj,ochj,c,y,z,newoch,och,aold,b,a:array[-100000..2000000] of int64;
   stpr,stoim,blup,bldown, blright, blleft, ppole,vol:array[-10..1200,-10..1200] of int64;
   marked:array[-10..1100000] of boolean;
    yyy,xx:mass;
    ss, ss1,ss2:string;
    point:array[0..200000] of mass;
    sa,sb,pra,prb,suma,sumb,ota,otb,mmax,mmin,smax,smin:array[-100..200000] of extended;
     zan:array[-10..20,010..200] of boolean;
    sss: array[-10..100000] of string;ch3,ch,ch1,ch2:char;
    dp:array[-1..500,-1..500,-1..500]of boolean;
    clav:array[-10..300,-10..300] of int64;
    ugol:array[0..5000,0..5000] of double;

  ddmax,ddmin :array[-1..300000,-1..20] of extended;
    chh,pole :array [-10..200,-10..200] of char;
    maxpr:array[0..nn] of string;
    str:array[0..nn] of string;
     nap,tt1,tt2,disk,v0,v1,s0,t0:extended;
     newx,newy,yy:array[-100..200000] of int64;

     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);
    }

   readln(n);
   readln(ss);
   for i:=-10 to 100 do for j:=-10 to 100 do clav[i,j]:=-1;
   clav[1,1]:=1;
   clav[1,2]:=2;
   clav[1,3]:=3;
   clav[2,1]:=4;
   clav[2,2]:=5;
   clav[2,3]:=6;
   clav[3,1]:=7;
   clav[3,2]:=8;
   clav[3,3]:=9;
   clav[4,2]:=0;
   for step:=1 to n do
     begin
        t:=ord(ss[step])-48;
        for i:=0 to 4 do for j:=0 to 4 do
        if clav[i,j]=t then zan[i,j]:=true;

     end;

  imax:=-100; imin:=100;  jmax:=-100; jmin:=100;
  for i:=1 to 10 do for j:=1 to 10 do if zan[i,j] then
    begin
    jmax:=max(jmax,j); jmin:=min(jmin,j);

    imax:=max(imax,i); imin:=min(imin,i);
    end;

  {writeln(imin,' ',imax,' -- ',jmax,' ',jmin);
   }
  if (imax-imin=2)and(jmax-jmin=2) then flag:=true;
  if (imax-imin=3) then flag:=true;
  if flag then write('YES') else write('NO');

   1:          close(output);
end.

program O_O;
 var
  i,j,k,n,m:longint;
  s:string;
  pd:array[1..4] of boolean;
  b:array[0..10] of boolean;
begin
  readln(n);
  readln(s);
  for i:=1 to n do
   b[ord(s[i])-48]:=true;
  for i:=0 to 9 do
   if b[i] then
    begin
     if (i=1)or(i=2)or(i=3) then
      pd[1]:=true;
     if (i=3)or(i=6)or(i=9) then
      pd[2]:=true;
     if (i=1)or(i=4)or(i=7)or(i=0) then
      pd[3]:=true;
     if (i=7)or(i=0)or(i=9) then
      pd[4]:=true;
    end;
  if (pd[1])and(pd[2])and(pd[3])and(pd[4]) then
   writeln('YES')
  else
   writeln('NO');
  readln;
end.

program O_O;
 var
  i,j,k,n,m:longint;
  s:string;
  pd:array[1..4] of boolean;
  b:array[0..10] of boolean;
begin
  readln(n);
  readln(s);
  for i:=1 to n do
   b[ord(s[i])-48]:=true;
  for i:=0 to 9 do
   if b[i] then
    begin
     if (i=1)or(i=2)or(i=3) then
      pd[1]:=true;
     if (i=3)or(i=6)or(i=9) then
      pd[2]:=true;
     if (i=1)or(i=4)or(i=7) then
      pd[3]:=true;
     if (i=7)or(i=0)or(i=9) then
      pd[4]:=true;
    end;
  if (pd[1])and(pd[2])and(pd[3])and(pd[4]) then
   writeln('YES')
  else
   writeln('NO');
  readln;
end.

var
   n,i,minb,minc,maxb,maxc,q,k,j,curi,curj,count:longint;
     a,b,c,x,y:array[1..1000] of longint;
     s,sd:string;
  begin
    readln(n);
       readln(s);
         for i:=1 to n do begin
          sd:=copy(s,i,1);
          val(sd,a[i],q);
          end;
        for i:=1 to n do begin
          if a[i]=1 then begin b[i]:=1; c[i]:=1; end;
          if a[i]=2 then begin b[i]:=1; c[i]:=2; end;
          if a[i]=3 then begin b[i]:=1; c[i]:=3; end;
          if a[i]=4 then begin b[i]:=2; c[i]:=1; end;
          if a[i]=5 then begin b[i]:=2; c[i]:=2; end;
          if a[i]=6 then begin b[i]:=2; c[i]:=3; end;
          if a[i]=7 then begin b[i]:=3; c[i]:=1; end;
          if a[i]=8 then begin b[i]:=3; c[i]:=2; end;
          if a[i]=9 then begin b[i]:=3; c[i]:=3; end;
          if a[i]=0 then begin b[i]:=4; c[i]:=2; end;
            end;
          for i:=1 to n-1 do x[i]:=b[i+1]-b[i];
            for i:=1 to n-1 do y[i]:=c[i+1]-c[i];
               count:=0;
              for i:=1 to 3 do begin
                for j:=1 to 3 do begin
                  curi:=i;
                  curj:=j;
                    q:=0;

                  for k:=1 to n-1 do begin
                    if ((curi+x[k]=4) and (curi+x[k]=4))
                    and
                    ((curj+y[k]=2)  and (curj+y[k]=2))
                      then begin inc(q); curi:=4; curj:=2; continue; end;

                if ((curi+x[k]>=1) and (curi+x[k]<=3))
                    and
                    ((curj+y[k]>=1)  and (curj+y[k]<=3))
                      then begin inc(q); curi:=curi+x[k]; curj:=curj+y[k]; end;

                end;
                  if q=n-1 then inc(count);
                end;
                end;

                 if count>1 then
                write('NO')
                  else write('YES');

        end.

const
   fin='mac.inp';fon='mac.out';
var t,i,n,d1,d2,d3,d4:longint; s:string; kt:boolean;
   a:array[1..10] of longint;

procedure solve;
begin
readln(n); read(s);
for i:=1 to n do
   a[i]:=ord(s[i])-48;
d1:=0; d2:=0; d3:=0; d4:=0;
for i:=1 to n do
   begin
   if (a[i]+3=11) or (a[i]+3<=9) then
      begin
      inc(d1);
      end;
   end;
for i:=1 to n do
   begin
   if (a[i]-3=-3) or (a[i]-3>=1) then
      begin
      inc(d2);
      end;
   end;
for i:=1 to n do
   begin
   if (a[i]+1=1) or ((a[i]+1<=9) and (a[i]<>3) and (a[i]<>6)) then
      begin
      inc(d3);
      end;
   end;
for i:=1 to n do
   begin
   if (a[i]-1=-1) or ((a[i]-1>=1) and (a[i]<>4) and (a[i]<>7)) then
      begin
      inc(d4);
      end;
   end;
kt:=true;
if (d1=n) or (d2=n) or (d3=n) or (d4=n) then
   kt:=false;

if kt=false then
   write('NO')
else
   write('YES');
end;

begin
//assign(input,fin);reset(input);
//assign(output,fon);rewrite(output);
solve;
end.

var
s:array[0..4] of string;
ss:string;
i,j,k,n,ans:integer;
flag:boolean;
begin
s[0]:='1234567890';
s[1]:='---1234568';
s[2]:='456789----';
s[3]:='-12-45-78-';
s[4]:='23-56-89--';
 readln(n);
 readln(ss);
 ans:=0;
        for j:=1 to 4 do
        begin
        flag:=false;
                for i:=1 to n do
                begin
                        for k:=1 to 10 do
                        if (s[0][k]=ss[i]) and (s[j][k]='-')
                        then flag:=true;
                end;
        if not flag then
                begin
                writeln('NO');
                halt(0);
                end;
        end;
writeln('YES');

end.

Var
s:string;
n,l,d,r,u,z,i:longint;
begin
 readln(n);
 readln(s);
 for i:=1 to length(s) do
  begin
   if s[i]='0' then z:=1;
   if (s[i]='1') or (s[i]='2') or (s[i]='3') then u:=1;
   if (s[i]='3') or (s[i]='6') or (s[i]='9') then r:=1;
   if (s[i]='7') or (s[i]='8') or (s[i]='9') then d:=1;
   if (s[i]='1') or (s[i]='4') or (s[i]='7') then l:=1;
  end;
if ((u=1) and (r=1) and (d=1) and (l=1)) or ((z=1) and (u=1)) then
 write('YES')
else
 write('NO');
end.

{$Mode objfpc}

var
  n,i,j,o,kq:integer;
  s:char;
  check:boolean;
  a:array[0..10] of boolean;

begin
  readln(n);
  for i:=1 to n do
    begin
      read(s);
      a[ord(s)-48]:=true;
    end;
  if a[1] or a[2] or a[3] then inc(kq);
  if a[1] or a[4] or a[7] then inc(kq);
  if a[3] or a[6] or a[9] then inc(kq);
  if a[7] or a[0] or a[9] then inc(kq);
  if kq < 4 then write('NO')
  else write('YES');
end.

{$Mode objfpc}

var
  n,i,j,o,kq:integer;
  s:char;
  check:boolean;
  a:array[0..10] of integer;

begin
  readln(n);
  for i:=1 to n do
    begin
      read(s);
      a[i]:=ord(s)-48;
      if a[i] = 0 then a[i]:=11;
    end;
  for i:=1 to 9 do
    begin
      o:=i;
      check:=false;
      for j:=2 to n do
        begin
          o:=o + (a[j]-a[j-1]);
          if (o < 1) or ((o > 9) and (o <> 11)) then check:=true;
        end;
      if not check then inc(kq);
    end;
  if kq > 1 then write('NO')
  else write('YES');
end.

var n,i,x:longint;
    a:array[1..9] of longint;
    sl:string; bl:boolean;
begin
 readln(n);
 readln(sl);
 for i:=1 to n do
  begin
   val(sl[i],x);
   a[i]:=x;
  end;
 bl:=false;
 for i:=1 to n do
  if a[i] <> 0 then
   if a[i] - 3 < 0 then
    begin
     bl:=true;
     break;
    end;
 if bl = false then begin write('NO'); exit; end;
 for i:=1 to n do
  if a[i] <> 8 then
   if (a[i] + 3 >= 10) or (a[i] = 0) then
    begin
     bl:=true;
     break;
    end;
 if bl = false then begin write('NO'); exit; end;
 for i:=1 to n do
   if (a[i] = 0) or (a[i] = 3) or (a[i] = 6) or (a[i] = 9) then
    begin
     bl:=true;
     break;
    end;
 if bl = false then begin write('NO'); exit; end;
 for i:=1 to n do
   if (a[i] = 0) or (a[i] = 1) or (a[i] = 4) or (a[i] = 7) then
    begin
     bl:=true;
     break;
    end;
 if bl = false then begin write('NO'); exit; end;
 write('YES');
end.

var n,i,x:longint;
    a:array[1..9] of longint;
    sl:string; bl:boolean;
begin
 readln(n);
 readln(sl);
 for i:=1 to n do
  begin
   val(sl[i],x);
   a[i]:=x;
  end;
 bl:=false;
 for i:=1 to n do
  if a[i] <> 0 then
   if a[i] - 3 < 0 then
    begin
     bl:=true;
     break;
    end;
 if bl = false then begin write('NO'); exit; end;
 for i:=1 to n do
  if a[i] <> 8 then
   if (a[i] + 3 >= 10) or (a[i] = 0) then
    begin
     bl:=true;
     break;
    end;
 if bl = false then begin write('NO'); exit; end;
 for i:=1 to n do
  if a[i] <> 8 then
   if (a[i] = 0) or (a[i] = 3) or (a[i] = 6) or (a[i] = 9) then
    begin
     bl:=true;
     break;
    end;
 if bl = false then begin write('NO'); exit; end;
 for i:=1 to n do
  if a[i] <> 8 then
   if (a[i] = 0) or (a[i] = 1) or (a[i] = 4) or (a[i] = 7) then
    begin
     bl:=true;
     break;
    end;
 if bl = false then begin write('NO'); exit; end;
 write('YES');
end.

var n,i,x:longint;
    a:array[1..9] of longint;
    sl:string; bl:boolean;
begin
 readln(n);
 readln(sl);
 for i:=1 to n do
  begin
   val(sl[i],x);
   a[i]:=x;
  end;
 bl:=false;
 for i:=1 to n do
  if a[i] <> 0 then
   if a[i] - 3 < 0 then
    begin
     bl:=true;
     break;
    end;
 if bl = false then begin write('NO'); exit; end;
 bl:=false;
 for i:=1 to n do
  if a[i] <> 8 then
   if (a[i] + 3 >= 10) or (a[i] = 0) then
    begin
     bl:=true;
     break;
    end;
 if bl = false then begin write('NO'); exit; end;
 bl:=false;
 for i:=1 to n do
   if (a[i] = 0) or (a[i] = 3) or (a[i] = 6) or (a[i] = 9) then
    begin
     bl:=true;
     break;
    end;
 if bl = false then begin write('NO'); exit; end;
 bl:=false;
 for i:=1 to n do
   if (a[i] = 0) or (a[i] = 1) or (a[i] = 4) or (a[i] = 7) then
    begin
     bl:=true;
     break;
    end;
 if bl = false then begin write('NO'); exit; end;
 write('YES');
end.

var
  a, b, i, k: int64;
  c, c1: char;
  ar: array [0..100] of char;
  q, q1: boolean;

begin
  readln(a);
  i := 0;
  while i < a do begin
    read(ar[i]);
    inc(i);
  end;
  i := 0;
  while i < a do begin
    if ar[i] <> '0' then k := ord(ar[i]) - 48
      else k := 11;
    if k - 1 = 0 then q := true;
    if (k + 1 = 10) or (k + 1 = 12) then q1 := true;
    inc(i);
  end;
  if (not(q)) or (not(q1)) then writeln('NO')
    else writeln('YES');
end.

var
  a, b, i, k: int64;
  c, c1: char;
  ar: array [0..100] of char;
  arr: array [1..10, 1..10] of int64;
  q, q1, q2, q3: boolean;

begin
  readln(a);
  i := 0;
  while i < a do begin
    read(ar[i]);
    inc(i);
  end;
  i := 0;
  while i < a do begin
    k := ord(ar[i]) - 48;
    if (k < 4) then q := true;
    if (k = 1) or (k = 4) or (k = 7) or (k = 0) then q1 := true;
    if (k = 7) or (k = 0) or (k = 9) then q2 := true;
    if (k = 3) or (k = 6) or (k = 9) or (k = 0) then q3 := true;
    inc(i);
  end;
  if (not(q)) or (not(q1)) or (not(q2)) or (not(q3)) then writeln('NO')
    else writeln('YES');
end.

var ch:char;
    n,i:longint;
    a:array[0..6] of longint;
begin
readln(n);
for i:=1 to n do
  begin
  read(ch);
  if ch in ['1','2','3'] then
    inc(a[1])
  else
    if ch in ['4','5','6'] then
      inc(a[2])
    else
      if ch in ['7','8','9'] then
        inc(a[3])
      else
        inc(a[4]);
  if ch='8' then
    inc(a[5]);
  end;
if (a[1]>=1) and (a[3]>=1) then
  if (a[3]=a[5]) and (a[4]=0) then
    writeln('NO')
  else
    writeln('YES')
else
  writeln('NO');
end.

program cellphone;
type sett=record
     x,y:integer;
end;
var n,i,j,ii:integer;
    str:string;
    p:array[1..4,1..4] of integer;
    a:array[1..1000] of integer;
    d:array[1..1000] of sett;
    pos:sett;
    ff,f:boolean;
begin
     readln(n);
     readln(str);
     fillchar(p,sizeof(p),0);
     for i:=1 to 3 do
         for j:=1 to 3 do
         p[i,j]:=1;
     p[2,4]:=1;
     for i:=1 to n do
     begin
          a[i]:=ord(a[i])-48;
     end;
     i:=0;
     while i<n-1 do
     begin
          i:=i+1;
          if a[i]=0 then
          begin
               if a[i+1]=0 then
               begin
                    d[i].x:=0;
                    d[i].y:=0;
               end
               else begin
                         d[i].x:=(a[i+1] mod 3)-2;
                         d[i].y:=4-((a[i+1] div 3)+1);
               end;
          end
          else begin
                    if (a[i+1]=0) then
                    begin
                         d[i].x:=2-(a[i] mod 3);
                         d[i].y:=4-(a[i] div 3+1);
                    end
                    else begin
                              d[i].x:=(a[i+1] mod 3)-(a[i] mod 3);
                              d[i].y:=(a[i+1] div 3)-(a[i] div 3);
                    end;
          end;
     end;
     for i:=0 to 9 do
     begin
          for j:=1 to n do
          begin
               if i=a[j] then
               begin
                    f:=false;
                    break;
               end;
          end;
          if f then
          begin
               if i=0 then
               begin
                    pos.x:=2;
                    pos.y:=4;
                    for ii:=1 to n-1 do
                    begin
                         pos.x:=pos.x+d[ii].x;
                         pos.y:=pos.y+d[ii].y;
                         if p[pos.x,pos.y]<>1 then
                         begin
                              ff:=false;
                              break;
                         end;
                    end;
               end
               else begin
                         pos.x:=i mod 3;
                         pos.y:=i div 3+1;
                         for ii:=1 to n do
                         begin
                              pos.x:=pos.x+d[ii].x;
                              pos.y:=pos.y+d[ii].y;
                              if p[pos.x,pos.y]<>1 then
                              begin
                                   ff:=false;
                                   break;
                              end;
                         end;
                    end;

          end;
          if ff then begin writeln('YES'); break;end;
     end;
     if not ff then writeln('NO');
end.
     i

program cellphone;
type sett=record
     x,y:integer;
end;
var n,i,j,ii:integer;
    str:string;
    p:array[1..4,1..4] of integer;
    a:array[1..1000] of integer;
    d:array[1..1000] of sett;
    pos:sett;
    ff,f:boolean;
begin
     readln(n);
     readln(str);
     fillchar(p,sizeof(p),0);
     for i:=1 to 3 do
         for j:=1 to 3 do
         p[i,j]:=1;
     p[2,4]:=1;
     for i:=1 to n do
     begin
          a[i]:=ord(a[i])-48;
     end;
     i:=0;
     while i<n-1 do
     begin
          i:=i+1;
          if a[i]=0 then
          begin
               if a[i+1]=0 then
               begin
                    d[i].x:=0;
                    d[i].y:=0;
               end
               else begin
                         d[i].x:=(a[i+1] mod 3)-2;
                         d[i].y:=4-((a[i+1] div 3)+1);
               end;
          end
          else begin
                    if (a[i+1]=0) then
                    begin
                         d[i].x:=2-(a[i] mod 3);
                         d[i].y:=4-(a[i] div 3+1);
                    end
                    else begin
                              d[i].x:=(a[i+1] mod 3)-(a[i] mod 3);
                              d[i].y:=(a[i+1] div 3)-(a[i] div 3);
                    end;
          end;
     end;
     for i:=0 to 9 do
     begin
          for j:=1 to n do
          begin
               if i=a[j] then
               begin
                    f:=false;
                    break;
               end;
          end;
          if f then
          begin
               if i=0 then
               begin
                    pos.x:=2;
                    pos.y:=4;
                    for ii:=1 to n-1 do
                    begin
                         pos.x:=pos.x+d[ii].x;
                         pos.y:=pos.y+d[ii].y;
                         if p[pos.x,pos.y]<>1 then
                         begin
                              ff:=false;
                              break;
                         end;
                    end;
               end
               else begin
                         pos.x:=i mod 3;
                         pos.y:=i div 3+1;
                         for ii:=1 to n do
                         begin
                              pos.x:=pos.x+d[ii].x;
                              pos.y:=pos.y+d[ii].y;
                              if p[pos.x,pos.y]<>1 then
                              begin
                                   ff:=false;
                                   break;
                              end;
                         end;
                    end;

          end;
          if ff then begin writeln('NO'); break;end;
     end;
     if not ff then writeln('YES');
end.

{$MODE OBJFPC}
const
  ip = '';//'689A.inp';
  op = '';//'689A.out';

var
  n : integer;
  s : ansistring;
  fi, fo : text;

procedure enter;
begin
  readln(fi, n);
  readln(fi, s);
end;

function check(s : ansistring) : boolean;
var
  i : integer;
begin
  for i := 1 to length(s) - 1 do
    if (s[i] <> s[i + 1]) then exit(false);
  exit(true);
end;

function check2(s : ansistring) : boolean;
var
  i : integer;
begin
  for i := 1 to length(s) do
    if (s[i] <> '0') and (s[i] <> '2') and (s[i] <> '5') and (s[i] <> '8') then exit(false);
  exit(true);
end;

procedure process;
begin
  if (pos('1', s) > 0) and (pos('9', s) > 0) then writeln(fo, 'YES')
  else if (pos('3', s) > 0) and (pos('7', s) > 0) then writeln(fo, 'YES')
  //else if (check(s)) then writeln(fo, 'YES')
  //else if (check2(s)) then writeln(fo, 'YES')
  else if (pos('2', s) > 0) and (pos('0', s) > 0) then writeln(fo, 'YES')
  else if (pos('1', s) > 0) and (pos('0', s) > 0) then writeln(fo, 'YES')
  else if (pos('3', s) > 0) and (pos('0', s) > 0) then writeln(fo, 'YES')
  else if (n > 7) then writeln(fo, 'YES')
  else writeln(fo, 'NO');
end;

begin
  assign(fi, ip); reset(fi);
  assign(fo, op); rewrite(fo);

  enter;
  process;

  close(fi); close(fo);
end.

{$MODE OBJFPC}
const
  ip = '';//'689A.inp';
  op = '';//'689A.out';

var
  n : integer;
  s : ansistring;
  fi, fo : text;

procedure enter;
begin
  readln(fi, n);
  readln(fi, s);
end;

function check(s : ansistring) : boolean;
var
  i : integer;
begin
  for i := 1 to length(s) - 1 do
    if (s[i] <> s[i + 1]) then exit(false);
  exit(true);
end;

function check2(s : ansistring) : boolean;
var
  i : integer;
begin
  for i := 1 to length(s) do
    if (s[i] <> '0') and (s[i] <> '2') and (s[i] <> '5') and (s[i] <> '8') then exit(false);
  exit(true);
end;

procedure process;
begin
  if (pos('1', s) > 0) and (pos('9', s) > 0) then writeln(fo, 'YES')
  else if (pos('3', s) > 0) and (pos('7', s) > 0) then writeln(fo, 'YES')
  else if (check(s)) then writeln(fo, 'YES')
  else if (check2(s)) then writeln(fo, 'YES')
  else writeln(fo, 'NO');
end;

begin
  assign(fi, ip); reset(fi);
  assign(fo, op); rewrite(fo);

  enter;
  process;

  close(fi); close(fo);
end.

{$MODE OBJFPC}
const
  ip = '';//'689A.inp';
  op = '';//'689A.out';

var
  n : integer;
  s : ansistring;
  fi, fo : text;

procedure enter;
begin
  readln(fi, n);
  readln(fi, s);
end;

function check(s : ansistring) : boolean;
var
  i : integer;
begin
  for i := 1 to length(s) - 1 do
    if (s[i] <> s[i + 1]) then exit(false);
  exit(true);
end;

function check2(s : ansistring) : boolean;
var
  i : integer;
begin
  for i := 1 to length(s) do
    if (s[i] <> '0') and (s[i] <> '2') and (s[i] <> '5') and (s[i] <> '8') then exit(false);
  exit(true);
end;

procedure process;
begin
  if (pos('1', s) > 0) and (pos('9', s) > 0) then writeln(fo, 'YES')
  else if (pos('3', s) > 0) and (pos('7', s) > 0) then writeln(fo, 'YES')
  //else if (check(s)) then writeln(fo, 'YES')
  else if (check2(s)) then writeln(fo, 'YES')
  else if (n > 7) then writeln(fo, 'YES')
  else writeln(fo, 'NO');
end;

begin
  assign(fi, ip); reset(fi);
  assign(fo, op); rewrite(fo);

  enter;
  process;

  close(fi); close(fo);
end.

{$MODE OBJFPC}
const
  ip = '';//'689A.inp';
  op = '';//'689A.out';

var
  n : integer;
  s : ansistring;
  fi, fo : text;

procedure enter;
begin
  readln(fi, n);
  readln(fi, s);
end;

function check(s : ansistring) : boolean;
var
  i : integer;
begin
  for i := 1 to length(s) - 1 do
    if (s[i] <> s[i + 1]) then exit(false);
  exit(true);
end;

procedure process;
begin
  if (pos('1', s) > 0) and (pos('9', s) > 0) then writeln(fo, 'YES')
  else if (pos('3', s) > 0) and (pos('7', s) > 0) then writeln(fo, 'YES')
  else if (check(s)) then writeln(fo, 'YES')
  else writeln(fo, 'NO');
end;

begin
  assign(fi, ip); reset(fi);
  assign(fo, op); rewrite(fo);

  enter;
  process;

  close(fi); close(fo);
end.

Program ioh;
Type gan=record
     x,y:longint;
     end;
Var n,i,j,k:longint;

    a,road:array[0..10] of gan;
    s:array[1..10] of longint;
    b:array[-1..10,-1..10] of longint;
    x,y:longint;
    res:boolean;
    ch:char;
Begin
  Readln(n);
  for i:=1 to n do begin
    Read(ch);
    s[i]:=ord(ch)-48;
  End;
  a[0].x:=2;
  a[0].y:=1;
  a[1].x:=1;
  a[1].y:=4;
  a[2].x:=2;
  a[2].y:=4;
  a[3].x:=3;
  a[3].y:=4;
  a[4].x:=1;
  a[4].y:=3;
  a[5].x:=2;
  a[5].y:=3;
  a[6].x:=3;
  a[6].y:=3;
  a[7].x:=1;
  a[7].y:=2;
  a[8].x:=2;
  a[8].y:=2;
  a[9].x:=3;
  a[9].y:=2;
  for i:=2 to n do begin
    road[i].x:=a[s[i]].x-a[s[i-1]].x;
    road[i].y:=a[s[i]].y-a[s[i-1]].y;
  End;
  for i:=-1 to 10 do
    for j:=-1 to 10 do b[i,j]:=-1;
  k:=1;
  for i:=4 downto 2 do begin

    for j:=1 to 3 do begin
      b[i,j]:=k;
      inc(k);

    end;

  End;
  b[1,2]:=0;
  For i:=4 downto 1 do begin
    for j:=1 to 3 do begin
      y:=i;
      x:=j;
         res:=true;
         if b[x,y]=-1 then begin
            res:=false;
            Break;
          end;
        for k:=2 to n do begin
          if b[x,y]=-1 then begin
            res:=false;
            Break;
          end;
          inc(x,road[k].x);
          inc(y,road[k].y);
        End;
        if res=true then begin
          Writeln('NO');
          Halt;
        End;
    End;
  End;

  Writeln('YES')
End.

Program ioh;
Type gan=record
     x,y:longint;
     end;
Var n,i,j,k:longint;

    a,road:array[0..10] of gan;
    s:array[1..10] of longint;
    b:array[-5..15,-5..15] of longint;
    x,y:longint;
    res:boolean;
    ch:char;
Begin
  Readln(n);
  for i:=1 to n do begin
    Read(ch);
    s[i]:=ord(ch)-48;
  End;
  a[0].x:=2;
  a[0].y:=1;
  a[1].x:=1;
  a[1].y:=4;
  a[2].x:=2;
  a[2].y:=4;
  a[3].x:=3;
  a[3].y:=4;
  a[4].x:=1;
  a[4].y:=3;
  a[5].x:=2;
  a[5].y:=3;
  a[6].x:=3;
  a[6].y:=3;
  a[7].x:=1;
  a[7].y:=2;
  a[8].x:=2;
  a[8].y:=2;
  a[9].x:=3;
  a[9].y:=2;

  for i:=2 to n do begin
    road[i].x:=a[s[i]].x-a[s[i-1]].x;
    road[i].y:=a[s[i]].y-a[s[i-1]].y;
    //Writeln(road[i].x,road[i].y);
  End;
  for i:=-5 to 15 do
    for j:=-5 to 15 do b[i,j]:=-1;
  k:=1;
  for i:=4 downto 2 do begin

    for j:=1 to 3 do begin
      b[i,j]:=k;
      inc(k);

    end;

  End;
  b[1,2]:=0;
  For i:=4 downto 1 do begin
    for j:=1 to 3 do begin
      y:=i;
      x:=j;
         res:=true;
         if b[x,y]=-1 then begin
            res:=false;
            Break;
          end;
        for k:=2 to n do begin
          if b[x,y]=-1 then begin
            res:=false;
            Break;
          end;
          inc(x,road[k].x);
          inc(y,road[k].y);
        End;
        if res=true then begin
          Writeln('NO');
          Halt;
        End;
    End;
  End;

  Writeln('YES')
End.

Program ioh;
Type gan=record
     x,y:longint;
     end;
Var n,i,j,k:longint;

    a,road:array[0..10] of gan;
    s:array[1..10] of longint;
    b:array[-5..15,-5..15] of longint;
    x,y:longint;
    res:boolean;
    ch:char;
Begin
  Readln(n);
  for i:=1 to n do begin
    Read(ch);
    s[i]:=ord(ch)-48;
  End;
  a[0].x:=2;
  a[0].y:=1;
  a[1].x:=1;
  a[1].y:=4;
  a[2].x:=2;
  a[2].y:=4;
  a[3].x:=3;
  a[3].y:=4;
  a[4].x:=1;
  a[4].y:=3;
  a[5].x:=2;
  a[5].y:=3;
  a[6].x:=3;
  a[6].y:=3;
  a[7].x:=1;
  a[7].y:=2;
  a[8].x:=2;
  a[8].y:=2;
  a[9].x:=3;
  a[9].y:=2;

  for i:=2 to n do begin
    road[i].x:=a[s[i]].x-a[s[i-1]].x;
    road[i].y:=a[s[i]].y-a[s[i-1]].y;
    //Writeln(road[i].x,road[i].y);
  End;
  for i:=-5 to 15 do
    for j:=-5 to 15 do b[i,j]:=-1;
  k:=1;
  for i:=4 downto 2 do begin

    for j:=1 to 3 do begin
      b[i,j]:=k;
      inc(k);

    end;

  End;
  b[1,2]:=0;
  For i:=4 downto 1 do begin
    for j:=1 to 3 do begin
      y:=i;
      x:=j;
         res:=true;
         if b[y,x]<>s[1] then begin
         if b[y,x]=-1 then begin
            res:=false;
          end;
        for k:=2 to n do begin
          //Writeln(x,y,' ',i,j);
          if b[y,x]=-1 then begin
            res:=false;
            Break;
          end;
          inc(x,road[k].x);
          inc(y,road[k].y);
        End;
        if b[x,y]=-1 then begin
            res:=false;
        end;
        if res=true then begin
          Writeln('NO');
         // Writeln(j,' ',i);
          Halt;
        End;
        end;
    End;
  End;

  Writeln('YES')
End.

Program ioh;
Type gan=record
     x,y:longint;
     end;
Var n,i,j,k:longint;

    a,road:array[0..10] of gan;
    s:array[1..10] of longint;
    b:array[-5..15,-5..15] of longint;
    x,y:longint;
    res:boolean;
    ch:char;
Begin
  Readln(n);
  for i:=1 to n do begin
    Read(ch);
    s[i]:=ord(ch)-48;
  End;
  a[0].x:=2;
  a[0].y:=1;
  a[1].x:=1;
  a[1].y:=4;
  a[2].x:=2;
  a[2].y:=4;
  a[3].x:=3;
  a[3].y:=4;
  a[4].x:=1;
  a[4].y:=3;
  a[5].x:=2;
  a[5].y:=3;
  a[6].x:=3;
  a[6].y:=3;
  a[7].x:=1;
  a[7].y:=2;
  a[8].x:=2;
  a[8].y:=2;
  a[9].x:=3;
  a[9].y:=2;

  for i:=2 to n do begin
    road[i].x:=a[s[i]].x-a[s[i-1]].x;
    road[i].y:=a[s[i]].y-a[s[i-1]].y;
    //Writeln(road[i].x,road[i].y);
  End;
  for i:=-5 to 15 do
    for j:=-5 to 15 do b[i,j]:=-1;
  k:=1;
  for i:=4 downto 2 do begin

    for j:=1 to 3 do begin
      b[i,j]:=k;
      inc(k);

    end;

  End;
  b[1,2]:=0;
  For i:=4 downto 1 do begin
    for j:=1 to 3 do begin
      y:=i;
      x:=j;
         res:=true;
         if b[x,y]=-1 then begin
            res:=false;

          end;
        for k:=2 to n do begin
          if b[x,y]=-1 then begin
            res:=false;
            Break;
          end;
          inc(x,road[k].x);
          inc(y,road[k].y);
        End;
        if b[x,y]=-1 then begin
            res:=false;

          end;
        if res=true then begin
          Writeln('NO');
          Halt;
        End;
    End;
  End;

  Writeln('YES')
End.

uses math;
const fi='';
      fo='';
      maxn=9;

var f1,f2:text;
    a:array[1..maxn]of longint;
    l,r,t,b,n:longint;
    check:boolean;
procedure openfile;
 begin
  assign(f1,fi);
  reset(f1);
  assign(f2,fo);
  rewrite(f2);
 end;
procedure closefile;
 begin
  close(f1);
  close(f2);
 end;
procedure input;
 var i:longint;   ch:char;
 begin
   readln(f1,n);
   for i:=1 to n do
    begin read(f1,ch); a[i]:=ord(ch)-48;end;
 end;

procedure init;
   var i:longint;
  begin
   l:=-1;
   r:=-1;
   t:=-1;
   b:=-1;
   for i:=1 to 9 do
    case a[i] of
      0:begin b:=1;check:=true;end;
      1:begin t:=1;l:=1;end;
      2:t:=1;
      3:begin t:=1;r:=1;end;
      4:l:=1;
      6:r:=1;
      7:begin b:=1;l:=1;end;
      9:begin b:=1;r:=1;end;
     end;
  end;

procedure solve;
  var i:longint;
  begin
   if ((t=1) and(l=1) and(r=1) and(b=1))or((t=1)and check) then write(f2,'YES') else write(f2,'NO');
  end;

procedure output;

  begin

  end;

begin
 openfile;
 input;
 init;
 solve;
 output;
 closefile;
end.

{$OPTIMIZATION LEVEL2}
{$INLINE ON}
uses math;
const log=18;
      ms=1e-9;
      oo=round(1e9);
      modulo=1000000007;
      fi='';
      fo='';
      maxn=100010;
      move:array[0..9,1..4]of longint=((8,-1,-1,-1),(-1,2,4,-1),(-1,3,5,1),(-1,-1,6,2),(1,5,7,-1),(2,6,8,4),(3,-1,9,5),(4,8,-1,-1),(5,9,0,7),(6,-1,-1,8));

var f1,f2:text;
    a,b:array[0..10]of longint;
    n:longint;

procedure openfile;
 begin
  assign(f1,fi);
  reset(f1);
  assign(f2,fo);
  rewrite(f2);
 end;

procedure closefile;
 begin
  close(f1);
  close(f2);
 end;

procedure input;
 var i:longint;
 begin
  readln(f1,n);
  for i:=1 to n do
   read(f1,a[i]);
 end;

procedure init;
  var i,j:longint;
      check:boolean;
  begin
   for i:=1 to 4 do
    begin
     check:=true;
     for j:=1 to n do
      b[j]:=move[a[j],i];
     for j:=1 to n do
      if b[j]=-1 then check:=false;
     if check then
      begin
       writeln(f2,'NO');
       closefile;
       halt;
      end;
    end;
  end;

procedure solve;
  var i,j:longint;
  begin
   writeln(f2,'YES');
  end;

procedure output;
  var i:longint;
  begin

  end;

begin
 openfile;
 input;
 init;
 solve;
 output;
 closefile;
end.

uses math;
const fi='';
      fo='';
      maxn=90;

var f1,f2:text;
    a:array[1..maxn]of longint;
    l,r,t,b,n:longint;
    check1,check2,check:boolean;
procedure openfile;
 begin
  assign(f1,fi);
  reset(f1);
  assign(f2,fo);
  rewrite(f2);
 end;
procedure closefile;
 begin
  close(f1);
  close(f2);
 end;
procedure input;
 var i:longint;   ch:char;
 begin
   readln(f1,n);
   for i:=1 to n do
    begin read(f1,ch); a[i]:=ord(ch)-48;end;
   check:=false;
   check1:=false;
   check2:=false;
 end;

procedure init;
   var i:longint;
  begin
   l:=-1;
   r:=-1;
   t:=-1;
   b:=-1;
   for i:=1 to 9 do
    case a[i] of
      0:begin b:=1;check:=true;end;
      1:begin t:=1;l:=1;check1:=true;end;
      2:t:=1;
      3:begin t:=1;r:=1;check2:=true;end;
      4:l:=1;
      6:r:=1;
      7:begin b:=1;l:=1;end;
      9:begin b:=1;r:=1;end;
     end;
  end;

procedure solve;
  var i:longint;
  begin
   if ((t=1) and(l=1) and(r=1) and(b=1))or((t=1)and (check1 or check2)and check) then write(f2,'YES') else write(f2,'NO');
  end;

procedure output;

  begin

  end;

begin
 openfile;
 input;
 init;
 solve;
 output;
 closefile;
end.

uses math;
const fi='';
      fo='';
      maxn=9;

var f1,f2:text;
    a:array[1..maxn]of longint;
    l,r,t,b,n:longint;
procedure openfile;
 begin
  assign(f1,fi);
  reset(f1);
  assign(f2,fo);
  rewrite(f2);
 end;
procedure closefile;
 begin
  close(f1);
  close(f2);
 end;
procedure input;
 var i:longint;   ch:char;
 begin
   readln(f1,n);
   for i:=1 to n do
    begin read(f1,ch); a[i]:=ord(ch)-48;end;
 end;

procedure init;
   var i:longint;
  begin
   l:=-1;
   r:=-1;
   t:=-1;
   b:=-1;
   for i:=1 to 9 do
    case a[i] of
      0:b:=1;
      1:begin t:=1;l:=1;end;
      2:t:=1;
      3:begin t:=1;r:=1;end;
      4:l:=1;
      6:r:=1;
      7:begin b:=1;l:=1;end;
      9:begin b:=1;r:=1;end;
     end;
  end;

procedure solve;
  var i:longint;
  begin
   if (t=1) and(l=1) and(r=1) and(b=1) then write(f2,'YES') else write(f2,'NO');
  end;

procedure output;

  begin

  end;

begin
 openfile;
 input;
 init;
 solve;
 output;
 closefile;
end.

uses math;
const fi='';
      fo='';
      maxn=90;

var f1,f2:text;
    a:array[1..maxn]of longint;
    l,r,t,b,n:longint;
    check1,check2,check:boolean;
procedure openfile;
 begin
  assign(f1,fi);
  reset(f1);
  assign(f2,fo);
  rewrite(f2);
 end;
procedure closefile;
 begin
  close(f1);
  close(f2);
 end;
procedure input;
 var i:longint;   ch:char;
 begin
   readln(f1,n);
   i:=1;
   while i<=n do
    begin read(f1,ch); a[i]:=ord(ch)-48; if (a[i]<10) and (a[i]>-1) then inc(i);end;
   check:=false;
   check1:=false;
   check2:=false;
 end;

procedure init;
   var i:longint;
  begin
   l:=-1;
   r:=-1;
   t:=-1;
   b:=-1;
   for i:=1 to 9 do
    case a[i] of
      0:begin b:=1;check:=true;end;
      1:begin t:=1;l:=1;check1:=true;end;
      2:t:=1;
      3:begin t:=1;r:=1;check2:=true;end;
      4:l:=1;
      6:r:=1;
      7:begin b:=1;l:=1;end;
      9:begin b:=1;r:=1;end;
     end;
  end;

procedure solve;
  var i:longint;
  begin
   if ((t=1) and(l=1) and(r=1) and(b=1))or((t=1)and check) then write(f2,'YES') else write(f2,'NO');
  end;

procedure output;

  begin

  end;

begin
 openfile;
 input;
 init;
 solve;
 output;
 closefile;
end.

Var n: int64;
  i,m,j,k: integer;
  s: string;
  test: boolean;
Begin
  readln(n);
  readln(s);
  For i:=0 To 1 Do
    Begin
      m := i;
      For j:=1 To n-1 Do
        Begin
          k := (ord(s[j+1])-48)-(ord(s[j])-48);
          m := m+k;
          If (m>10) Or (m<0) Then test := true
          Else test := false;
        End;
      If test=false Then
        Begin
          writeln('No');
          break;
        End;
    End;
End.

var
  f : array[-50..50,-50..50] of longint;
  x,y : array[0..15] of longint;
  n,i,j,xx,yy,q,a,x1,y1,k,aa : longint;
  c : char;
  ff : boolean;

begin
  readln(n);
  fillchar(f,sizeof(f),63);
  f[1,1]:=1; f[1,2]:=2; f[1,3]:=3;
  f[2,1]:=4; f[2,2]:=5; f[2,3]:=6;
  f[3,1]:=7; f[3,2]:=8; f[3,3]:=9;
  f[4,2]:=0;
  read(c); a:=ord(c)-48; aa:=a;
  for i:=1 to 4 do for j:=1 to 3 do if f[i,j] = a then begin xx:=i; yy:=j; break; end;
  for q:=2 to n do begin
    read(c);
    a:=ord(c)-48;
    inc(k);
    for i:=1 to 4 do for j:=1 to 3 do if f[i,j] = a then begin x1:=i; y1:=j; break; end;
    x[k]:=x1-xx; y[k]:=y1-yy;
    xx:=x1; yy:=y1;
  end;
  readln;
  for q:=0 to 9 do begin
    if q = aa then continue;
    for i:=1 to 4 do for j:=1 to 3 do if f[i,j] = q then begin xx:=i; yy:=j; break; end;
    ff:=false;
    for i:=1 to k do begin
      x1:=xx+x[i]; y1:=yy+y[i];
      if not (f[x1,y1] in [0..9]) then begin ff:=true; break; end;
      x1:=xx; y1:=yy;
    end;
    if not ff then begin writeln('NO'); halt; end;
  end;
  writeln('YES');
end.

var
  f,fk : array[-50..50,-50..50] of longint;
  x,y : array[0..15] of longint;
  n,i,j,xx,yy,q,a,x1,y1,k,aa : longint;
  c : char;
  ff : boolean;

begin
  readln(n);
  fillchar(f,sizeof(f),63);
  f[1,1]:=1; f[1,2]:=2; f[1,3]:=3;
  f[2,1]:=4; f[2,2]:=5; f[2,3]:=6;
  f[3,1]:=7; f[3,2]:=8; f[3,3]:=9;
  f[4,2]:=0;
  for i:=0 to 5 do for j:=0 to 5 do if f[i,j] in [0..9] then fk[i,j]:=1;
  read(c); a:=ord(c)-48; aa:=a;
  for i:=1 to 4 do for j:=1 to 3 do if f[i,j] = a then begin xx:=i; yy:=j; break; end;
  for q:=2 to n do begin
    read(c);
    a:=ord(c)-48;
    inc(k);
    for i:=1 to 4 do for j:=1 to 3 do if f[i,j] = a then begin x1:=i; y1:=j; break; end;
    x[k]:=x1-xx; y[k]:=y1-yy;
    xx:=x1; yy:=y1;
  end;
  readln;
  for q:=0 to 9 do begin
    if q = aa then continue;
    for i:=1 to 4 do for j:=1 to 3 do if f[i,j] = q then begin xx:=i; yy:=j; break; end;
    ff:=false;
    for i:=1 to k do begin
      x1:=xx+x[i]; y1:=yy+y[i];
      if fk[x1,y1] = 0 then begin ff:=true; break; end;
      xx:=x1; y1:=yy;
    end;
    if not ff then begin writeln('NO'); halt; end;
  end;
  writeln('YES');
end.

var
  ok:boolean;
  i,j,k,c,x,y,d:integer;
  s:string;
  w: char;
begin
 readln(s);
 readln(s);
 c:=0;
 ok:=false;
 x:=0;
 y:=0;
 d:=0;
 for i:=0 to 3 do
 begin
  for j:=0 to 2 do
  begin
   ok:=true;
   for k:=1 to length(s) do
   begin
    d:=ord(s[k]);
    if d=48 then
    begin
     x:=1;
     y:=3;
    end else
    begin
     if d <=51 then begin
      x:=d-49;
      y:=0;
     end else
     begin
      if d <=54 then begin
       x:=d-52;
       y:=1;
      end else begin
       x:=d-55;
       y:=2;
      end;
     end;
    end;
    x:=x+j;
    y:=y+i;
    if (not (((x <=2) and (y <=2)) or ((x=1) and (y=3)))) then ok :=false;
   end;
   if ok then c:=c+1;
  end;
 end;
 if c =1 then begin s:='YES'; end else s:='NO';
 writeln(s);
end.

var
n,i,X:longint;
a:array[0..10] of longint;
f:boolean;c:char;
begin
  //assign(input,'mphone.in');reset(input);
 // assign(output,'mphone.out');rewrite(output);
  readln(n);
  for i:=1 to n do
    begin
      read(c);
      a[i]:=ord(c)-ORD('0');
      if c='0' then
        a[i]:=11;
    end;
  f:=false;
  for i:=1 to n do
    if not((a[i]+3) in [1,2,3,4,5,6,7,8,9,11]) then
      f:=true;
  if f then
    begin
      f:=false;
      for i:=1 to n do
        BEGIN
          if a[i]-3<=0 then f:=true
          else
          if not((A[I]-3) in [1,2,3,4,5,6,7,8,9,11]) then
            f:=true;
        END;
      if f=FALSE then writeln('NO')
        else writeln('YES');
    end
  else writeln('NO');
  close(input);
  close(output);
end.

var n,i:longint;c:char;
f:array[0..101]of boolean;
a,b:array[0..101]of longint;
procedure dfs(t:longint;flag:boolean);
var i:longint;
begin
if t>n then
  begin
  if flag then
    begin
    writeln('NO');
    close(input);close(output);halt;
    end;
  exit;
  end;
for i:=1 to 11 do
  if(i<>10)and(f[i]=false)then
    begin
    f[i]:=true;b[t]:=i;
    dfs(t+1,flag and(a[t]-a[t-1]=b[t]-b[t-1])or(t=1));
    f[i]:=false;
    end;
end;
begin
//assign(input,'mphone.in');reset(input);
//assign(output,'mphone.out');rewrite(output);
readln(n);
for i:=1 to n do
  begin
  read(c);a[i]:=ord(c)-48;
  if a[i]=0 then a[i]:=11;
  f[a[i]]:=true;
  end;
dfs(1,true);
writeln('YES');
close(input);close(output);
end.

var n,i,vmin,vmax,gmin,gmax,e,x,y,l7,l9:longint;
c:char;
begin
y:=0; vmax:=-1; gmax:=-1; vmin:=100; gmin:=100;
l7:=0; l9:=0;
readln(n);
for i:=1 to n do
begin
read(c);
val(c,x,e);
if (x=0) then begin y:=1; vmax:=3; if (1<gmin) then gmin:=1; if (1>gmax) then gmax:=1; if (3<vmin) then vmin:=3; end else
begin
if (x=7) then l7:=1 else if (x=9) then l9:=9;
if ((x-1) div 3>vmax) then vmax:=(x-1) div 3;
if ((x-1) div 3<vmin) then vmin:=(x-1) div 3;
if ((x-1) mod 3>gmax) then gmax:=(x-1) mod 3;
if ((x-1) mod 3<gmin) then gmin:=(x-1) mod 3;
end;
end;
if ((y=1) and (vmax-vmin+1>=4)) or ((y=0) and ((vmax-vmin+1>=3) and ((l7=1) or (l9=1))) and (gmax-gmin+1>=3)) then write('YES') else write('NO');
end.

var n,i,vmin,vmax,gmin,gmax,e,x,y:longint;
c:char;
begin
y:=0; vmax:=-1; gmax:=-1; vmin:=100; gmin:=100;
readln(n);
for i:=1 to n do
begin
read(c);
val(c,x,e);
if (x=0) then begin y:=1; vmax:=3; if (1<gmin) then gmin:=1; if (1>gmax) then gmax:=1; if (3<vmin) then vmin:=3; end else
begin
if ((x-1) div 3>vmax) then vmax:=(x-1) div 3;
if ((x-1) div 3<vmin) then vmin:=(x-1) div 3;
if ((x-1) mod 3>gmax) then gmax:=(x-1) mod 3;
if ((x-1) mod 3<gmin) then gmin:=(x-1) mod 3;
end;
end;
if ((y=1) and (vmax-vmin+1>=4)) or ((y=0) and (vmax-vmin+1>=3) and (gmax-gmin+1>=3)) then write('YES') else write('NO');
end.

var
 a,b,aa:array[-1..10,-1..10]of longint;
 res:array[0..10000]of string;
 n,m,k,l,j,i,p1,p2,p3,p4:longint;
 s:string;
begin
 readln(n);
 readln(s);
 b[1,1]:=1;b[1,2]:=1;b[1,3]:=1;b[2,1]:=1;b[2,2]:=1;
 b[2,3]:=1;b[3,1]:=1;b[3,2]:=1;b[3,3]:=1;b[4,1]:=1;

 for i:=1 to n do
 begin
  if s[i]='1' then a[1,1]:=1;
  if s[i]='2' then a[1,2]:=1;
  if s[i]='3' then a[1,3]:=1;
  if s[i]='4' then a[2,1]:=1;
  if s[i]='5' then a[2,2]:=1;
  if s[i]='6' then a[2,3]:=1;
  if s[i]='7' then a[3,1]:=1;
  if s[i]='8' then a[3,2]:=1;
  if s[i]='9' then a[3,3]:=1;
  if s[i]='0' then a[4,1]:=1;
 end;

 aa:=a;
 for i:=4 downto 1 do
 begin
  for j:=4 downto 1 do if a[i,j]=1 then begin a[i,j]:=0; a[i+1,j]:=1; end;
 end;
 p1:=1; p2:=1; p3:=1; p4:=1;
 for i:=0 to 5 do
 begin
  for j:=0 to 5 do if (a[i,j]=1)and(b[i,j]=0) then p1:=0;
 end;

 a:=aa;
 for i:=1 to 5 do
 begin
  for j:=1 to 5 do if a[i,j]=1 then begin a[i,j]:=0; a[i-1,j]:=1; end;
 end;
 for i:=0 to 5 do
 begin
  for j:=0 to 5 do if (a[i,j]=1)and(b[i,j]=0) then p2:=0;
 end;

 a:=aa;
 for i:=4 downto 5 do
 begin
  for j:=4 downto 5 do if a[i,j]=1 then begin a[i,j]:=0; a[i,j+1]:=1; end;
 end;
 for i:=0 to 5 do
 begin
  for j:=0 to 5 do if (a[i,j]=1)and(b[i,j]=0) then p3:=0;
 end;

 a:=aa;
 for i:=1 to 5 do
 begin
  for j:=1 to 5 do if a[i,j]=1 then begin a[i,j]:=0; a[i,j-1]:=1; end;
 end;
 for i:=0 to 5 do
 begin
  for j:=0 to 5 do if (a[i,j]=1)and(b[i,j]=0) then p4:=0;
 end;

 if (p1+p2+p3+p4>0) then writeln('NO') else writeln('YES');
end.

var
 a,b,aa:array[-1..10,-1..10]of longint;
 res:array[0..10000]of string;
 n,m,k,l,j,i,p1,p2,p3,p4:longint;
 s:string;
begin
 readln(n);
 readln(s);
 b[1,1]:=1;b[1,2]:=1;b[1,3]:=1;b[2,1]:=1;b[2,2]:=1;
 b[2,3]:=1;b[3,1]:=1;b[3,2]:=1;b[3,3]:=1;b[4,1]:=1;

 for i:=1 to n do
 begin
  if s[i]='1' then a[1,1]:=1;
  if s[i]='2' then a[1,2]:=1;
  if s[i]='3' then a[1,3]:=1;
  if s[i]='4' then a[2,1]:=1;
  if s[i]='5' then a[2,2]:=1;
  if s[i]='6' then a[2,3]:=1;
  if s[i]='7' then a[3,1]:=1;
  if s[i]='8' then a[3,2]:=1;
  if s[i]='9' then a[3,3]:=1;
  if s[i]='0' then a[4,1]:=1;
 end;

 aa:=a;
 for i:=4 downto 1 do
 begin
  for j:=4 downto 1 do if a[i,j]=1 then begin a[i,j]:=0; a[i+1,j]:=1; end;
 end;
 p1:=1; p2:=1; p3:=1; p4:=1;
 for i:=0 to 4 do
 begin
  for j:=0 to 4 do if (a[i,j]=1)and(b[i,j]=0) then p1:=0;
 end;

 a:=aa;
 for i:=1 to 4 do
 begin
  for j:=1 to 4 do if a[i,j]=1 then begin a[i,j]:=0; a[i-1,j]:=1; end;
 end;
 for i:=0 to 4 do
 begin
  for j:=0 to 4 do if (a[i,j]=1)and(b[i,j]=0) then p2:=0;
 end;

 a:=aa;
 for i:=4 downto 1 do
 begin
  for j:=4 downto 1 do if a[i,j]=1 then begin a[i,j]:=0; a[i,j+1]:=1; end;
 end;
 for i:=0 to 4 do
 begin
  for j:=0 to 4 do if (a[i,j]=1)and(b[i,j]=0) then p3:=0;
 end;

 a:=aa;
 for i:=1 to 4 do
 begin
  for j:=1 to 4 do if a[i,j]=1 then begin a[i,j]:=0; a[i,j-1]:=1; end;
 end;
 for i:=0 to 4 do
 begin
  for j:=0 to 4 do if (a[i,j]=1)and(b[i,j]=0) then p4:=0;
 end;

 if (p1+p2+p3+p4>0) then writeln('NO') else writeln('YES');
end.

Var n,i,j,ff1:longint;
    s:string;
    f,a,b:array[1..10] of longint;
    const x:array[1..10] of longint =(1,1,1,2,2,2,3,3,3,4);
    const y:array[1..10] of longint =(1,2,3,1,2,3,1,2,3,2);
    Begin
    readln(n);
    readln(s);
    for i:=1 to 10 do
     begin
     a[i]:=x[i];
     b[i]:=y[i];
     end;
    f[ord(s[1])-48]:=1;
    for i:=2 to n do
     begin
      for j:=1 to 10 do
       begin
        a[j]:=a[j]-(x[ord(s[i-1])-48]-x[ord(s[i])-48]);
        b[j]:=b[j]-(y[ord(s[i-1])-48]-y[ord(s[i])-48]);
        if (b[j]<>2) and (a[j]=4) then f[j]:=1;
        if (a[j]<1) then f[j]:=1;
        if (b[j]>3) then f[j]:=1;
        if (b[j]<1) then f[j]:=1;
        if (a[j]>4) then f[j]:=1;

       end;
     end;
     for i:=1 to 10 do
      if f[i]=0 then ff1:=1;
     if ff1=1 then writeln('NO')
      else writeln('YES');
     end.

Var n,i,j,ff1:longint;
    s:string;
    f,a,b:array[0..10] of longint;
    const x:array[0..10] of longint =(4,1,1,1,2,2,2,3,3,3,4);
    const y:array[0..10] of longint =(2,1,2,3,1,2,3,1,2,3,2);
    Begin
    readln(n);
    readln(s);
    for i:=1 to 10 do
     begin
     a[i]:=x[i];
     b[i]:=y[i];
     end;
    f[ord(s[1])-48]:=1;
    for i:=2 to n do
     begin
      for j:=0 to 9 do
       begin
        a[j]:=a[j]-(x[ord(s[i-1])-48]-x[ord(s[i])-48]);
        b[j]:=b[j]-(y[ord(s[i-1])-48]-y[ord(s[i])-48]);
        if (b[j]<>2) and (a[j]=4) then f[j]:=1;
        if (a[j]<1) then f[j]:=1;
        if (b[j]>3) then f[j]:=1;
        if (b[j]<1) then f[j]:=1;
        if (a[j]>4) then f[j]:=1;

       end;
     end;
     for i:=0 to 9 do
      if f[i]=0 then ff1:=1;
     if ff1=1 then writeln('NO')
      else writeln('YES');
     end.

var kt:boolean;
s:ansistring;
        x,y,i,n,j,xx,yy,k:longint;
        a:array[-10..10,-10..10]of char;
                l,r:array[0..100000] of longint;
function th1(x,y:longint):boolean;
var i:longint;
begin
        for i:=2 to n do
        begin
                x:=x+l[i];
                y:=y+r[i];
                if a[x,y]='?' then exit(false);
        end;
        exit(true);
end;
begin
        readln(n);
        kt:=false;
        readln(s);
        for i:=0 to  5 do
                for j:=0  to 5 do a[i,j]:='?';
        a[1,1]:='1';
        a[1,2]:='2';
        a[1,3]:='3';
        a[2,1]:='4';
        a[2,2]:='5';
        a[2,3]:='6';
        a[3,1]:='7';
        a[3,2]:='8';
        a[3,3]:='9';
        a[4,2]:='0';
        xx:=0;
        yy:=0;
        for i:=1 to n do
        begin
                if s[i]='0' then
                begin
                        x:=4;
                        y:=2;
                end else
                begin
                        k:=ord(s[i])-ord('0');
                        if k mod  3 =0 then x:=k div 3 else x:=k div 3+1;
                        if k mod  3 =0 then y:=3 else y:=k mod 3;
                       // writeln(x,y);
                end;
                l[i]:=x-xx;
                r[i]:=y-yy;
               // writeln(l[i],' ',r[i]);
                xx:=x;
                yy:=y;
        end;
        for i:=1 to 3 do
                for j:=1 to 3 do
                        if a[i,j]<>s[1] then
                begin
                        if th1(i,j) then kt:=true;
                end;
        if s[1]<>'0' then if th1(4,2) then kt:=true;
        if not kt then write('YES') else write('NO');
end.

const
   tfi='';
   tfo='';

type info= record
   x, y: longint; end;

var
   fi, fo: text;
   n: longint;
   a: array[0..4,0..4] of longint;
   x: array[0..100] of longint;
   pos: array[0..100] of info;

procedure Init;
var
   i, j, w: longint;
begin
   w := 0;
   for i:=1 to 3 do
      for j:=1 to 3 do
         begin
            inc(w);
            a[i, j] := w;
            pos[w].x :=i; pos[w].y := j;
         end;
   a[4, 1] := -1; a[4, 3] := -1;
   a[4, 2] := 0; pos[0].x := 4; pos[0].y := 2;
end;

procedure __;
var
   i: longint;
   c: char;
begin
   assign(fi, tfi); reset(fi);
   assign(fo, tfo); rewrite(fo);
   readln(fi, n);
   for i:=1 to n do
      begin
         read(fi, c);
         x[i] := ord(c)-48;
      end;
end;

function check(u, v, k1, k2: longint): boolean;
var
   x, y: longint;
begin
   x := u+k1;
   y := v+k2;
   if (x<1) or (y<1)  or (y>3) or (x>3) then exit(false);
   if a[x, y]=-1 then exit(false);
   exit(true);
end;

procedure xuly;
var
   i, j, k, k1, k2: longint;
   ok: boolean;
begin
   if n=1 then
      begin
         writeln(fo,'NO'); exit;
      end;

   for i:=1 to 4 do
      for j:=1 to 3 do
         if ((i<>pos[x[1]].x) or (j<>pos[x[1]].y)) and (a[i, j]<>-1) then
            begin
               ok := true;
               for k:=2 to n do
                  begin
                     k1 := pos[x[k]].x-pos[x[1]].x;
                     k2 := pos[x[k]].y-pos[x[1]].y;
                     if not check(i, j, k1, k2) then
                        begin
                           ok := false; break;
                        end;
                  end;
               if ok then
                  begin
                     writeln(fo,'NO'); exit;
                  end;
            end;
   writeln(fo,'YES');
end;

procedure _;
begin
   close(fi); close(fo);
end;

BEGIN
   Init;
   __;
   xuly;
   _;
END.

{$MODE OBJFPC}
program dream_hyojoo;
uses sysutils;
var
    xx,n,i,j:integer;
    s:char;
    a,movex,movey:array[0..10] of integer;
    st:boolean;

function hang(i:integer):integer;
begin
    if i=0 then exit(4) else exit(i div 3+1)
end;

function cot(i:integer):integer;
begin
    if i=0 then exit(2) else
    if i mod 3=0 then exit(3) else exit(i mod 3)
end;

function solve(i,j,k:integer):integer;
var x,y:integer;
begin
    y:=cot(i);
    x:=hang(i);
    x:=x+j;
    y:=y+k;
    if (x>3) or (x<0) or (y<1) or (y>3) then
       begin
        st:=true;
        exit
       end;
    if x=3 then
       if y=2 then exit(0) else
          begin
            st:=true;
            exit
          end;
    exit(x*3+y)
end;

begin
    //assign(input,'dream_hyojoo.inp');
    //reset(input);
    readln(n);
    for i:=1 to n do
        begin
            read(s);
            a[i]:=strtoint(s);
            movey[i]:=cot(a[i])-cot(a[i-1]);
            movex[i]:=hang(a[i])-hang(a[i-1])
        end;
    for i:=0 to 9 do
    if i<>a[1] then
        begin
             xx:=1;
             st:=false;
             for j:=2 to n do
                 begin

                     xx:=solve(xx,movex[j],movey[j]);
                     if st then break
                 end;
             if not st then
                begin
                 writeln('NO');
                 halt
                end;
        end;
    writeln('YES')
end.

{$MODE OBJFPC}
program dream_hyojoo;
uses sysutils;
var
    xx,n,i,j:integer;
    s:char;
    a,movex,movey:array[0..10] of integer;
    st:boolean;

function hang(i:integer):integer;
begin
    if i=0 then exit(4) else
    if i mod 3=0 then exit(i div 3) else exit(i div 3+1)
end;

function cot(i:integer):integer;
begin
    if i=0 then exit(2) else
    if i mod 3=0 then exit(3) else exit(i mod 3)
end;

function solve(i,j,k:integer):integer;
var x,y:integer;
begin
    y:=cot(i);
    x:=hang(i);
    x:=x+j;
    y:=y+k;
    if (x>3) or (x<0) or (y<1) or (y>3) then
       begin
        st:=true;
        exit
       end;
    if x=3 then
       if y=2 then exit(0) else
          begin
            st:=true;
            exit
          end;
    exit((x-1)*3+y)
end;

begin
    //assign(input,'dream_hyojoo.inp');
   // reset(input);
    readln(n);
    for i:=1 to n do
        begin
            read(s);
            a[i]:=strtoint(s);
            movey[i]:=cot(a[i])-cot(a[i-1]);
            movex[i]:=hang(a[i])-hang(a[i-1])
        end;
    for i:=0 to 9 do
    if i<>a[1] then
        begin
             xx:=1;
             st:=false;
             for j:=2 to n do
                 begin

                     xx:=solve(xx,movex[j],movey[j]);
                     if st then break
                 end;
             if not st then
                begin
                 writeln('NO');
                 halt
                end;
        end;
    writeln('YES')
end.

{$MODE OBJFPC}
program dream_hyojoo;
uses sysutils;
var
    xx,n,i,j:integer;
    s:char;
    a,movex,movey:array[0..10] of integer;
    st:boolean;

function hang(i:integer):integer;
begin
    if i=0 then exit(4) else
    if i mod 3=0 then exit(i div 3) else exit(i div 3+1)
end;

function cot(i:integer):integer;
begin
    if i=0 then exit(2) else
    if i mod 3=0 then exit(3) else exit(i mod 3)
end;

function solve(i,j,k:integer):integer;
var x,y:integer;
begin
    y:=cot(i);
    x:=hang(i);
    x:=x+j;
    y:=y+k;
    if (x>4) or (x<0) or (y<1) or (y>3) then
       begin
        st:=true;
        exit
       end;
    if x=4 then
       if y=2 then exit(0) else
          begin
            st:=true;
            exit
          end;
    exit((x-1)*3+y)
end;

begin
    //assign(input,'dream_hyojoo.inp');
    //reset(input);
    readln(n);
    for i:=1 to n do
        begin
            read(s);
            a[i]:=strtoint(s);
            movey[i]:=cot(a[i])-cot(a[i-1]);
            movex[i]:=hang(a[i])-hang(a[i-1])
        end;
    for i:=0 to 9 do
    if i<>a[1] then
        begin
             xx:=i;
             st:=false;
             for j:=2 to n do
                 begin

                     xx:=solve(xx,movex[j],movey[j]);
                     if st then break
                 end;
             if not st then
                begin
                 writeln('NO');
                 halt
                end;
        end;
    writeln('YES')
end.

{$MODE OBJFPC}
program dream_hyojoo;
uses sysutils;
var
    xx,n,i,j:integer;
    s:char;
    a,movex,movey:array[0..10] of integer;
    st:boolean;

function hang(i:integer):integer;
begin
    if i=0 then exit(4) else
    if i mod 3=0 then exit(i div 3) else exit(i div 3+1)
end;

function cot(i:integer):integer;
begin
    if i=0 then exit(2) else
    if i mod 3=0 then exit(3) else exit(i mod 3)
end;

function solve(i,j,k:integer):integer;
var x,y:integer;
begin
    y:=cot(i);
    x:=hang(i);
    x:=x+j;
    y:=y+k;
    if (x>3) or (x<0) or (y<1) or (y>3) then
       begin
        st:=true;
        exit
       end;
    if x=3 then
       if y=2 then exit(0) else
          begin
            st:=true;
            exit
          end;
    exit((x-1)*3+y)
end;

begin
    //assign(input,'dream_hyojoo.inp');
    //reset(input);
    readln(n);
    for i:=1 to n do
        begin
            read(s);
            a[i]:=strtoint(s);
            movey[i]:=cot(a[i])-cot(a[i-1]);
            movex[i]:=hang(a[i])-hang(a[i-1])
        end;
    for i:=0 to 9 do
    if i<>a[1] then
        begin
             xx:=i;
             st:=false;
             for j:=2 to n do
                 begin

                     xx:=solve(xx,movex[j],movey[j]);
                     if st then break
                 end;
             if not st then
                begin
                 writeln('NO');
                 halt
                end;
        end;
    writeln('YES')
end.

{$MODE OBJFPC}
program dream_hyojoo;
uses sysutils;
var
    xx,n,i,j:integer;
    s:char;
    a,movex,movey:array[0..10] of integer;
    st:boolean;

function hang(i:integer):integer;
begin
    if i=0 then exit(4) else
    if i mod 3=0 then exit(i div 3) else exit(i div 3+1)
end;

function cot(i:integer):integer;
begin
    if i=0 then exit(2) else
    if i mod 3=0 then exit(3) else exit(i mod 3)
end;

function solve(i,j,k:integer):integer;
var x,y:integer;
begin
    y:=cot(i);
    x:=hang(i);
    x:=x+j;
    y:=y+k;
    if (x>3) or (x<0) or (y<1) or (y>3) then
       begin
        st:=true;
        exit
       end;
    if x=4 then
       if y=2 then exit(0) else
          begin
            st:=true;
            exit
          end;
    exit((x-1)*3+y)
end;

begin
    //assign(input,'dream_hyojoo.inp');
    //reset(input);
    readln(n);
    for i:=1 to n do
        begin
            read(s);
            a[i]:=strtoint(s);
            movey[i]:=cot(a[i])-cot(a[i-1]);
            movex[i]:=hang(a[i])-hang(a[i-1])
        end;
    for i:=0 to 9 do
    if i<>a[1] then
        begin
             xx:=i;
             st:=false;
             for j:=2 to n do
                 begin

                     xx:=solve(xx,movex[j],movey[j]);
                     if st then break
                 end;
             if not st then
                begin
                 writeln('NO');
                 halt
                end;
        end;
    writeln('YES')
end.

var
 j1,ij,w,y,i1,f,k,q,r,h,i,j:longint;
 a:array[0..5,0..5]of integer;
 s:string;
begin
 //assign (input,'cinema.in');reset(input);
 //assign(output,'cinema.out');rewrite(output);
  readln(w);
  readln(s);
  for i:=1 to w do
  begin
   val(s[i],y);
   r:=(2+y) div 3;
   if r=0 then r:=4;
   h:=y mod 3 ;
   if h=0 then h:=3;
   a[r,h]:=1;
  end;
  for i:=0 to 4 do a[0,i]:=2;
  for i:=0 to 4 do a[i,0]:=2;
  for i:=0 to 4 do a[i,4]:=2;
  for i:=0 to 4 do a[5,i]:=2;
  a[4,1]:=2;
  a[4,3]:=2;
   f:=0;
  for i:=1 to 4 do for j:=1 to 3 do if f=0 then if a[i,j]=1 then if a[i-1,j]=2 then f:=1;
  if f=0 then begin writeln('NO'); halt; end;
  f:=0;
  for i:=1 to 4 do for j:=1 to 3 do if f=0 then if a[i,j]=1 then if a[i+1,j]=2 then f:=1;
  if f=0 then begin writeln('NO'); halt; end;
   f:=0;
  for i:=1 to 4 do for j:=1 to 3 do if f=0 then if a[i,j]=1 then if a[i,j-1]=2 then f:=1;
  if f=0 then begin writeln('NO'); halt; end;
  f:=0;
  for i:=1 to 4 do for j:=1 to 3 do if f=0 then if a[i,j]=1 then if a[i,j+1]=2 then f:=1;
  if f=0 then begin writeln('NO'); halt; end;

  writeln('YES');
end.

const fi = '';

var  s: string;
     n, i: longint;
     res, co0, co: boolean;
     f: text;

begin
     assign(f, fi); reset(f);
     readln(f, n);
     readln(f, s);
     close(f);

     for i:= 1 to n do if s[i] = '0' then begin co0:= true; break; end;
     res:= false;
     if co0 then
        begin
           for i:= 1 to n do
              if ('1' <= s[i]) and (s[i] <= '3') then res:= true;
        end
     else
        begin
           res:= true; co:= false;
           for i:= 1 to n do
              if ('1' <= s[i]) and (s[i] <= '3') then co:= true;
           res:= res and co;
           co:= false;
           for i:= 1 to n do
              if ('7' <= s[i]) and (s[i] <= '9') then co:= true;
           res:= res and co;
           co:= false;
           for i:= 1 to n do
              if (s[i] = '1') or (s[i] = '4') or (s[i] = '7') then co:= true;
           res:= res and co;
           co:= false;
           for i:= 1 to n do
              if (s[i] = '3') or (s[i] = '6') or (s[i] = '9') then co:= true;
           res:= res and co;
        end;
     if res then writeln('YES') else writeln('NO');
     readln;
end.