#include <stdio.h>
#include <stdlib.h>
int main(){
	int x[10]={2,1,2,3,1,2,3,1,2,3};
	int y[10]={4,1,1,1,2,2,2,3,3,3};
	int flag,n,a[10],i,flag1=0,flag2=0;
	scanf("%d ",&n);
	char c;
	for(i=0;i<n;i++){
		scanf("%c",&c);
		a[i]=c-'0';
		if (a[i]==0) flag2=1;
		if(a[i]==7 || a[i]==9)flag1=1;
	}
	int minx=4,maxx=0,miny=5,maxy=0;
	for(i=0;i<n;i++){
		if (x[a[i]]<minx)minx=x[a[i]];
		if (x[a[i]]>maxx)maxx=x[a[i]];
		if (y[a[i]]<miny)miny=y[a[i]];
		if (y[a[i]]>maxy)maxy=y[a[i]];
	}
	//printf("%d %d %d %d\n",minx, maxx, miny, maxy);
	if ((maxy-miny)==3) flag=0;
	else if((maxx-minx)==2 && (maxy-miny)==2 && flag1 && !flag2) flag=0;
	else flag=1;
	if (flag ==0) printf("YES");
	else printf("NO");
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i,flag0=0,flagup=0,flagright=0,flagleft=0,flagdown=0;
    char ptrn[10];
     /*for(i=0;i<n;i++){
        ptrn[i]=='-';
     }*/
    scanf("%d\n",&n);
   // printf("n=%d\n",n);
    for(i=0;i<n;i++){
    scanf("%c",&ptrn[i]);
    }
   // printf("%c%c%c%c%c%c%c%c%c%c\n",ptrn[0],ptrn[1],ptrn[2],ptrn[3],ptrn[4],ptrn[5],ptrn[6],ptrn[7],ptrn[8],ptrn[9]);
   // printf("n=%d\n",n);
    for(i=0;i<n;i++){
        if(ptrn[i]=='0'){
            flag0=1;
            break;
        }
    }
    if(flag0==1){
        for(i=0;i<n;i++){
            if(ptrn[i]>='1' && ptrn[i]<='3'){
                printf("YES");
                flag0=2;
                break;
            }
        }
        if(flag0==1){
                printf("NO");
            }
        }
        else{
             //   printf("try=%d\n",n);
             for(i=0;i<n;i++){
               //   printf("try2\n");
                if(ptrn[i]>='1' && ptrn[i]<='3'){
                    flagup=1;
                   //  printf("\n ptrnup[%d]=%c",i,ptrn[i]);

                }
                 if(ptrn[i]=='3' || ptrn[i]=='6' || ptrn[i]=='9'){
                    flagright=1;
                   // printf("\n ptrnrit[%d]=%c",i,ptrn[i]);
                }
                if(ptrn[i]=='1' || ptrn[i]=='4' || ptrn[i]=='7'){
                    flagleft=1;
                  //  printf("\n ptrnlft[%d]=%c",i,ptrn[i]);
                }
                if(ptrn[i]=='7' || ptrn[i]=='9'){
                    flagdown=1;
                  //  printf("\n ptrndwn[%d]=%c",i,ptrn[i]);
                 //   printf("a7eee");
                }
             }
             if(flagdown==1 && flagleft==1 && flagright==1 && flagup==1){
            printf("YES");
           // printf("\n i=%d   up %d down %d left %d right %d",i,flagup,flagdown,flagleft,flagright);
        }
        else{
            printf("NO");
           // printf("\n i=%d   up %d down %d left %d right %d",i,flagup,flagdown,flagleft,flagright);
        }
        }

    return 0;
}

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<limits.h>
char arr[20][20];
int cmp[20];
char numbs[50];
int flag;
int cnt;
int solve(){
int len=strlen(numbs); int i; int k=0;
for(i=0;i<len-1;i++){
int f = arr[numbs[i]-'0'][0]-'0';
int f1= arr[numbs[i]-'0'][1]-'0';
int l = arr[numbs[i+1]-'0'][0]-'0';
int l1 = arr[numbs[i+1]-'0'][1]-'0';

cmp[k++]=l-f;;
cmp[k++]=l1-f1;
}
int x,m;
for(i=0;i<4;i++){
for(x=0;x<3;x++){
flag=1;
if(i==3 && x==0)
continue;
if(i==3 && x==2)
continue;
int t=i;
int t1=x;
for(m=0;m<k;m+=2){
t = t+cmp[m];
t1 = t1+cmp[m+1];
if(t>3 || t<0 || t1>2 || t1<0 || (t==3 && t1==0) || (t==3 && t1==2))
flag=0;;
}
if(flag){
cnt++;
if(cnt==2){
printf("NO");
return;}}
}
}
}
int main(){
int a,b,c,d,e,f,g,h;
strcpy(arr[0],"31");
strcpy(arr[1],"00");
strcpy(arr[2],"01");
strcpy(arr[3],"02");
strcpy(arr[4],"10");
strcpy(arr[5],"11");
strcpy(arr[6],"12");
strcpy(arr[7],"20");
strcpy(arr[8],"21");
strcpy(arr[9],"22");
scanf("%d",&f);
getchar();
gets(numbs);
solve();
if(cnt!=2){
        printf("YES");
}
}

#ifdef ONLINE_JUDGE
    #define NDEBUG 1
#endif
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <math.h>

#define long int64_t
#define fore(i,k,n) for (int _k = (k), _n = (n), i = _k; i <= _n; ++i)
#define forr(i,n,k) for (int _k = (k), _n = (n), i = _n; i >= _k; --i)
#define scani(x) int x; scanf("%d", &x)
#define scans(x) static char x[LEN]; scanf("%s", x)
#define LIST_INIT_CAP 4
#define HASH_INIT_CAP 64
#define HASH_SKIP 11
#define TREE_INIT_CAP 1024
#define TREE_MAX_HEIGHT 64
#define DEQUE_INIT_CAP 1024
#define HEAP_INIT_CAP 1024
#define TAKEN 1
#define EMPTY 0
#define TOMB -1
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))

#define LEN 2004

char va[10][4] = { { -1, -1, -1, 0 },
    { 0, 0, -1, -1 }, { 0, 0, 0, -1}, { -1, 0, 0, -1 },
    { 0, 0, -1, 0 }, { 0, 0, 0, 0}, {-1, 0, 0, 0},
    { 0, -1, -1, 0}, {0, 0, 0,0 }, {-1, -1, 0, 0} };

int main() {
    scani(n);
    scans(str);
    fore (i, 0, n-1) str[i] -= '0';
    fore (j, 0, 3) {
        bool ok = false;
        fore (i, 0, n-1) {
            if (va[str[i]][j] == -1) ok = true;
        }
        if (!ok) { printf("NO"); return 0; }
    }
    printf("YES");

    return 0;
}

#include <stdio.h>
#include <string.h>
#include <malloc.h>

typedef struct {
	int vert, hori;
} vektor;
typedef struct{
	int vert, hori;
} adresa;

adresa br2adr(char a){
	adresa adr;
	if (a == '1') {adr.vert = 0; adr.hori = 0; return adr;}
	if (a == '2') {adr.vert = 0; adr.hori = 1; return adr;}
	if (a == '3') {adr.vert = 0; adr.hori = 2; return adr;}
	if (a == '4') {adr.vert = -1; adr.hori = 0; return adr;}
	if (a == '5') {adr.vert = -1; adr.hori = 1; return adr;}
	if (a == '6') {adr.vert = -1; adr.hori = 2; return adr;}
	if (a == '7') {adr.vert = -2; adr.hori = 0; return adr;}
	if (a == '8') {adr.vert = -2; adr.hori = 1; return adr;}
	if (a == '9') {adr.vert = -2; adr.hori = 2; return adr;}
	if (a == '0') {adr.vert = -3; adr.hori = 1; return adr;}
	/*inace:*/
	adr.hori = adr.vert = -1;
	return adr;
}

char adr2br(adresa adr){
	if (adr.vert == 0 && adr.hori == 0) { return '1';}
	if (adr.vert == 0 && adr.hori == 1) { return '2';}
	if (adr.vert == 0 && adr.hori == 2) { return '3';}
	if (adr.vert == -1 && adr.hori == 0) { return '4';}
	if (adr.vert == -1 && adr.hori == 1) { return '5';}
	if (adr.vert == -1 && adr.hori == 2) { return '6';}
	if (adr.vert == -2 && adr.hori == 0) { return '7';}
	if (adr.vert == -2 && adr.hori == 1) { return '8';}
	if (adr.vert == -2 && adr.hori == 2) { return '9';}
	if (adr.vert == -3 && adr.hori == 1) { return '0';}
	/*inace:*/
	return -1;
}

vektor kretanje(char a, char b){
	vektor vek;
	vek.vert = (br2adr(b).vert-br2adr(a).vert);
	vek.hori = (br2adr(b).hori-br2adr(a).hori);
	return vek;
}

char *proseci(vektor *put, char pocbr, int dimbr){
	/*obavlja setnju po putu zadanom vektorima u polju i vraca
	  telefonski broj (string) koji se dobije*/

	char *broj = NULL;
	char el;
	int i;
	adresa tren;

	broj = (char *) malloc(sizeof(char) * (dimbr + 1));

	broj[0] = pocbr;
	tren = br2adr(pocbr);

	for(i = 1; i < dimbr; i++){

		tren.hori += put[i-1].hori;
		tren.vert += put[i-1].vert;
		el = adr2br(tren);
		if (el == -1) return NULL;
		broj[i] = adr2br(tren);

	}

	broj[i] = '\0';
	/*printf("%s\n", broj);*/
	return broj;

}

int main(){
	int n, i; /*duljina niza brojeva*/
	char str[9+1];
	char trbr;
	char *nbr;
	vektor *put;

	scanf("%d", &n);
	scanf("%s", str);
	/*napravi polje vektora put*/
	put = (vektor *) malloc(sizeof(vektor) * (n-1));
	trbr = str[0];
	for(i = 1; i < n; i++){
		put[i-1] = kretanje(trbr, str[i]);
		trbr = str[i];
	}

	/*printf("\nVektor:\n");
	for(i = 0; i < n-1; i++)
		printf("%2d%2d\n", put[i].vert, put[i].hori);
	printf("\n");*/

	for(i = '0'; i <= '9'; i++){
		nbr = proseci(put, i, n);
		if (nbr != NULL){
			/*printf("%s ", nbr);*/
			if (strcmp(nbr, str) != 0){
				printf("NO");
				free(put);
				free(nbr);
				return 0;
			}
		}
	}

	printf("YES");
	free(put);
	free(nbr);

	return 0;
}

#include<stdio.h>

static int map[10];

int main()
{
    int n;
    scanf("%d", &n);
    getchar();

    while(n--)
    {
        char c;
        c = getchar();

        map[ c - '0' ] = 1;
    }

    int flag = 0;

    if( !(map[1] || map[4] || map[7] || map[0]) ) flag = 1;
    else if( !(map[3] || map[6] || map[9] || map[0]) ) flag = 1;
    else if ( !(map[1]||map[2]||map[3]) ) flag = 1;
    else if(!(map[7] || map[9] || map[0])) flag = 1;
    else if( !(map[1]||map[2]||map[3]||map[4]||
               map[7]) ) flag = 1;
    else if( !(map[1]||map[2]||map[3]||map[6]||
               map[9]) ) flag = 1;
    else if( !(map[1]||map[4]||map[7]||map[8]||
               map[0]) ) flag = 1;
    else if( !(map[3]||map[6]||map[9]||map[8]||
               map[0]) ) flag = 1;

    if(flag == 1) printf("NO\n");
    else printf("YES\n");

    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define SET(a,b) memset(a,b,sizeof(a))
#define scan(n) scanf("%d",&n)
#define print(n) printf("%d\n",n)
#define scanl(n) scanf("%lld",&n)
#define printl(n) printf("%lld\n",n)

//stacks
/*void push(int n,int ar[],int i)
{
        ar[i]=n;
        i++;
}
void pop(int ar[],int i)
{
        if(i>0)
        {
                ar[i-1]=0;
                i--;
        }
}*/

//queues
/*void qpush(int ar[],int val,int head,int tail,int range)
{
        if(head==tail)
        {
                ar[head]=val;
                if(tail+1==range)
                        tail=0;
                else
                        tail++;
        }
        else
        {
                ar[tail]=val;
                if(tail+1==range)
                        tail=0;
                else
                        tail++;
        }
        if(tail==head)
        {
                if(head+1==range)
                        head=0;
                else
                        head++;
        }
}

void qpop(int head,int tail,int range)
{
        if(head+1==range)
                head=0;
        else
                head++;
}*/

//pow
/*int fun(int a,int b,int m)
{
        if(b==0)
                return 1;
        int d,x;
        d=fun(a,b/2,m);
        x=(d*d)%m;
        if(b%2==0)
                return x;
        else
                return (x*a%m)%m;
}
*/
//bst
/*typedef struct tree
{
        int val;
        struct tree *l;
        struct tree *r;
}node;
//node *head;
node *insert(int x,node *root)
{
        if(root==NULL)
        {
                root=(node *)malloc(sizeof(node));
                root->val=x;
        }
        else
        {
                if(x<=root->val)
                {
                        if(root->l==NULL)
                        {
                                root->l=(node *)malloc(sizeof(node));
                                root->l->val=x;
                        }
                        else
                                root->l=insert(x,root->l);
                }
                else
                {
                        if(root->r==NULL)
                        {
                                root->r=(node *)malloc(sizeof(node));
                                root->r->val=x;
                        }
                        else
                        {
                                root->r=insert(x,root->r);
                        }
                }
        }
        return root;
}
node *find(int x,node *root)
{
        if(root==NULL)
        {
                return 0;
        }
        else
        {
                if(x==root->val)
                        return root;
                else if(x<root->val)
                {
                        if(root->l==NULL)
                        {
                                return 0;
                        }
                        else
                        {
                                find(x,root->l);
                        }
                }
                else
                {
                        if(root->r==NULL)
                        {
                                return 0;
                        }
                        else
                        {
                                find(x,root->r);
                        }
                }
        }
}

void inorder(node *root)
{
        if(root==NULL)
        {
                return;
        }
        if(root->l==NULL)
        {
                printf("%d",root->val);
                if(root->r==NULL)
                        return;
                else
                        inorder(root->r);
        }
        else
        {
                inorder(root->l);
                printf("%d",root->val);
                if(root->r==NULL)
                        return;
                else
                        inorder(root->r);
        }
}
void preorder(node *root)
{
        if(root==NULL)
        {
                return;
        }
        else
        {
                printf("%d",root->val);
                preorder(root->l);
                preorder(root->r);
        }
}

void postorder(node *root)
{
        if(root==NULL)
        {
                return;
        }
        else
        {
                postorder(root->l);
                postorder(root->r);
                printf("%d",root->val);
        }
}
*/
//adjacency list
/*typedef struct ll
{
        int val;
        struct ll *next;
}nd;

//n *ar[100001];
void insert(int a,int b)
{
        if(ar[a]==NULL)
        {
                ar[a]=(nd *)malloc(sizeof(nd));
                ar[a]->val=b;
                ar[a]->next=NULL;
        }
        else
        {
                nd *temp=(nd *)malloc(sizeof(nd)),*t;
                temp->val=b;
                temp->next=ar[a];
                ar[a]=temp;
        }
}

//dfs
//int state[100001];
void dfs(int a)
{
        state[a]=1;
        count++;
        nd *temp=ar[a];
        while(temp!=NULL)
        {
                if(state[temp->val]!=1)
                        dfs(temp->val);
                temp=temp->next;
        }
        return;
}*/

//dijkstra + heaps
/*typedef struct ll2
{
        int val;
        int weight;
        struct ll2 *next;
}nde;
*/
//nde *ar[500005];
//int state[500005];

/*void insert(int a,int b,int w)//insert to adjacency list
{
	if(ar[a]==NULL)
  	{
 	 	ar[a]=(node *)malloc(sizeof(node));
 	 	ar[a]->val=b;
 	 	ar[a]->weight=w;
 	 	ar[a]->next=NULL;
 	}
 	else
  	{
  		node *temp=(node *)malloc(sizeof(node)),*t;
  		temp->val=b;
  		temp->weight=w;
  		temp->next=ar[a];
  		ar[a]=temp;
  	}
}*/

//int pt[500005],d[500005];
//int heap[500005][2];
//int ptr;
/*void decpty(int val,int pos)//decrease priority
{
        heap[pos][0]=val;
        int x=pos;
        while(x>0)
        {
                if(heap[x][0]>=heap[x/2][0])
                        break;
                else
                {
                        pt[heap[x][1]]=x/2;
                        pt[heap[x/2][1]]=x;
                        int temp=heap[x][0],t2=heap[x][1];
                        heap[x][0]=heap[x/2][0];
                        heap[x][1]=heap[x/2][1];
                        heap[x/2][0]=temp;
                        heap[x/2][1]=t2;
                        x=x/2;
                }
        }
}

void hinsert(int val,int val2)//insert to heap
{
        heap[ptr][0]=val;
        heap[ptr][1]=val2;
        pt[val2]=ptr;
        int x=ptr;
        ptr++;
        while(x>0)
        {
                if(heap[x][0]>=heap[x/2][0])
                        break;
                else
                {
                        pt[heap[x][1]]=x/2;
                        pt[heap[x/2][1]]=x;
                        int temp=heap[x][0],t2=heap[x][1];
                        heap[x][0]=heap[x/2][0];
                        heap[x][1]=heap[x/2][1];
                        heap[x/2][0]=temp;
                        heap[x/2][1]=t2;
                        x=x/2;
                }
        }
}

int hdeletemin()//delete min elem from heap
{
        int ret;
        ret=heap[1][1];
        pt[heap[1][1]]=-1;
        pt[heap[ptr-1][1]]=1;
        heap[1][0]=heap[ptr-1][0];
        heap[1][1]=heap[ptr-1][1];
        ptr--;
        int x=1;
        while(x<ptr)
        {
                if(2*x+1>=ptr)
                {
                        if(2*x<ptr)
                        {
                                if(heap[2*x][0]<heap[x][0])
                                {
                                        pt[heap[x][1]]=2*x;
                                        pt[heap[2*x][1]]=x;
                                        int temp=heap[x][0];
                                        int temp2=heap[x][1];
                                        heap[x][0]=heap[2*x][0];
                                        heap[x][1]=heap[2*x][1];
                                        heap[2*x][0]=temp;
                                        heap[2*x][1]=temp2;
                                        x=2*x;
                                }
                                else
                                        break;
                        }
                        else
                                break;
                }
                else if(heap[x][0]<=heap[2*x][0] && heap[x][0]<=heap[2*x+1][0])
                        break;
                else
                {
                        if(heap[2*x][0]<=heap[2*x+1][0])
                        {
                                pt[heap[x][1]]=2*x;
                                pt[heap[2*x][1]]=x;
                                int temp=heap[x][0];
                                int temp2=heap[x][1];
                                heap[x][0]=heap[2*x][0];
                                heap[x][1]=heap[2*x][1];
                                heap[2*x][0]=temp;
                                heap[2*x][1]=temp2;
                                x=2*x;
                        }
                        else
                        {
                                pt[heap[x][1]]=2*x+1;
                                pt[heap[2*x+1][1]]=x;
                                int temp=heap[x][0];
                                int temp2=heap[x][1];
                                heap[x][0]=heap[2*x+1][0];
                                heap[x][1]=heap[2*x+1][1];
                                heap[2*x+1][0]=temp;
                                heap[2*x+1][1]=temp2;
                                x=2*x+1;
                        }
                }
        }
        return ret;
}

void dikstra(int u,int v)
{
        while(ptr!=1)
        {
                int v=hdeletemin();
                node *temp=ar[v];
                while(temp!=NULL)
                {
                        int w=temp->val;
                        if(d[v]+temp->weight < d[w])
                        {
                                d[w]=d[v]+temp->weight;
                                decpty(d[w],pt[w]);
                        }
                        temp=temp->next;
                }
        }
}*/

/*int main()
{
  	int n,m,u,v,w,i;
  	scanf("%d%d",&n,&m);
  	for(i=0;i<=n;i++)
  	state[i]=0;
  	while(m--)
  	{
  		scanf("%d%d%d",&u,&v,&w);
  		insert(u,v,w);
  	}
  	scanf("%d%d",&u,&v);
  	ptr=1;
  	hinsert(0,u);
  	d[u]=0;
  	for(i=1;i<=n;i++)
  	{
  		if(i!=u)
  		{
  			hinsert(1000000000,i);
  			d[i]=1000000000;
  		}
  	}
  	dikstra(u,v);
  	if(d[v]==1000000000)
  	printf("NO\n");
  	else
  	printf("%d\n",d[v]);
  	return 0;
}*/

//kruskal + dsu

//int dsu[N];
/*int find(int x)
{
        if(dsu[x]==x)return x;
        return dsu[x] = find(dsu[x]);
}

void Union(int a,int b)
{
        if(a==b)
                return;
        dsu[a] = b;
}

typedef struct edge
{
        int u,v;
        int weight;
}edge;
*/
//edge e[N];
/*int cmp(const void *a,const void *b)
{
	return ((edge*)a)->weight - ((edge*)b)->weight;
}*/
/*int main()
{
  	int i;
  	int n,m;
  	scanf("%d %d\n",&n,&m);
  	for(i=0;i<m;i++)
	scanf("%d %d %d",&e[i].u,&e[i].v,&e[i].weight);
	for(i=1;i<=n;i++)
	dsu[i]=i;
	qsort(e,m,sizeof(edge),cmp);
	long long int sum=0;
	for(i=0;i<m;i++)
	{
	 	int a,b;
	 	if((a=find(e[i].u))!=(b=find(e[i].v)))
	 	{
	 		sum+=e[i].weight;
	  		Union(a,b);
	  	}
	}
	printf("%lld\n",sum);
	return 0;
}*/

//max
/*int max(int a,int b)
{
    if(a>b)
        return a;
    else
        return b;
}
*/
//qsort

/*int cmpfunc(const void *a,const void *b)
{
        return (*(int *)a - *(int *)b);
}*/
//qsort(ar,n,sizeof(int),cmpfunc);

//-------------------------------------------------------------------------------------------------------------------------------------

int main()
{
       char s[100];
       int n,ans,i,ar[100];
       int right,left,top,bottom;
       right=1;
       left=1;
       top=1;
       bottom=1;
       scan(n);
       scanf("%s",s);
       for(i=0;i<n;i++)
       {
              ar[i]=s[i]-'0';
       }
       for(i=0;i<n;i++)
       {
              if(ar[i]==3 || ar[i]==6 || ar[i]==9)
                     right=0;
              if(ar[i]==1 || ar[i]==4 || ar[i]==7)
                     left=0;
              if(ar[i]==1 || ar[i]==2 || ar[i]==3)
                     top=0;
              if(ar[i]==7 || ar[i]==0 || ar[i]==9)
                     bottom=0;
       }
       int c1=1;
       for(i=0;i<n;i++)
       {
              if(ar[i]==0)
                     c1=0;
       }
       if(top==0 && c1==0)
              printf("YES\n");
       else if(left==1 || right==1 || top==1 || bottom==1)
              printf("NO\n");
       else
              printf("YES\n");
       return 0;
}

#include <stdio.h>

int n, visit[10], res;

int ans() {
    if(visit[1]==0 && visit[2]==0 && visit[3]==0) return 1;
    if(visit[7]==0 && visit[9]==0 && visit[0]==0) return 1;
    if(visit[0]==1) return 0;
    if(visit[1]==0 && visit[4]==0 && visit[7]==0) return 1;
    if(visit[3]==0 && visit[6]==0 && visit[9]==0) return 1;
    return 0;
}

int main() {
    scanf("%d", &n);
    for(int i=0;i<n;i++) {
        int digit;
        scanf("%1d", &digit);
        visit[digit]=1;
    }
    res=ans();
    if(res==0) puts("YES");
    else puts("NO");
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct pv{
	int x;
	int y;
};

int main()
{
	struct pv num[10],route[10];
	num[1].x=1;
	num[1].y=1;

	num[2].x=2;
	num[2].y=1;

	num[3].x=3;
	num[3].y=1;

	num[4].x=1;
	num[4].y=2;

	num[5].x=2;
	num[5].y=2;

	num[6].x=3;
	num[6].y=2;

	num[7].x=1;
	num[7].y=3;

	num[8].x=2;
	num[8].y=3;

	num[9].x=3;
	num[9].y=3;

	num[0].x=2;
	num[0].y=4;

	int  n,key2,key1,i,j;
	char str[10];
	//hardcoding
	scanf("%d",&n);
	scanf("%s",str);

	for(i=1;i<n;i++)
	{

		key2=str[i]  - '0';
		key1=str[i-1]- '0';

		route[i-1].x = num[key2].x-num[key1].x;
		route[i-1].y = num[key2].y-num[key1].y;
		//printf("%d %d\n",route[i-1].x, route[i-1].y);

	}

	struct pv src,dest;
	int fail=0,cnt=0;

	for(i=0;i<=9;i++)
	{
		//printf("%d %d\n",route[i].x, route[i].y);
		if(i == str[0]-'0')
		{
			continue;
		}
		src.x=num[i].x;
		src.y=num[i].y;
		fail=0;
		for(j=1;j<n;j++)
		{
			dest.x=src.x+route[j-1].x;
			dest.y=src.y+route[j-1].y;
			//printf("%d %d %d\n",dest.x, dest.y,j);

			if(!(dest.x<=3 && dest.x>=1 && dest.y>=1 && dest.y<=3))
			{

				if(!(dest.x==2&&dest.y==4))
				{	//printf("break\n");
					fail=1;
					break;
				}

			}

			src.x=dest.x;
			src.y=dest.y;

		}
		if(j==n && fail==0)// we were able to find the number
		{
			//printf("success\n");
			cnt++;
			break;
		}

	}
	if(cnt>0)
	{
		printf("NO");
	}
	else
	{
		printf("YES");
	}

  return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int d[10];

int main() {
	int n;
	char s[10];
	scanf("%d%s", &n, s);
	for(int i=0 ; i<n ; i++) {
		d[s[i] - '0'] = 1;
	}
	if(!d[1] && !d[2] && !d[3]) {
		printf("NO");
		return 0;
	}
	if(d[0]) {
		printf("YES");
		return 0;
	}
	if(!d[1] && !d[4] && !d[7]) {
		printf("NO");
		return 0;
	}
	if(!d[3] && !d[6] && !d[9]) {
		printf("NO");
		return 0;
	}
	if(d[7] || d[9]) {
		printf("YES");
		return 0;
	}
	printf("NO");
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

static int arr[4][3];

void setnum(char ch);

int check_left(){
	return !(arr[0][0] || arr[1][0] || arr[2][0] || arr[3][1]);
}

int check_right() {
	return !(arr[0][2] || arr[1][2] || arr[2][2] || arr[3][1]);
}

int check_top() {
	return !(arr[0][0] || arr[0][1] || arr[0][2]);
}

int check_bottom() {
	return !(arr[2][0] || arr[3][1] || arr[2][2]);
}

int main()
{
	char str[10];
	int r, c, i, n;
	int haszero = 0;

	scanf("%d", &n);
	scanf("%s", str);

	for (i = 0; i < n; i++) {
		setnum(str[i]);
		if(str[i] == '0') haszero = 1;
	}

    if(check_left() || check_right() || check_top() || check_bottom()) printf("NO");
    else printf("YES");

    return 0;
}

void setnum(char ch) {
    switch (ch) {
		case '0': arr[3][1] = ch; return;
		case '1': arr[0][0] = ch; return;
		case '2': arr[0][1] = ch; return;
		case '3': arr[0][2] = ch; return;
		case '4': arr[1][0] = ch; return;
		case '5': arr[1][1] = ch; return;
		case '6': arr[1][2] = ch; return;
		case '7': arr[2][0] = ch; return;
		case '8': arr[2][1] = ch; return;
		case '9': arr[2][2] = ch; return;
    }
}

# include <stdio.h>

int main() {
	int A[4][4];
	int num = 1;
	int i,j,k;
	for(i=0;i<3;i++){
		for(j=0;j<3;j++){
			A[i][j] = num;
			num++;
		}
	}

	A[3][0] = -1;
	A[3][1] = 0;
	A[3][2] = -1;

	int n;
	scanf("%d",&n);
	char arr[n];
	int Arr[n];
	scanf("%s",arr);
	int I[n];
	int J[n];
	for(i=0;i<n;i++){
		Arr[i] = (int) arr[i] - '0';
	}
	int temp;
	for(i=0;i<n;i++){
		temp = Arr[i];
		for(j=0;j<4;j++){
			for(k=0;k<3;k++){
				if(A[j][k]==temp){
					I[i] = j;
					J[i] = k;
				}
			}
		}
	}

	for(i=0;i<n-1;i++){
		I[i] = I[i+1] - I[i];
		J[i] = J[i+1] - J[i];
	}

	int count = 0;
	for(i=0;i<4;i++){
		for(j=0;j<3;j++){
			if(A[i][j]!=-1){
				int tempi = i;
				int tempj = j;
				int flag=1;
				for (k = 0; k < n-1; k++){
					tempi = tempi + I[k];
					tempj = tempj + J[k];
					if (tempi >= 0 && tempi <= 2){
						if(tempj >= 0 && tempj <= 2){
							;
						}else{
							flag=0;
							break;
						}
					}else{
						if(tempi==3 && tempj==1){
							;
						}else{
							flag=0;
							break;
						}
					}
				}
				if(flag==1){
					count++;
				}
			}
		}
	}
	if(count==1){
		printf("YES\n");
	}else{
		printf("NO\n");
	}

	return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int n, phone[10], number[10];
int main()
{
	scanf("%d",&n);
	for(int a=1;a<=n;a++){
	scanf("%1d",&phone[a]);
	number[phone[a]]++;}
	if(number[0])
	{
		if(number[1]||number[2]||number[3])
		printf("YES");
		else printf("NO");
	}
	else if(number[7])
	{
		if(number[3]||((number[2]||number[1])&&(number[6]||number[9])))
		printf("YES");
		else printf("NO");
	}
	else if(number[9])
	{
		if(number[1]||((number[2]||number[3])&&(number[4]||number[7])))
		printf("YES");
		else printf("NO");
	}
	else printf("NO");
}

#include<stdio.h>
#include<string.h>

int main()	{

	char contact[100];
	char two_test_key[]={'1','2','3'};
	char two_test_key_follows[][10]={{'0','9'}, {'0'}, {'0','7'}};
	char group_test_key[]={'4','6','2'};
	char group_test_follows[][5][10]={
										{{'3','9'},{'9','2'}},
										{{'1','7'},{'7','2'}},
										{{'7','9'},{'7','6'},{'9','4'}},
									};
	int i,j,k,n=0;

	scanf("%d",&i);
	scanf("%s",contact);
	for(i=0;i<3;i++)	{
		if(strchr(contact,two_test_key[i]))	{
			if(strchr(contact,two_test_key_follows[i][0]))	{
				puts("YES");
				return 0;
			}
			if(i-1 && strchr(contact,two_test_key_follows[i][1]))	{
				puts("YES");
				return 0;
			}
		}
	}
	for(i=0;i<3;i++)	{
		if(strchr(contact, group_test_key[i]))	{
			k=2;	if(i>1) k=3;
			for(j=0;j<k;j++)	{
				if(strchr(contact, group_test_follows[i][j][0]) && strchr(contact, group_test_follows[i][j][1]))	{
					puts("YES");
					return 0;
				}
			}
		}
	}

	puts("NO");

	return 0;
}

#include<stdio.h>
#include<string.h>

int main()	{

	char contact[100];
	char two_test_key[]={'1','2','3'};
	char two_test_key_follows[][100]={{'0','9'}, {'0'}, {'0','7'}};
	char group_test_key[]={'4','6','2'};
	char group_test_follows[][20][100]={
										{{'3','9'},{'9','2'}},
										{{'1','7'},{'7','2'}},
										{{'7','9'},{'7','6'},{'9','4'}},
									};
	long long i,j,k;

	scanf("%d",&i);
	scanf("%s",contact);
	for(i=0;i<3;i++)	{
		if(strchr(contact,two_test_key[i]))	{
			if(strchr(contact,two_test_key_follows[i][0]))	{
				puts("YES");
				return 0;
			}
			if(i-1 && strchr(contact,two_test_key_follows[i][1]))	{
				puts("YES");
				return 0;
			}
		}
	}
	for(i=0;i<3;i++)	{
		if(strchr(contact, group_test_key[i]))	{
			k=2;	if(i>1) k=3;
			for(j=0;j<k;j++)	{
				if(strchr(contact, group_test_follows[i][j][0]) && strchr(contact, group_test_follows[i][j][1]))	{
					puts("YES");
					return 0;
				}
			}
		}
	}

	puts("NO");

	return 0;
}

#include <stdio.h>
#include <stdlib.h>

char kb[5][5] = {"123","456","789","x0x"};
int moves[10][3];
int n;
char num[16];

int findx(char c){
	int x,y;
	for(x=0;x<4;x++)
		for(y=0;y<3;y++)
			if(kb[x][y] == c)
				return x;
}

int findy(char c){
	int x,y;
	for(x=0;x<4;x++)
		for(y=0;y<3;y++)
			if(kb[x][y] == c)
				return y;
}

int move(int x, int y){
	int i;
	//printf("\n:");
	for(i=0;i<n;i++){
		//printf("%d %d\n",x,y);
		x+=moves[i][0];
		y+=moves[i][1];
		if(x<0 || x>3 || y<0 || y>2)
			return 0;
		if(kb[x][y] == 'x')
			return 0;
	}
	return 1;
}

int main(){

	scanf("%d",&n);
	scanf("%s",&num);

	int i,cx,cy,nx,ny;
	cx = findx(num[0]);
	cy = findy(num[0]);
	for(i=1;i<n;i++){
		nx = findx(num[i]);
		ny = findy(num[i]);

		moves[i-1][0] = nx - cx;
		moves[i-1][1] = ny - cy;

		//printf("%d %d\n",nx - cx,ny - cy);

		cx = nx;
		cy = ny;

	}

	int x,y;
	for(x=0;x<4;x++)
		for(y=0;y<3;y++)
			if(kb[x][y]!='x' && kb[x][y]!=num[0] && move(x,y)){
				printf("NO\n");
				return 0;
			}

	printf("YES\n");

	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#define max 9

bool belongs(char Phone[max] , int N , char Key[max], int M){

    int i=0,k;
    while (i<N){
        k = 0;
        while ((k<M) && ( Phone[i] != Key[k] )) k++;
        if (k<M) i++; else return false;
    }
    return true;
}

void verifyUnique(char Phone[max] , int N ){
    char arr1[max] = {'1','2','4','5','7','8'};
    char arr2[max] = {'4','5','7','8','0'};
    char arr3[max] = {'4','5','6','7','8','9','0'};
    char arr4[max] = {'5','6','8','9','0'};
    char arr5[max] = {'2','3','5','6','8','9'};
    char arr6[max] = {'2','3','5','6','9'};
    char arr7[max] = {'1','2','3','4','5','6','8'};
    char arr8[max] = {'1','2','4','5','7'};
    if ( (belongs(Phone,N,arr1,6)) ||
         (belongs(Phone,N,arr2,5)) ||
         (belongs(Phone,N,arr3,7)) ||
         (belongs(Phone,N,arr4,5)) ||
         (belongs(Phone,N,arr5,6)) ||
         (belongs(Phone,N,arr6,5)) ||
         (belongs(Phone,N,arr7,7)) ||
         (belongs(Phone,N,arr8,5)) ){

            printf("NO");

        } else printf("YES");

    return;

}

void readNumber(char Phone[max] , int N){
    scanf("%*c");
    int i;
    for(i = 0;i < N;i++) scanf("%c",&Phone[i]);
    return;
}

int main() {

    int N;
    scanf("%d",&N);
    char Phone[max];
    readNumber(Phone,N);
    verifyUnique(Phone,N);

    return (EXIT_SUCCESS);
}

#include <stdio.h>

int arr[9], n;

void input();
void solve();

int exist(int);

int main(){
	input();
	solve();

	return 0;
}

void input(){
	scanf("%d", &n);
	for (int i=0; i < n; i++)
		scanf("%1d", &arr[i]);
}

void solve(){
	if (exist(0) && (exist(1) || exist(2) || exist(3))) printf("YES\n");
	else if (exist(7) && (exist(1) || exist(2) || exist(3)) && (exist(3) || exist(6) || exist(9))) printf("YES\n");
	else if (exist(9) && (exist(1) || exist(2) || exist(3)) && (exist(1) || exist(4) || exist(7))) printf("YES\n");
	else printf("NO\n");
}

int exist(int a){
	int index=0;
	for (int i=0; i< n; i++)
		if (a==arr[i])
			index++;

	if (index) return 1;
	else return 0;
}

#include <stdio.h>

const int i[10] = {3, 0, 0, 0, 1, 1, 1, 2, 2, 2};
const int j[10] = {1, 0, 1, 2, 0, 1, 2, 0, 1, 2};

int di[10][10];
int dj[10][10];

inline int isvalid(int ci, int cj) {
	int k;
	for (k = 0; k < 10; k++)
		if (i[k] == ci && j[k] == cj)
			return 1;
	return 0;
}

int main(void) {
	int k;
	int n;
	char str[10];
	int from, to;
	int num, cnt;

	for (from = 0; from < 10; from++)
		for (to = 0; to < 10; to++) {
			di[from][to] = i[to] - i[from];
			dj[from][to] = j[to] - j[from];
		}

	scanf("%d %s", &n, str);

	cnt = 0;
	for (num = 0; num < 10; num++) {
		int ci = i[num], cj = j[num];
		for (k = 0; k < n - 1; k++) {
			ci += di[str[k] - '0'][str[k + 1] - '0'];
			cj += dj[str[k] - '0'][str[k + 1] - '0'];
			if (!isvalid(ci, cj))
				break;
		}

		cnt += k == n - 1;
	}

	puts(cnt == 1 ? "YES" : "NO");

	return 0;
}

#include <stdio.h>
#include <string.h>

int main() {
	int test;
	char inp[11];
	int inp2[11];
	scanf ("%d\n",&test);
	gets(inp);
	memset (inp2, 0, sizeof(inp2));
	int x, check=1;
	for (x=0;x<test;x++){
		int lala = inp[x]-'0';
		inp2[lala]++;

	}

	if (!(inp2[1]>0||inp2[4]>0||inp2[7]>0||inp2[0]>0)) {
		printf ("NO\n");
	}
	else if (!(inp2[3]>0||inp2[6]>0||inp2[9]>0||inp2[0]>0)) {
		printf("NO\n");
	}
	else if (!(inp2[1] > 0 || inp2[2]>0 || inp2[3]>0)) {
		printf("NO\n");
	}
	else if (!(inp2[7] >0 || inp2[0] >0 ||inp2[9]>0)) {
		printf("NO\n");
	}
	else {
		printf("YES\n");
	}
}

#include <stdio.h>

int main() {
	static char s[10];
	int n, i, yes1, yes2, yes3, yes4;

	scanf("%d%s", &n, s);
	yes1 = yes2 = yes3 = yes4 = 0;
	for (i = 0; i < n; i++)
		if (s[i] == '1')
			yes1 = yes2 = 1;
		else if (s[i] == '2')
			yes2 = 1;
		else if (s[i] == '3')
			yes2 = yes3 = 1;
		else if (s[i] == '4')
			yes1 = 1;
		else if (s[i] == '6')
			yes3 = 1;
		else if (s[i] == '7')
			yes1 = yes4 = 1;
		else if (s[i] == '9')
			yes3 = yes4 = 1;
		else if (s[i] == '0')
			yes1 = yes3 = yes4 = 1;
	printf(yes1 && yes2 && yes3 && yes4 ? "YES\n" : "NO\n");
	return 0;
}

#include <stdio.h>

int flag[10];

int main(void) {
	int n;
	char c;
	scanf("%d\n", &n);

	while (n-- > 0) {
		scanf("%c", &c);
		flag[c - '0'] = 1;
	}

	if (flag[1] && flag[9] ||
		flag[3] && flag[7] ||
		flag[0] && flag[1] ||
		flag[0] && flag[2] ||
		flag[0] && flag[3] ||
		flag[1] && flag[6] && flag[7] ||
		flag[3] && flag[4] && flag[9] ||
		flag[7] && flag[2] && flag[9] ||
		flag[7] && flag[6] && flag[2] ||
		flag[2] && flag[4] && flag[9])
	{
		printf("YES");
	}
	else
		printf("NO");

	return 0;
}

#include <stdio.h>

int flag[10];

int main(void) {
	int n;
	char c;
	scanf("%d\n", &n);

	while (n-- > 0) {
		scanf("%c", &c);
		flag[c - '0'] = 1;
	}

	if (flag[1] && flag[9] ||
		flag[3] && flag[7] ||
		flag[0] && flag[1] ||
		flag[0] && flag[2] ||
		flag[0] && flag[3] ||
		flag[1] && flag[6] && flag[7] ||
		flag[3] && flag[4] && flag[9])
	{
		printf("YES");
	}
	else
		printf("NO");

	return 0;
}

#include <stdio.h>

int flag[10];

int main(void) {
	int n;
	char c;
	scanf("%d\n", &n);

	while (n-- > 0) {
		scanf("%c", &c);
		flag[c - '0'] = 1;
	}

	if (flag[1] && flag[9] ||
		flag[3] && flag[7] ||
		flag[0] && flag[1] ||
		flag[0] && flag[2] ||
		flag[0] && flag[3] ||
		flag[1] && flag[6] && flag[7] ||
		flag[3] && flag[4] && flag[9] ||
		flag[7] && flag[2] && flag[9])
	{
		printf("YES");
	}
	else
		printf("NO");

	return 0;
}

#include <stdio.h>

int flag[10];

int main(void) {
	int n;
	char c;
	scanf("%d\n", &n);

	while (n-- > 0) {
		scanf("%c", &c);
		flag[c - '0'] = 1;
	}

	if (flag[1] && flag[9] ||
		flag[3] && flag[7] ||
		flag[0] && flag[1] ||
		flag[0] && flag[2] ||
		flag[0] && flag[3])
	{
		printf("YES");
	}
	else
		printf("NO");

	return 0;
}

#include <stdio.h>

int flag[10];

int main(void) {
	int n;
	char c;
	scanf("%d\n", &n);

	while (n-- > 0) {
		scanf("%c", &c);
		flag[c - '0'] = 1;
	}

	if (flag[1] && flag[9] ||
		flag[3] && flag[7] ||
		flag[0] && flag[1] ||
		flag[0] && flag[2] ||
		flag[0] && flag[3] ||
		flag[1] && flag[6] && flag[7] ||
		flag[3] && flag[4] && flag[9] ||
		flag[7] && flag[2] && flag[9] ||
		flag[1] && flag[7] && flag[8] ||
		flag[3] && flag[9] && flag[8])
	{
		printf("YES");
	}
	else
		printf("NO");

	return 0;
}

#include <stdio.h>
#include <stdlib.h>
int main(){
	int x[10]={2,1,2,3,1,2,3,1,2,3};
	int y[10]={4,1,1,1,2,2,2,3,3,3};
	int flag,n,a[10],i,flag1=0;;
	scanf("%d ",&n);
	char c;
	for(i=0;i<n;i++){
		scanf("%c",&c);
		a[i]=c-'0';
		if(a[i]==7 || a[i]==9)flag1=1;
	}
	int minx=4,maxx=0,miny=5,maxy=0;
	for(i=0;i<n;i++){
		if (x[a[i]]<minx)minx=x[a[i]];
		if (x[a[i]]>maxx)maxx=x[a[i]];
		if (y[a[i]]<miny)miny=y[a[i]];
		if (y[a[i]]>maxy)maxy=y[a[i]];
	}
	//printf("%d %d %d %d\n",minx, maxx, miny, maxy);
	if ((maxy-miny)==3) flag=0;
	else if((maxx-minx)==2 && (maxy-miny)==2 && flag1) flag=0;
	else flag=1;
	if (flag ==0) printf("YES");
	else printf("NO");
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
int main(){
	int x[10]={2,1,2,3,1,2,3,1,2,3};
	int y[10]={4,1,1,1,2,2,2,3,3,3};
	int flag,n,a[10],i;
	scanf("%d ",&n);
	char c;
	for(i=0;i<n;i++){
		scanf("%c",&c);
		a[i]=c-'0';
	}
	int minx=4,maxx=0,miny=5,maxy=0;
	for(i=0;i<n;i++){
		if (x[a[i]]<minx)minx=x[a[i]];
		if (x[a[i]]>maxx)maxx=x[a[i]];
		if (y[a[i]]<miny)miny=y[a[i]];
		if (y[a[i]]>maxy)maxy=y[a[i]];
	}
	//printf("%d %d %d %d\n",minx, maxx, miny, maxy);
	if((maxx-minx)==2) flag=0;
	else if ((maxy-miny)==3) flag=0;
	else{
		if((maxx-minx)==1){
			if ((maxy-miny)==2) flag=0;
		}
		else flag =1;
	}
	if (flag ==0) printf("YES");
	else printf("NO");
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
int main(){
	int x[10]={2,1,2,3,1,2,3,1,2,3};
	int y[10]={4,1,1,1,2,2,2,3,3,3};
	int flag,n,a[10],i;
	scanf("%d ",&n);
	char c;
	for(i=0;i<n;i++){
		scanf("%c",&c);
		a[i]=c-'0';
	}
	int minx=4,maxx=0,miny=5,maxy=0;
	for(i=0;i<n;i++){
		if (x[a[i]]<minx)minx=x[a[i]];
		if (x[a[i]]>maxx)maxx=x[a[i]];
		if (y[a[i]]<miny)miny=y[a[i]];
		if (y[a[i]]>maxy)maxy=y[a[i]];
	}
	//printf("%d %d %d %d\n",minx, maxx, miny, maxy);
	if((maxx-minx)==2) flag=0;
	else if ((maxy-miny)==3) flag=0;
	else{
		if((maxx-minx)==1){
			if ((maxy-miny)==2) flag=0;
		}
		else flag =1;
	}
	if (flag ==0) printf("YES\n");
	else printf("NO\n");
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i,flag0=0,flagup=0,flagright=0,flagleft=0,flagdown=0;
    char ptrn[10];
     /*for(i=0;i<n;i++){
        ptrn[i]=='-';
     }*/
    scanf("%d\n",&n);
   // printf("n=%d\n",n);
    for(i=0;i<n;i++){
    scanf("%c",&ptrn[i]);
    }
   // printf("%c%c%c%c%c%c%c%c%c%c\n",ptrn[0],ptrn[1],ptrn[2],ptrn[3],ptrn[4],ptrn[5],ptrn[6],ptrn[7],ptrn[8],ptrn[9]);
   // printf("n=%d\n",n);
    for(i=0;i<n;i++){
        if(ptrn[i]=='0'){
            flag0=1;
            break;
        }
    }
    if(flag0==1){
        for(i=0;i<n;i++){
            if(ptrn[i]>='1' && ptrn[i]<='3'){
                printf("YES0");
                flag0=2;
                break;
            }
        }
        if(flag0==1){
                printf("NO0");
            }
        }
        else{
             //   printf("try=%d\n",n);
             for(i=0;i<n;i++){
               //   printf("try2\n");
                if(ptrn[i]>='1' && ptrn[i]<='3'){
                    flagup=1;
                   //  printf("\n ptrnup[%d]=%c",i,ptrn[i]);

                }
                 if(ptrn[i]=='3' || ptrn[i]=='6' || ptrn[i]=='9'){
                    flagright=1;
                   // printf("\n ptrnrit[%d]=%c",i,ptrn[i]);
                }
                if(ptrn[i]=='1' || ptrn[i]=='4' || ptrn[i]=='7'){
                    flagleft=1;
                  //  printf("\n ptrnlft[%d]=%c",i,ptrn[i]);
                }
                if(ptrn[i]=='7' || ptrn[i]=='9'){
                    flagdown=1;
                  //  printf("\n ptrndwn[%d]=%c",i,ptrn[i]);
                 //   printf("a7eee");
                }
             }
             if(flagdown==1 && flagleft==1 && flagright==1 && flagup==1){
            printf("YES");
           // printf("\n i=%d   up %d down %d left %d right %d",i,flagup,flagdown,flagleft,flagright);
        }
        else{
            printf("NO");
           // printf("\n i=%d   up %d down %d left %d right %d",i,flagup,flagdown,flagleft,flagright);
        }
        }

    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i,flag0=0,flagup=0,flagright=0,flagleft=0,flagdown=0;
    char ptrn[10];
     /*for(i=0;i<n;i++){
        ptrn[i]=='-';
     }*/
    scanf("%d\n",&n);
   // printf("n=%d\n",n);
    for(i=0;i<n;i++){
    scanf("%c",&ptrn[i]);
    }
   // printf("%c%c%c%c%c%c%c%c%c%c\n",ptrn[0],ptrn[1],ptrn[2],ptrn[3],ptrn[4],ptrn[5],ptrn[6],ptrn[7],ptrn[8],ptrn[9]);
   // printf("n=%d\n",n);
    for(i=0;i<n;i++){
        if(ptrn[i]=='0'){
            flag0=1;
            break;
        }
    }
    if(flag0==1){
        for(i=0;i<n;i++){
            if(ptrn[i]>='1' && ptrn[i]<='3'){
                printf("YES");
                flag0=2;
                break;
            }
        }
        if(flag0==1){
                printf("NO");
            }
        }
        else{
             //   printf("try=%d\n",n);
             for(i=0;i<n;i++){
               //   printf("try2\n");
                if(ptrn[i]>='1' && ptrn[i]<='3'){
                    flagup=1;
                }
                 if(ptrn[i]=='3' || ptrn[i]<='6' || ptrn[i]<='9'){
                    flagright=1;
                }
                if(ptrn[i]=='1' || ptrn[i]<='4' || ptrn[i]<='7'){
                    flagleft=1;
                }
                if(ptrn[i]=='7' || ptrn[i]<='9'){
                    flagdown=1;
                 //   printf("a7eee");
                }
             }
             if(flagdown==1 && flagleft==1 && flagright==1 && flagup==1){
            printf("YES");
        }
        else{
            printf("NO");
           // printf("\n i=%d   up %d down %d left %d right %d",i,flagup,flagdown,flagleft,flagright);
        }
        }

    return 0;
}

#include<stdio.h>
int main()
{
    int n,i,flag8 = 0,flag0 = 0,final = 0;
    char arr[10],c;
    scanf("%d%c",&n,&c);
    for(i=0;i<n;i++)
    {
        scanf("%c",&arr[i]);
        if(arr[i] == '8')
        {
            flag8 = 1;
            arr[i] = '5';
        }
        if(arr[i] == '0')
        {
            flag0 = 1;
        }
    }
    if(flag0)
    {
        for(i=0;i<n;i++)
        {
            if(arr[i] == '0')
                arr[i] == '8';
            if(arr - 51 < 1)
                final = 1;
        }
    }
    else
    {
        for(i=0;i<n;i++)
        {
            if(arr[i]-45 > 9 || arr[i]-51 < 1)
            {
                final = 1;
            }
        }
    }
    if(final)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

#include<stdio.h>

static int map[10];

int main()
{
    int n;
    scanf("%d", &n);
    getchar();

    while(n--)
    {
        char c;
        c = getchar();

        map[ c - '0' ] = 1;
    }

    int flag = 0;

    if( !(map[1] || map[4] || map[7] || map[0]) ) flag = 1;
    else if( !(map[3] || map[6] || map[9] || map[0]) ) flag = 1;
    else if ( !(map[1]||map[2]||map[3]) ) flag = 1;
    else if(!(map[7]||map[8]||map[9]||map[0])) flag = 1;
    else if( !(map[1]||map[2]||map[3]||map[4]||
               map[7]) ) flag = 1;
    else if( !(map[1]||map[2]||map[3]||map[6]||
               map[9]) ) flag = 1;
    else if( !(map[1]||map[4]||map[7]||map[8]||
               map[0]) ) flag = 1;
    else if( !(map[3]||map[6]||map[9]||map[8]||
               map[0]) ) flag = 1;

    if(flag == 1) printf("NO\n");
    else printf("YES\n");

    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define SET(a,b) memset(a,b,sizeof(a))
#define scan(n) scanf("%d",&n)
#define print(n) printf("%d\n",n)
#define scanl(n) scanf("%lld",&n)
#define printl(n) printf("%lld\n",n)

//stacks
/*void push(int n,int ar[],int i)
{
        ar[i]=n;
        i++;
}
void pop(int ar[],int i)
{
        if(i>0)
        {
                ar[i-1]=0;
                i--;
        }
}*/

//queues
/*void qpush(int ar[],int val,int head,int tail,int range)
{
        if(head==tail)
        {
                ar[head]=val;
                if(tail+1==range)
                        tail=0;
                else
                        tail++;
        }
        else
        {
                ar[tail]=val;
                if(tail+1==range)
                        tail=0;
                else
                        tail++;
        }
        if(tail==head)
        {
                if(head+1==range)
                        head=0;
                else
                        head++;
        }
}

void qpop(int head,int tail,int range)
{
        if(head+1==range)
                head=0;
        else
                head++;
}*/

//pow
/*int fun(int a,int b,int m)
{
        if(b==0)
                return 1;
        int d,x;
        d=fun(a,b/2,m);
        x=(d*d)%m;
        if(b%2==0)
                return x;
        else
                return (x*a%m)%m;
}
*/
//bst
/*typedef struct tree
{
        int val;
        struct tree *l;
        struct tree *r;
}node;
//node *head;
node *insert(int x,node *root)
{
        if(root==NULL)
        {
                root=(node *)malloc(sizeof(node));
                root->val=x;
        }
        else
        {
                if(x<=root->val)
                {
                        if(root->l==NULL)
                        {
                                root->l=(node *)malloc(sizeof(node));
                                root->l->val=x;
                        }
                        else
                                root->l=insert(x,root->l);
                }
                else
                {
                        if(root->r==NULL)
                        {
                                root->r=(node *)malloc(sizeof(node));
                                root->r->val=x;
                        }
                        else
                        {
                                root->r=insert(x,root->r);
                        }
                }
        }
        return root;
}
node *find(int x,node *root)
{
        if(root==NULL)
        {
                return 0;
        }
        else
        {
                if(x==root->val)
                        return root;
                else if(x<root->val)
                {
                        if(root->l==NULL)
                        {
                                return 0;
                        }
                        else
                        {
                                find(x,root->l);
                        }
                }
                else
                {
                        if(root->r==NULL)
                        {
                                return 0;
                        }
                        else
                        {
                                find(x,root->r);
                        }
                }
        }
}

void inorder(node *root)
{
        if(root==NULL)
        {
                return;
        }
        if(root->l==NULL)
        {
                printf("%d",root->val);
                if(root->r==NULL)
                        return;
                else
                        inorder(root->r);
        }
        else
        {
                inorder(root->l);
                printf("%d",root->val);
                if(root->r==NULL)
                        return;
                else
                        inorder(root->r);
        }
}
void preorder(node *root)
{
        if(root==NULL)
        {
                return;
        }
        else
        {
                printf("%d",root->val);
                preorder(root->l);
                preorder(root->r);
        }
}

void postorder(node *root)
{
        if(root==NULL)
        {
                return;
        }
        else
        {
                postorder(root->l);
                postorder(root->r);
                printf("%d",root->val);
        }
}
*/
//adjacency list
/*typedef struct ll
{
        int val;
        struct ll *next;
}nd;

//n *ar[100001];
void insert(int a,int b)
{
        if(ar[a]==NULL)
        {
                ar[a]=(nd *)malloc(sizeof(nd));
                ar[a]->val=b;
                ar[a]->next=NULL;
        }
        else
        {
                nd *temp=(nd *)malloc(sizeof(nd)),*t;
                temp->val=b;
                temp->next=ar[a];
                ar[a]=temp;
        }
}

//dfs
//int state[100001];
void dfs(int a)
{
        state[a]=1;
        count++;
        nd *temp=ar[a];
        while(temp!=NULL)
        {
                if(state[temp->val]!=1)
                        dfs(temp->val);
                temp=temp->next;
        }
        return;
}*/

//dijkstra + heaps
/*typedef struct ll2
{
        int val;
        int weight;
        struct ll2 *next;
}nde;
*/
//nde *ar[500005];
//int state[500005];

/*void insert(int a,int b,int w)//insert to adjacency list
{
	if(ar[a]==NULL)
  	{
 	 	ar[a]=(node *)malloc(sizeof(node));
 	 	ar[a]->val=b;
 	 	ar[a]->weight=w;
 	 	ar[a]->next=NULL;
 	}
 	else
  	{
  		node *temp=(node *)malloc(sizeof(node)),*t;
  		temp->val=b;
  		temp->weight=w;
  		temp->next=ar[a];
  		ar[a]=temp;
  	}
}*/

//int pt[500005],d[500005];
//int heap[500005][2];
//int ptr;
/*void decpty(int val,int pos)//decrease priority
{
        heap[pos][0]=val;
        int x=pos;
        while(x>0)
        {
                if(heap[x][0]>=heap[x/2][0])
                        break;
                else
                {
                        pt[heap[x][1]]=x/2;
                        pt[heap[x/2][1]]=x;
                        int temp=heap[x][0],t2=heap[x][1];
                        heap[x][0]=heap[x/2][0];
                        heap[x][1]=heap[x/2][1];
                        heap[x/2][0]=temp;
                        heap[x/2][1]=t2;
                        x=x/2;
                }
        }
}

void hinsert(int val,int val2)//insert to heap
{
        heap[ptr][0]=val;
        heap[ptr][1]=val2;
        pt[val2]=ptr;
        int x=ptr;
        ptr++;
        while(x>0)
        {
                if(heap[x][0]>=heap[x/2][0])
                        break;
                else
                {
                        pt[heap[x][1]]=x/2;
                        pt[heap[x/2][1]]=x;
                        int temp=heap[x][0],t2=heap[x][1];
                        heap[x][0]=heap[x/2][0];
                        heap[x][1]=heap[x/2][1];
                        heap[x/2][0]=temp;
                        heap[x/2][1]=t2;
                        x=x/2;
                }
        }
}

int hdeletemin()//delete min elem from heap
{
        int ret;
        ret=heap[1][1];
        pt[heap[1][1]]=-1;
        pt[heap[ptr-1][1]]=1;
        heap[1][0]=heap[ptr-1][0];
        heap[1][1]=heap[ptr-1][1];
        ptr--;
        int x=1;
        while(x<ptr)
        {
                if(2*x+1>=ptr)
                {
                        if(2*x<ptr)
                        {
                                if(heap[2*x][0]<heap[x][0])
                                {
                                        pt[heap[x][1]]=2*x;
                                        pt[heap[2*x][1]]=x;
                                        int temp=heap[x][0];
                                        int temp2=heap[x][1];
                                        heap[x][0]=heap[2*x][0];
                                        heap[x][1]=heap[2*x][1];
                                        heap[2*x][0]=temp;
                                        heap[2*x][1]=temp2;
                                        x=2*x;
                                }
                                else
                                        break;
                        }
                        else
                                break;
                }
                else if(heap[x][0]<=heap[2*x][0] && heap[x][0]<=heap[2*x+1][0])
                        break;
                else
                {
                        if(heap[2*x][0]<=heap[2*x+1][0])
                        {
                                pt[heap[x][1]]=2*x;
                                pt[heap[2*x][1]]=x;
                                int temp=heap[x][0];
                                int temp2=heap[x][1];
                                heap[x][0]=heap[2*x][0];
                                heap[x][1]=heap[2*x][1];
                                heap[2*x][0]=temp;
                                heap[2*x][1]=temp2;
                                x=2*x;
                        }
                        else
                        {
                                pt[heap[x][1]]=2*x+1;
                                pt[heap[2*x+1][1]]=x;
                                int temp=heap[x][0];
                                int temp2=heap[x][1];
                                heap[x][0]=heap[2*x+1][0];
                                heap[x][1]=heap[2*x+1][1];
                                heap[2*x+1][0]=temp;
                                heap[2*x+1][1]=temp2;
                                x=2*x+1;
                        }
                }
        }
        return ret;
}

void dikstra(int u,int v)
{
        while(ptr!=1)
        {
                int v=hdeletemin();
                node *temp=ar[v];
                while(temp!=NULL)
                {
                        int w=temp->val;
                        if(d[v]+temp->weight < d[w])
                        {
                                d[w]=d[v]+temp->weight;
                                decpty(d[w],pt[w]);
                        }
                        temp=temp->next;
                }
        }
}*/

/*int main()
{
  	int n,m,u,v,w,i;
  	scanf("%d%d",&n,&m);
  	for(i=0;i<=n;i++)
  	state[i]=0;
  	while(m--)
  	{
  		scanf("%d%d%d",&u,&v,&w);
  		insert(u,v,w);
  	}
  	scanf("%d%d",&u,&v);
  	ptr=1;
  	hinsert(0,u);
  	d[u]=0;
  	for(i=1;i<=n;i++)
  	{
  		if(i!=u)
  		{
  			hinsert(1000000000,i);
  			d[i]=1000000000;
  		}
  	}
  	dikstra(u,v);
  	if(d[v]==1000000000)
  	printf("NO\n");
  	else
  	printf("%d\n",d[v]);
  	return 0;
}*/

//kruskal + dsu

//int dsu[N];
/*int find(int x)
{
        if(dsu[x]==x)return x;
        return dsu[x] = find(dsu[x]);
}

void Union(int a,int b)
{
        if(a==b)
                return;
        dsu[a] = b;
}

typedef struct edge
{
        int u,v;
        int weight;
}edge;
*/
//edge e[N];
/*int cmp(const void *a,const void *b)
{
	return ((edge*)a)->weight - ((edge*)b)->weight;
}*/
/*int main()
{
  	int i;
  	int n,m;
  	scanf("%d %d\n",&n,&m);
  	for(i=0;i<m;i++)
	scanf("%d %d %d",&e[i].u,&e[i].v,&e[i].weight);
	for(i=1;i<=n;i++)
	dsu[i]=i;
	qsort(e,m,sizeof(edge),cmp);
	long long int sum=0;
	for(i=0;i<m;i++)
	{
	 	int a,b;
	 	if((a=find(e[i].u))!=(b=find(e[i].v)))
	 	{
	 		sum+=e[i].weight;
	  		Union(a,b);
	  	}
	}
	printf("%lld\n",sum);
	return 0;
}*/

//max
/*int max(int a,int b)
{
    if(a>b)
        return a;
    else
        return b;
}
*/
//qsort

/*int cmpfunc(const void *a,const void *b)
{
        return (*(int *)a - *(int *)b);
}*/
//qsort(ar,n,sizeof(int),cmpfunc);

//-------------------------------------------------------------------------------------------------------------------------------------

int main()
{
       char s[100];
       int n,ans,i,ar[100];
       int right,left,top,bottom;
       right=1;
       left=1;
       top=1;
       bottom=1;
       scan(n);
       scanf("%s",s);
       for(i=0;i<n;i++)
       {
              ar[i]=s[i]-'0';
       }
       for(i=0;i<n;i++)
       {
              if(ar[i]==3 || ar[i]==6 || ar[i]==9)
                     right=0;
              if(ar[i]==1 || ar[i]==4 || ar[i]==7)
                     left=0;
              if(ar[i]==1 || ar[i]==2 || ar[i]==3)
                     top=0;
              if(ar[i]==7 || ar[i]==0 || ar[i]==9)
                     bottom=0;
       }
       if(left==1 || right==1 || top==1 || bottom==1)
              printf("NO\n");
       else
              printf("YES\n");
       return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define SET(a,b) memset(a,b,sizeof(a))
#define scan(n) scanf("%d",&n)
#define print(n) printf("%d\n",n)
#define scanl(n) scanf("%lld",&n)
#define printl(n) printf("%lld\n",n)

//stacks
/*void push(int n,int ar[],int i)
{
        ar[i]=n;
        i++;
}
void pop(int ar[],int i)
{
        if(i>0)
        {
                ar[i-1]=0;
                i--;
        }
}*/

//queues
/*void qpush(int ar[],int val,int head,int tail,int range)
{
        if(head==tail)
        {
                ar[head]=val;
                if(tail+1==range)
                        tail=0;
                else
                        tail++;
        }
        else
        {
                ar[tail]=val;
                if(tail+1==range)
                        tail=0;
                else
                        tail++;
        }
        if(tail==head)
        {
                if(head+1==range)
                        head=0;
                else
                        head++;
        }
}

void qpop(int head,int tail,int range)
{
        if(head+1==range)
                head=0;
        else
                head++;
}*/

//pow
/*int fun(int a,int b,int m)
{
        if(b==0)
                return 1;
        int d,x;
        d=fun(a,b/2,m);
        x=(d*d)%m;
        if(b%2==0)
                return x;
        else
                return (x*a%m)%m;
}
*/
//bst
/*typedef struct tree
{
        int val;
        struct tree *l;
        struct tree *r;
}node;
//node *head;
node *insert(int x,node *root)
{
        if(root==NULL)
        {
                root=(node *)malloc(sizeof(node));
                root->val=x;
        }
        else
        {
                if(x<=root->val)
                {
                        if(root->l==NULL)
                        {
                                root->l=(node *)malloc(sizeof(node));
                                root->l->val=x;
                        }
                        else
                                root->l=insert(x,root->l);
                }
                else
                {
                        if(root->r==NULL)
                        {
                                root->r=(node *)malloc(sizeof(node));
                                root->r->val=x;
                        }
                        else
                        {
                                root->r=insert(x,root->r);
                        }
                }
        }
        return root;
}
node *find(int x,node *root)
{
        if(root==NULL)
        {
                return 0;
        }
        else
        {
                if(x==root->val)
                        return root;
                else if(x<root->val)
                {
                        if(root->l==NULL)
                        {
                                return 0;
                        }
                        else
                        {
                                find(x,root->l);
                        }
                }
                else
                {
                        if(root->r==NULL)
                        {
                                return 0;
                        }
                        else
                        {
                                find(x,root->r);
                        }
                }
        }
}

void inorder(node *root)
{
        if(root==NULL)
        {
                return;
        }
        if(root->l==NULL)
        {
                printf("%d",root->val);
                if(root->r==NULL)
                        return;
                else
                        inorder(root->r);
        }
        else
        {
                inorder(root->l);
                printf("%d",root->val);
                if(root->r==NULL)
                        return;
                else
                        inorder(root->r);
        }
}
void preorder(node *root)
{
        if(root==NULL)
        {
                return;
        }
        else
        {
                printf("%d",root->val);
                preorder(root->l);
                preorder(root->r);
        }
}

void postorder(node *root)
{
        if(root==NULL)
        {
                return;
        }
        else
        {
                postorder(root->l);
                postorder(root->r);
                printf("%d",root->val);
        }
}
*/
//adjacency list
/*typedef struct ll
{
        int val;
        struct ll *next;
}nd;

//n *ar[100001];
void insert(int a,int b)
{
        if(ar[a]==NULL)
        {
                ar[a]=(nd *)malloc(sizeof(nd));
                ar[a]->val=b;
                ar[a]->next=NULL;
        }
        else
        {
                nd *temp=(nd *)malloc(sizeof(nd)),*t;
                temp->val=b;
                temp->next=ar[a];
                ar[a]=temp;
        }
}

//dfs
//int state[100001];
void dfs(int a)
{
        state[a]=1;
        count++;
        nd *temp=ar[a];
        while(temp!=NULL)
        {
                if(state[temp->val]!=1)
                        dfs(temp->val);
                temp=temp->next;
        }
        return;
}*/

//dijkstra + heaps
/*typedef struct ll2
{
        int val;
        int weight;
        struct ll2 *next;
}nde;
*/
//nde *ar[500005];
//int state[500005];

/*void insert(int a,int b,int w)//insert to adjacency list
{
	if(ar[a]==NULL)
  	{
 	 	ar[a]=(node *)malloc(sizeof(node));
 	 	ar[a]->val=b;
 	 	ar[a]->weight=w;
 	 	ar[a]->next=NULL;
 	}
 	else
  	{
  		node *temp=(node *)malloc(sizeof(node)),*t;
  		temp->val=b;
  		temp->weight=w;
  		temp->next=ar[a];
  		ar[a]=temp;
  	}
}*/

//int pt[500005],d[500005];
//int heap[500005][2];
//int ptr;
/*void decpty(int val,int pos)//decrease priority
{
        heap[pos][0]=val;
        int x=pos;
        while(x>0)
        {
                if(heap[x][0]>=heap[x/2][0])
                        break;
                else
                {
                        pt[heap[x][1]]=x/2;
                        pt[heap[x/2][1]]=x;
                        int temp=heap[x][0],t2=heap[x][1];
                        heap[x][0]=heap[x/2][0];
                        heap[x][1]=heap[x/2][1];
                        heap[x/2][0]=temp;
                        heap[x/2][1]=t2;
                        x=x/2;
                }
        }
}

void hinsert(int val,int val2)//insert to heap
{
        heap[ptr][0]=val;
        heap[ptr][1]=val2;
        pt[val2]=ptr;
        int x=ptr;
        ptr++;
        while(x>0)
        {
                if(heap[x][0]>=heap[x/2][0])
                        break;
                else
                {
                        pt[heap[x][1]]=x/2;
                        pt[heap[x/2][1]]=x;
                        int temp=heap[x][0],t2=heap[x][1];
                        heap[x][0]=heap[x/2][0];
                        heap[x][1]=heap[x/2][1];
                        heap[x/2][0]=temp;
                        heap[x/2][1]=t2;
                        x=x/2;
                }
        }
}

int hdeletemin()//delete min elem from heap
{
        int ret;
        ret=heap[1][1];
        pt[heap[1][1]]=-1;
        pt[heap[ptr-1][1]]=1;
        heap[1][0]=heap[ptr-1][0];
        heap[1][1]=heap[ptr-1][1];
        ptr--;
        int x=1;
        while(x<ptr)
        {
                if(2*x+1>=ptr)
                {
                        if(2*x<ptr)
                        {
                                if(heap[2*x][0]<heap[x][0])
                                {
                                        pt[heap[x][1]]=2*x;
                                        pt[heap[2*x][1]]=x;
                                        int temp=heap[x][0];
                                        int temp2=heap[x][1];
                                        heap[x][0]=heap[2*x][0];
                                        heap[x][1]=heap[2*x][1];
                                        heap[2*x][0]=temp;
                                        heap[2*x][1]=temp2;
                                        x=2*x;
                                }
                                else
                                        break;
                        }
                        else
                                break;
                }
                else if(heap[x][0]<=heap[2*x][0] && heap[x][0]<=heap[2*x+1][0])
                        break;
                else
                {
                        if(heap[2*x][0]<=heap[2*x+1][0])
                        {
                                pt[heap[x][1]]=2*x;
                                pt[heap[2*x][1]]=x;
                                int temp=heap[x][0];
                                int temp2=heap[x][1];
                                heap[x][0]=heap[2*x][0];
                                heap[x][1]=heap[2*x][1];
                                heap[2*x][0]=temp;
                                heap[2*x][1]=temp2;
                                x=2*x;
                        }
                        else
                        {
                                pt[heap[x][1]]=2*x+1;
                                pt[heap[2*x+1][1]]=x;
                                int temp=heap[x][0];
                                int temp2=heap[x][1];
                                heap[x][0]=heap[2*x+1][0];
                                heap[x][1]=heap[2*x+1][1];
                                heap[2*x+1][0]=temp;
                                heap[2*x+1][1]=temp2;
                                x=2*x+1;
                        }
                }
        }
        return ret;
}

void dikstra(int u,int v)
{
        while(ptr!=1)
        {
                int v=hdeletemin();
                node *temp=ar[v];
                while(temp!=NULL)
                {
                        int w=temp->val;
                        if(d[v]+temp->weight < d[w])
                        {
                                d[w]=d[v]+temp->weight;
                                decpty(d[w],pt[w]);
                        }
                        temp=temp->next;
                }
        }
}*/

/*int main()
{
  	int n,m,u,v,w,i;
  	scanf("%d%d",&n,&m);
  	for(i=0;i<=n;i++)
  	state[i]=0;
  	while(m--)
  	{
  		scanf("%d%d%d",&u,&v,&w);
  		insert(u,v,w);
  	}
  	scanf("%d%d",&u,&v);
  	ptr=1;
  	hinsert(0,u);
  	d[u]=0;
  	for(i=1;i<=n;i++)
  	{
  		if(i!=u)
  		{
  			hinsert(1000000000,i);
  			d[i]=1000000000;
  		}
  	}
  	dikstra(u,v);
  	if(d[v]==1000000000)
  	printf("NO\n");
  	else
  	printf("%d\n",d[v]);
  	return 0;
}*/

//kruskal + dsu

//int dsu[N];
/*int find(int x)
{
        if(dsu[x]==x)return x;
        return dsu[x] = find(dsu[x]);
}

void Union(int a,int b)
{
        if(a==b)
                return;
        dsu[a] = b;
}

typedef struct edge
{
        int u,v;
        int weight;
}edge;
*/
//edge e[N];
/*int cmp(const void *a,const void *b)
{
	return ((edge*)a)->weight - ((edge*)b)->weight;
}*/
/*int main()
{
  	int i;
  	int n,m;
  	scanf("%d %d\n",&n,&m);
  	for(i=0;i<m;i++)
	scanf("%d %d %d",&e[i].u,&e[i].v,&e[i].weight);
	for(i=1;i<=n;i++)
	dsu[i]=i;
	qsort(e,m,sizeof(edge),cmp);
	long long int sum=0;
	for(i=0;i<m;i++)
	{
	 	int a,b;
	 	if((a=find(e[i].u))!=(b=find(e[i].v)))
	 	{
	 		sum+=e[i].weight;
	  		Union(a,b);
	  	}
	}
	printf("%lld\n",sum);
	return 0;
}*/

//max
/*int max(int a,int b)
{
    if(a>b)
        return a;
    else
        return b;
}
*/
//qsort

/*int cmpfunc(const void *a,const void *b)
{
        return (*(int *)a - *(int *)b);
}*/
//qsort(ar,n,sizeof(int),cmpfunc);

//-------------------------------------------------------------------------------------------------------------------------------------

int main()
{
       char s[100];
       int n,ans,i,ar[100];
       int right,left,top,bottom;
       right=1;
       left=1;
       top=1;
       bottom=1;
       scan(n);
       scanf("%s",s);
       for(i=0;i<n;i++)
       {
              ar[i]=s[i]-'0';
       }
       for(i=0;i<n;i++)
       {
              if(ar[i]==3 || ar[i]==6 || ar[i]==9)
                     right=0;
              if(ar[i]==1 || ar[i]==4 || ar[i]==7)
                     left=0;
              if(ar[i]==1 || ar[i]==2 || ar[i]==3)
                     top=0;
              if(ar[i]==7 || ar[i]==0 || ar[i]==9)
                     bottom=0;
       }
       int c1=0;
       for(i=0;i<n;i++)
       {
              if(ar[i]==0)
                     c1=0;
       }
       if(top==0 && c1==0)
              printf("YES\n");
       else if(left==1 || right==1 || top==1 || bottom==1)
              printf("NO\n");
       else
              printf("YES\n");
       return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int d[10];

int main() {
	int n;
	char s[10];
	scanf("%d%s", &n, s);
	for(int i=0 ; i<n ; i++) {
		d[s[i] - '0'] = 1;
	}
	if(!d[1] && !d[2] && !d[3]) {
		printf("NO");
		return 0;
	}
	if(d[0]) {
		printf("YES");
		return 0;
	}
	if(d[7] || d[9]) {
		printf("YES");
		return 0;
	}
	printf("NO");
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

static int arr[4][3];

int rowcount();
int colcount();
void setnum(char ch);

int main()
{
	char str[10];
	int r, c, i, n;
	int haszero = 0;

	scanf("%d", &n);
	scanf("%s", str);

	for (i = 0; i < n; i++) {
		setnum(str[i]);
		if(str[i] == '0') haszero = 1;
	}

	r = rowcount();
	c = colcount();

	if (haszero) {
		if(r == 4) printf("YES");
		else printf("NO");
	} else {
		if(r == 3 && c == 3) printf("YES");
		else printf("NO");
	}

}

int rowcount() {
    int i, j, min = -1, max = 0;

    for(i = 0; i < 4; i++) {
		for(j = 0; j < 3; j++) {
            if(arr[i][j]) {
				if(min == -1){
					min = i;
					max = i;
				}
				else max = i;
				break;
            }
		}
    }

    return max - min + 1;
}

int colcount() {
	int i, j, min = -1, max = 0;

	for(j = 0; j < 3; j++) {
		for(i = 0; i < 4; i++) {
			if(arr[i][j]) {
				if(min == -1) {
					min = j;
					max = j;
				}
				else max = j;
				break;
			}
		}
	}

	return max - min + 1;
}

void setnum(char ch) {
    switch (ch) {
		case '0': arr[3][1] = ch; return;
		case '1': arr[0][0] = ch; return;
		case '2': arr[0][1] = ch; return;
		case '3': arr[0][2] = ch; return;
		case '4': arr[1][0] = ch; return;
		case '5': arr[1][1] = ch; return;
		case '6': arr[1][2] = ch; return;
		case '7': arr[2][0] = ch; return;
		case '8': arr[2][1] = ch; return;
		case '9': arr[2][2] = ch; return;
    }
}

#include <stdio.h>
#include <stdlib.h>

static int arr[4][3];

int rowcount();
int colcount();
void setnum(char ch);

int main()
{
	char str[10];
	int r, c, i, n;
	int haszero = 0;

	scanf("%d", &n);
	scanf("%s", str);

	for (i = 0; i < n; i++) {
		setnum(str[i]);
		if(str[i] == '0') haszero = 1;
	}

	r = rowcount();
	c = colcount();

	printf("%d %d\n", r, c);

	if(r == 4) printf("YES");
	else if(r == 3 && c == 3 && ((arr[0][0] && arr[2][2]) || (arr[0][2] && arr[2][0]))) printf("YES");
	else printf("NO");
}

int rowcount() {
    int i, j, min = -1, max = 0;

    for(i = 0; i < 4; i++) {
		for(j = 0; j < 3; j++) {
            if(arr[i][j]) {
				if(min == -1){
					min = i;
					max = i;
				}
				else max = i;
				break;
            }
		}
    }

    return max - min + 1;
}

int colcount() {
	int i, j, min = -1, max = 0;

	for(j = 0; j < 3; j++) {
		for(i = 0; i < 4; i++) {
			if(arr[i][j]) {
				if(min == -1) {
					min = j;
					max = j;
				}
				else max = j;
				break;
			}
		}
	}

	return max - min + 1;
}

void setnum(char ch) {
    switch (ch) {
		case '0': arr[3][1] = ch; return;
		case '1': arr[0][0] = ch; return;
		case '2': arr[0][1] = ch; return;
		case '3': arr[0][2] = ch; return;
		case '4': arr[1][0] = ch; return;
		case '5': arr[1][1] = ch; return;
		case '6': arr[1][2] = ch; return;
		case '7': arr[2][0] = ch; return;
		case '8': arr[2][1] = ch; return;
		case '9': arr[2][2] = ch; return;
    }
}

#include <stdio.h>
#include <stdlib.h>

static int arr[4][3];

int rowcount();
int colcount();
void setnum(char ch);

int main()
{
	char str[10];
	int r, c, i, n;
	int haszero = 0;

	scanf("%d", &n);
	scanf("%s", str);

	for (i = 0; i < n; i++) {
		setnum(str[i]);
		if(str[i] == '0') haszero = 1;
	}

	r = rowcount();
	c = colcount();

	//printf("%d %d\n", r, c);

	if(r == 4) printf("YES");
	else if(r == 3 && c == 3 && ((arr[0][0] && arr[2][2])
								|| (arr[0][2] && arr[2][0])
								|| (arr[2][0] && arr[2][2])
								|| (arr[0][0] && arr[0][2])
								|| (arr[0][2] && arr[2][2]))) printf("YES");
	else printf("NO");
}

int rowcount() {
    int i, j, min = -1, max = 0;

    for(i = 0; i < 4; i++) {
		for(j = 0; j < 3; j++) {
            if(arr[i][j]) {
				if(min == -1){
					min = i;
					max = i;
				}
				else max = i;
				break;
            }
		}
    }

    return max - min + 1;
}

int colcount() {
	int i, j, min = -1, max = 0;

	for(j = 0; j < 3; j++) {
		for(i = 0; i < 4; i++) {
			if(arr[i][j]) {
				if(min == -1) {
					min = j;
					max = j;
				}
				else max = j;
				break;
			}
		}
	}

	return max - min + 1;
}

void setnum(char ch) {
    switch (ch) {
		case '0': arr[3][1] = ch; return;
		case '1': arr[0][0] = ch; return;
		case '2': arr[0][1] = ch; return;
		case '3': arr[0][2] = ch; return;
		case '4': arr[1][0] = ch; return;
		case '5': arr[1][1] = ch; return;
		case '6': arr[1][2] = ch; return;
		case '7': arr[2][0] = ch; return;
		case '8': arr[2][1] = ch; return;
		case '9': arr[2][2] = ch; return;
    }
}

#include <stdio.h>
#include <stdlib.h>

static int arr[4][3];

int rowcount();
int colcount();
void setnum(char ch);

int main()
{
	char str[10];
	int r, c, i, n;
	int haszero = 0;

	scanf("%d", &n);
	scanf("%s", str);

	for (i = 0; i < n; i++) {
		setnum(str[i]);
		if(str[i] == '0') haszero = 1;
	}

	r = rowcount();
	c = colcount();

	//printf("%d %d\n", r, c);

	if(r == 4) printf("YES");
	else if(r == 3 && c == 3 && ((arr[0][0] && arr[2][2]) || (arr[0][2] && arr[2][0]))) printf("YES");
	else printf("NO");
}

int rowcount() {
    int i, j, min = -1, max = 0;

    for(i = 0; i < 4; i++) {
		for(j = 0; j < 3; j++) {
            if(arr[i][j]) {
				if(min == -1){
					min = i;
					max = i;
				}
				else max = i;
				break;
            }
		}
    }

    return max - min + 1;
}

int colcount() {
	int i, j, min = -1, max = 0;

	for(j = 0; j < 3; j++) {
		for(i = 0; i < 4; i++) {
			if(arr[i][j]) {
				if(min == -1) {
					min = j;
					max = j;
				}
				else max = j;
				break;
			}
		}
	}

	return max - min + 1;
}

void setnum(char ch) {
    switch (ch) {
		case '0': arr[3][1] = ch; return;
		case '1': arr[0][0] = ch; return;
		case '2': arr[0][1] = ch; return;
		case '3': arr[0][2] = ch; return;
		case '4': arr[1][0] = ch; return;
		case '5': arr[1][1] = ch; return;
		case '6': arr[1][2] = ch; return;
		case '7': arr[2][0] = ch; return;
		case '8': arr[2][1] = ch; return;
		case '9': arr[2][2] = ch; return;
    }
}

#include<stdio.h>
#include<string.h>

int main()	{

	char contact[100];
	char two_test_key[]={'1','2','3'};
	char two_test_key_follows[][10]={{'0','9'}, {'0'}, {'0','7'}};
	char group_test[][10]={{'1','4','7','6'}, {'3','6','9','4'}};
	int i,j;

	scanf("%d",&i);
	scanf("%s",contact);
	for(i=0;i<3;i++)	{
		if(strchr(contact,two_test_key[i]))	{
			if(strchr(contact,two_test_key_follows[i][0]))	{
				puts("YES");
				return 0;
			}
			if(i!=1 && strchr(contact,two_test_key_follows[i][1]))	{
				puts("YES");
				return 0;
			}
		}
	}
	for(i=0;i<2;i++)	{
		for(j=0;j<4;j++)	{
			if(!strchr(contact, group_test[i][j]))	{
				break;
			}
		}
		if(j == 4)	{
			puts("YES");
			return 0;
		}
	}

	puts("NO");

	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#define max 9

bool belongs(char Phone[max] , int N , char Key[max], int M){

    int i=0,k;
    while (i<N){
        k = 0;
        while ((k<M) && ( Phone[i] != Key[k] )) k++;
        if (k<M) i++; else return false;
    }
    return true;
}

void verifyUnique(char Phone[max] , int N ){
    char arr1[max] = {'1','2','4','5','7','8'};
    char arr2[max] = {'4','5','7','8','0'};
    char arr3[max] = {'4','5','6','7','8','9','0'};
    char arr4[max] = {'5','6','8','9','0'};
    char arr5[max] = {'2','3','5','6','8','9'};
    char arr6[max] = {'2','3','5','6','9'};
    char arr7[max] = {'1','2','3','4','5','6','8'};
    char arr8[max] = {'1','2','4','5','6','7'};
    if ( (belongs(Phone,N,arr1,6)) ||
         (belongs(Phone,N,arr2,5)) ||
         (belongs(Phone,N,arr3,7)) ||
         (belongs(Phone,N,arr4,5)) ||
         (belongs(Phone,N,arr5,6)) ||
         (belongs(Phone,N,arr6,5)) ||
         (belongs(Phone,N,arr7,7)) ||
         (belongs(Phone,N,arr8,6)) ){

            printf("NO");

        } else printf("YES");

    return;

}

void readNumber(char Phone[max] , int N){
    scanf("%*c");
    int i;
    for(i = 0;i < N;i++) scanf("%c",&Phone[i]);
    return;
}

int main() {

    int N;
    scanf("%d",&N);
    char Phone[max];
    readNumber(Phone,N);
    verifyUnique(Phone,N);

    return (EXIT_SUCCESS);
}

#include <stdio.h>
#include <string.h>

int main() {
	int test,x;
	char excl[] = "2580";
	char excl2[]="147";
	char excl3[]="369";
	char excl4[]="248";
	char excl5[]="268";
	char inp[11];
	int check=0;
	scanf ("%d\n", &test );
	gets(inp);
	if (strcmp(inp,excl)==0)check=2;
	else if (strcmp(inp,excl2)==0)check=0;
	else if (strcmp(inp,excl3)==0)check=0;
	else if (strcmp(inp,excl4)>=0)check=2;
	else if (strcmp(inp,excl5)>=0)check=2;
	else {
		for (x=0;x<test;x++){
		/*int lala = inp[x]-'0';
		if (lala%2==0){
			if (x<test-1){
				int lili = inp[x+1]-'0';
				if (lili%2==0)check++;
			}
		}*/
		if (inp[x]=='3' || inp[x]=='7')check++;
		if (inp[x]=='9' || inp[x]=='1')check++;

		//printf("%d",lala);
		}
	}
	if (check>=2)printf("YES");
	else printf("NO");
}

#include <stdio.h>
#include <string.h>

int main() {
	int test,x;
	char inp[11];
	int check=0;
	scanf ("%d\n", &test );
	gets(inp);
	for (x=0;x<test;x++){
		if (inp[x]=='3' || inp[x]=='7')check++;
		if (inp[x]=='9' || inp[x]=='1')check++;

	}
	if (check>=2)printf("YES");
	else printf("NO");
}

#include <stdio.h>
#include <string.h>

int main() {
	int test,x;
	char excl[] = "2580";
	char excl2[]="147";
	char excl3[]="369";
	char inp[11];
	int check=0;
	scanf ("%d\n", &test );
	gets(inp);
	if (strcmp(inp,excl)==0)check=2;
	else if (strcmp(inp,excl2)==0)check=0;
	else if (strcmp(inp,excl3)==0)check=0;
	else {
		for (x=0;x<test;x++){
		int lala = inp[x]-'0';
		if (lala%2==0){
			if (x<test-1){
				int lili = inp[x+1]-'0';
				if (lili%2==0)check++;
			}
		}
		else if (inp[x]=='3' || inp[x]=='7')check++;
		else if (inp[x]=='9' || inp[x]=='1')check++;

		//printf("%d",lala);
		}
	}

	if (check>=2)printf("YES");
	else printf("NO");
}

#include <stdio.h>
#include <string.h>

int main() {
	int test,x;
	char excl[] = "2580";
	char excl2[]="147";
	char excl3[]="369";
	char inp[11];
	int check=0;
	scanf ("%d\n", &test );
	gets(inp);
	if (strcmp(inp,excl)==0)check=2;
	else if (strcmp(inp,excl2)==0)check=0;
	else if (strcmp(inp,excl3)==0)check=0;
	else {
		for (x=0;x<test;x++){
		/*int lala = inp[x]-'0';
		if (lala%2==0){
			if (x<test-1){
				int lili = inp[x+1]-'0';
				if (lili%2==0)check++;
			}
		}*/
		if (inp[x]=='3' || inp[x]=='7')check++;
		if (inp[x]=='9' || inp[x]=='1')check++;

		//printf("%d",lala);
		}
	}
	if (check>=2)printf("YES");
	else printf("NO");
}

#include <stdio.h>
#include <string.h>

int main() {
	int test,x;
	char excl[] = "2580";

	char inp[11];
	int check=0;
	scanf ("%d\n", &test );
	gets(inp);
	if (strcmp(inp,excl)==0)check=2;
	for (x=0;x<test;x++){
		int lala = inp[x]-'0';
		if (lala%2==0){
			if (x<test-1){
				int lili = inp[x+1]-'0';
				if (lili%2==0)check++;
			}
		}
		else if (inp[x]=='3' || inp[x]=='7')check++;
		else if (inp[x]=='9' || inp[x]=='1')check++;

		//printf("%d",lala);
	}
	if (check>=2)printf("YES");
	else printf("NO");
}

#include <stdio.h>
#include <string.h>

int main() {
	int test,x;
	char inp[11];
	int check=0;
	scanf ("%d\n", &test );
	gets(inp);
	for (x=0;x<test;x++){
		if (inp[x]=='3' || inp[x]=='7')check++;
		if (inp[x]=='9' || inp[x]=='1')check++;
		if (inp[x]=='2' || inp[x]=='0')check++;
	}
	if (check>=2)printf("YES");
	else printf("NO");
}

#include <stdio.h>
#include <string.h>

int main() {
	int test,x;
	char excl[] = "2580";

	char inp[11];
	int check=0;
	scanf ("%d\n", &test );
	gets(inp);
	if (strcmp(inp,excl)==0)check=2;
	for (x=0;x<test;x++){
		int lala = inp[x]-'0';
		int lili = inp[x+1]-'0';
		if (lala%2==0){
			if (x<test-1){
				if (lili%2==0)check++;
			}
		}
		if (inp[x]=='3' || inp[x]=='7')check++;
		if (inp[x]=='9' || inp[x]=='1')check++;

		//printf("%d",lala);
	}
	if (check>=2)printf("YES");
	else printf("NO");
}

#include <stdio.h>
#include <stdlib.h>
int main(){
	int x[10]={2,1,2,3,1,2,3,1,2,3};
	int y[10]={4,1,1,1,2,2,2,3,3,3};
	int flag,n,a[10],i;
	scanf("%d ",&n);
	char c;
	for(i=0;i<n;i++){
		scanf("%c",&c);
		a[i]=c-'0';
	}
	int minx=4,maxx=0,miny=5,maxy=0;
	for(i=0;i<n;i++){
		if (x[a[i]]<minx)minx=x[a[i]];
		if (x[a[i]]>maxx)maxx=x[a[i]];
		if (y[a[i]]<miny)miny=y[a[i]];
		if (y[a[i]]>maxy)maxy=y[a[i]];
	}
	//printf("%d %d %d %d\n",minx, maxx, miny, maxy);
	if((maxx-minx)==2) flag=0;
	else if ((maxy-miny)==3) flag=0;
	else flag=1;
	if (flag ==0) printf("YES");
	else printf("NO");
	return 0;
}

#include <stdio.h>

int main() {
	static char s[10];
	int n, i, yes1, yes2, yes3, yes4;

	scanf("%d%s", &n, s);
	yes1 = yes2 = yes3 = yes4 = 0;
	for (i = 0; i < n; i++)
		if (s[i] == '1')
			yes1 = yes2 = 1;
		else if (s[i] == '2')
			yes2 = 1;
		else if (s[i] == '3')
			yes2 = yes3 = 1;
		else if (s[i] == '4')
			yes1 = 1;
		else if (s[i] == '6')
			yes3 = 1;
		else if (s[i] == '7')
			yes1 = yes4 = 1;
		else if (s[i] == '9')
			yes3 = yes4 = 1;
		else if (s[i] == '0')
			yes4 = 1;
	printf(yes1 && yes2 && yes3 && yes4 ? "YES\n" : "NO\n");
	return 0;
}