While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] 

Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image]  [Image] 

Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?


-----Input-----

The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in.

The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.


-----Output-----

If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.

Otherwise print "NO" (without quotes) in the first line.


-----Examples-----
Input
3
586

Output
NO

Input
2
09

Output
NO

Input
9
123456789

Output
YES

Input
3
911

Output
YES



-----Note-----

You can find the picture clarifying the first sample case in the statement above.

Difficulty: interview

Starter code:

Solutions:
# A

input()
l = list(map(int, list(input())))

if (1 in l or 4 in l or 7 in l or 0 in l) and (1 in l or 2 in l or 3 in l) and (3 in l or 6 in l or 9 in l or 0 in l) and (7 in l or 0 in l or 9 in l):
    print("YES")
else:
    print("NO")


n = int(input())
numb = input()
num = [0]*10
for i in numb:
    num[int(i)] = 1
ans = 0
if num[1] + num[2] + num[3] > 0:
    ans += 1
if num[1] + num[4] + num[7] + num[0] > 0:
    ans += 1
if num[3] + num[6] + num[9] + num[0] > 0:
    ans += 1
if num[7] + num[0] + num[9] > 0:
    ans += 1
if ans == 4:
    print("YES")
else:
    print("NO")


n = int(input())
d = list(map(int,input()))

l = all([i not in d for i in [1,4,7,0]])
r = all([i not in d for i in [3,6,9,0]])
u = all([i not in d for i in [1,2,3]])
d = all([i not in d for i in [7,0,9]])
print('NO' if l or r or u or d else 'YES')


n = int(input())

l = [41, 10, 11, 12, 20, 21, 22, 30, 31, 32]
s = list([l[int(x)] for x in input()])

def exists_up(s):
    l1 = [x - 10 for x in s]
    return all(x in l for x in l1)

def exists_down(s):
    l1 = [x + 10 for x in s]
    return all(x in l for x in l1)

def exists_left(s):
    l1 = [x - 1 for x in s]
    return all(x in l for x in l1)

def exists_right(s):
    l1 = [x + 1 for x in s]
    return all(x in l for x in l1)

if exists_up(s) or exists_down(s) or exists_left(s) or exists_right(s):
    print("NO")
else:
    print("YES")


def main():
    input()
    seq = input()

    LEFT = {
        '0': False,
        '1': False,
        '2': True,
        '3': True,
        '4': False,
        '5': True,
        '6': True,
        '7': False,
        '8': True,
        '9': True,
    }
    RIGHT = {
        '0': False,
        '1': True,
        '2': True,
        '3': False,
        '4': True,
        '5': True,
        '6': False,
        '7': True,
        '8': True,
        '9': False,
    }
    UP = {
        '0': True,
        '1': False,
        '2': False,
        '3': False,
        '4': True,
        '5': True,
        '6': True,
        '7': True,
        '8': True,
        '9': True,
    }
    DOWN = {
        '0': False,
        '1': True,
        '2': True,
        '3': True,
        '4': True,
        '5': True,
        '6': True,
        '7': False,
        '8': True,
        '9': False,
    }
    print('NO' if any(all(can[n] for n in seq) for can in (LEFT, RIGHT, UP, DOWN)) else 'YES')

    
def __starting_point():
    main()

__starting_point()

n = int(input())
s = input()
a = [0]*10
for i in range(n):
    a[int(s[i])] = 1

if a[1]+a[2]+a[3] == 0 or a[7]+a[9]+a[0] == 0 or a[1]+a[4]+a[7]+a[0] == 0 or a[3] + a[6] + a[9] + a[0] == 0:
    print('NO')
else:
    print('YES')


n = int(input())
s = input()

haszero = 0
for x in s:
    if(x=='0'):
        haszero = 1

hasup = 0
hasleft = 0
hasright = 0
hasdown = 0

for x in s:
    if(x=='1')or(x=='2')or(x=='3'):
        hasup = 1
    if(x=='1')or(x=='4')or(x=='7'):
        hasleft = 1
    if(x=='3')or(x=='6')or(x=='9'):
        hasright = 1
    if(x=='7')or(x=='0')or(x=='9'):
        hasdown = 1

if hasup and hasleft and hasright and hasdown:
    print('YES')
else:
    if hasup and haszero:
        print('YES')
    else:
        print('NO')

def Left(a):
    if (a != 1 and a != 4 and a != 7 and a != 0):
        return True
    return False

def Right(a):
    if (a != 3 and a != 6 and a != 9 and a != 0):
        return True
    return False

def Up(a):
    if (a != 1 and a != 2 and a != 3):
        return True
    return False

def Down(a):
    if (a != 7 and a != 9 and a != 0):
        return True
    return False

n = int(input())
str1 = input()

u =0
d=0
l=0
r=0
for iss in str1:
    i = int(iss)
    if (Up(i)):
        u+=1
    if (Down(i)):
        d += 1
    if (Left(i)):
        l += 1
    if (Right(i)):
        r += 1

if (u == len(str1)
    or d == len(str1)
    or l == len(str1)
    or r == len(str1)):
    print("NO")
else:
    print("YES")




n = int(input())
s = input().rstrip()

def canMove(moves, dx, dy):
	for x, y in moves:
		tx = x + dx
		ty = y + dy
		if not (0 <= tx < 3 and 0 <= ty < 3):
			if not (tx == 3 and ty == 1):
				return False
	return True


l = [
[	3, 1,],
[	0, 0,],
[	0, 1,],
[	0, 2,],
[	1, 0,],
[	1, 1,],
[	1, 2,],
[	2, 0],
[	2, 1,],
[	2, 2,],
]


move = []
for x in s:
	move.append(l[int(x)])
# print(move)

cnt = 0
for i in range(10):
	for j in range(10):
		dx = i - 5
		dy = j - 5
		if canMove(move, dx, dy):
			cnt += 1
if cnt == 1:
	print('YES')
else:
	print('NO')



def works(numbers):
    if (numbers[1] or numbers[2] or numbers[3]):
        if (numbers[7] or numbers[0] or numbers[9]):
            if (numbers[1] or numbers[4] or numbers[7] or numbers[0]):
                if (numbers[3] or numbers[6] or numbers[9] or numbers[0]):
                    return True
                else:
                    return False
            else:
                return False
        else:
            return False
    else:
        return False


n=int(input())
line=input()
numbers={}
for i in range (10):
    numbers[i]=False
for ch in line:
    numbers[int(ch)]=True
if works(numbers):
    print ("YES")
else:
    print("NO")


n = int(input())
L = [int(x) for x in input()]

C = [None] * 10
p={}
for i in range(1,10):
    C[i] = ((i-1)//3, (i-1)%3)
    p[C[i]] = True
C[0] = (3, 1)
p[C[0]] = True
cnt = 0
possib = []
q = [(i, j) for i in range(-6, 7) for j in range(-6, 7)]
for base in q:
    gone = False
    for num in L:
        diff = C[num]
        nn = (diff[0] + base[0], diff[1] + base[1])
        if nn not in p:
            gone = True
            break
    if not gone:
        possib.append(base)
        cnt += 1
if cnt == 1:
    print('YES')
else:
    print('NO')


a = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [-1, 0, -1]]
d = [(3, 1), (0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]
n = int(input())
b = list(map(int, list(input())))
c = []
for i in range(n - 1):
    c.append((d[b[i + 1]][0] - d[b[i]][0], d[b[i + 1]][1] - d[b[i]][1]))
for i in range(10):
    x, y = d[i][0], d[i][1]
    fl = 1
    for j in c:
        x1, y1 = x + j[0], y + j[1]
        if (x1, y1) not in d:
            fl = 0
        x, y = x1, y1
    if fl and i != b[0]:
        print("NO")
        break
else:
    print("YES")


n = int(input())
s = input()
pr = True
for i in range(len(s)):
    if s[i] in '3690':
        pr = False
vn = True
for i in range(len(s)):
    if s[i] in '709':
        vn = False
le = True
for i in range(len(s)):
    if s[i] in '1470':
        le = False
vv = True
for i in range(len(s)):
    if s[i] in '123':
        vv = False
if (pr or  vn or le or vv):
    print('NO')
else:
    print('YES')


coords = {0: (1, 0), 1: (0, 3), 2: (1, 3), 3: (2, 3), 4: (0, 2), 5: (1, 2), 6: (2, 2), 7: (0, 1), 8: (1, 1), 9: (2, 1)}
valid_coords = set()
for elem in coords:
    valid_coords.add(coords[elem])
n = input()
s = [int(elem) for elem in input()]
vectors = []
for i in range(len(s) - 1):
    t = [0, 0]
    t[0] = coords[s[i + 1]][0] - coords[s[i]][0]
    t[1] = coords[s[i + 1]][1] - coords[s[i]][1]
    vectors.append(t)
cnt = 0
for elem in coords:
    start = coords[elem]
    faults = 0
    for v in vectors:
        new_start = (start[0] + v[0], start[1] + v[1])
        start = new_start
        if start not in valid_coords:
            faults += 1
    if faults == 0:
        cnt += 1
if cnt == 1:
    print('YES')
else:
    print('NO')

#! /usr/bin/env python3

import sys

n = int(input())
s = list(map(lambda x: int(x) - int('0'), input()))

d = [(1, 3)] + [(i, j) for j in range(3) for i in range(3)]

for u in range(10):
    if u == s[0]:
        continue
    x, y = d[u]
    for i in range(1, n):
        dx, dy = (d[s[i]][0] - d[s[i - 1]][0], d[s[i]][1] - d[s[i - 1]][1])
        x += dx
        y += dy
        if (x, y) not in d:
            break
    else:
        print(u, file=sys.stderr)
        print('NO')
        return

print('YES')


from sys import setrecursionlimit, exit
from math import ceil, floor, acos, pi
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from functools import reduce
setrecursionlimit(10**8)
RI=lambda x=' ': list(map(int,input().rstrip().split(x)))
RS=lambda x=' ': input().rstrip().split(x)
dX= [-1, 1, 0, 0,-1, 1,-1, 1]
dY= [ 0, 0,-1, 1, 1,-1,-1, 1]
mod=int(1e9+7)
eps=1e-6
MAX=1010
#################################################
n=RI()[0]
s=RS()[0]
pos={}
acceptable={}
for i in range(1,10):
    pos[i]=((i-1)//3 +1, (i-1)%3 + 1)
pos[0]=(4,2)
for v in list(pos.values()):
    acceptable[v]=1
s=list(map(int, list(s)))
cnt=0
for st in acceptable:
    curr=list(st)
    flag=1
    for i in range(1, len(s)):
        curr[0]+=pos[s[i]][0]-pos[s[i-1]][0]
        curr[1]+=pos[s[i]][1]-pos[s[i-1]][1]
        if tuple(curr) not in acceptable:
            flag=0
    if flag:
        cnt+=1
print("YES" if cnt==1 else "NO")
        
        
        


p = [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9],
     [-1, 0, -1]]

n = int(input())
d = [int(x) for x in input()]
s = [(i, j) for i in range(4) for j in range(3) if p[i][j] != -1]
c = [True for _ in s]
m = {((i+1) % 10): s[i] for i in range(len(s))}
for i in range(1, n):
    for j in range(len(s)):
        if not c[j]:
            continue
        try:
            sji = s[j][0] + (m[d[i]][0] - m[d[i-1]][0])
            sjj = s[j][1] + (m[d[i]][1] - m[d[i-1]][1])
            s[j] = (sji, sjj)
            if s[j][0] < 0 or s[j][1] < 0 or p[s[j][0]][s[j][1]] == -1:
                c[j] = False
        except Exception as e:
            c[j] = False
if sum(c) > 1:
    print("NO")
else:
    print("YES")



#   (col, row)
KEYS = {
    1: (0, 0),
    2: (1, 0),
    3: (2, 0),
    4: (0, 1),
    5: (1, 1),
    6: (2, 1),
    7: (0, 2),
    8: (1, 2),
    9: (2, 2),
    0: (1, 3)
}

BOARD = set(KEYS.values())

n = int(input())
number = list(map(int, list(input())))


def add_offset(cell, offset):
    return (cell[0] + offset[0], cell[1] + offset[1])

uniq = True

for posible_starts in BOARD:
    if KEYS[number[0]] != posible_starts:
        all_fit = True
        off = (posible_starts[0] - KEYS[number[0]][0],
               posible_starts[1] - KEYS[number[0]][1])
        for num_part in number:
            if add_offset(KEYS[num_part], off) not in BOARD:
                all_fit = False
                break
        if all_fit:
            uniq = False

if uniq:
    print("YES")
else:
    print("NO")


import sys

def canMoveLeft(digit):
	index = [
	False,	#0
	False,	#1
	True,	#2
	True,	#3
	False,	#4
	True,	#5
	True,	#6
	False,	#7
	True,	#8
	True,	#9
	]
	return index[digit]

def canMoveRight(digit):
	index = [
	False,	#0
	True,	#1
	True,	#2
	False,	#3
	True,	#4
	True,	#5
	False,	#6
	True,	#7
	True,	#8
	False,	#9
	]
	return index[digit]

def canMoveUp(digit):
	index = [
	True,	#0
	False,	#1
	False,	#2
	False,	#3
	True,	#4
	True,	#5
	True,	#6
	True,	#7
	True,	#8
	True,	#9
	]
	return index[digit]

def canMoveDown(digit):
	index = [
	False,	#0
	True,	#1
	True,	#2
	True,	#3
	True,	#4
	True,	#5
	True,	#6
	False,	#7
	True,	#8
	False,	#9
	]
	return index[digit]

n = int(input())
number = [int(i) for i in input()]
#print(number)

movedown = [all([ canMoveDown(i) for i in number ]),
			all([ canMoveUp(i) for i in number ]),
			all([ canMoveLeft(i) for i in number ]),
			all([ canMoveRight(i) for i in number ])]

if any(movedown):
	print('NO')
else:
	print('YES')

#print(movedown)


import sys
sp1 = ['1','4','7']
sp2 = ['1','2','3']
sp3 = ['3','6','9']
sp4 = ['7','0','9']
n = int(input())
s = input()
for i in sp2:
    if i in s:
        if '0' in s:
            print('YES')
            return
        else:    
            for j in sp1:
                if j in s:
                    for k in sp3:
                        if k in s:
                            for t in sp4:
                                if t in s:
                                    print('YES')
                                    return
else:
    print('NO')


3

n = int(input())

str = input()

L = [1, 4, 7]
R = [3, 6, 9]
T = [1, 2, 3]
B = [7, 9]

bl = False
br = False
bt = False
bb = False
b0 = False

for s in str:
    symb = int(s)
    bl = bl or (symb in L)
    br = br or (symb in R)
    bt = bt or (symb in T)
    bb = bb or (symb in B)
    b0 = b0 or (symb == 0)

if (bl and br and bt and bb) or (bt and b0):
    print("YES")
else:
    print("NO")


input()
a = list(map(int, str(input())))

d = {
    1: (0, 0),
    2: (1, 0),
    3: (2, 0),
    4: (0, 1),
    5: (1, 1),
    6: (2, 1),
    7: (0, 2),
    8: (1, 2),
    9: (2, 2),
    0: (1, 3)
}

r = list(map(lambda x: (d[x][0] + 1, d[x][1]), a))
l = list(map(lambda x: (d[x][0] - 1, d[x][1]), a))
t = list(map(lambda x: (d[x][0], d[x][1] + 1), a))
b = list(map(lambda x: (d[x][0], d[x][1] - 1), a))
rt = list(map(lambda x: (d[x][0] + 1, d[x][1] + 1), a))
rb = list(map(lambda x: (d[x][0] + 1, d[x][1] - 1), a))
lt = list(map(lambda x: (d[x][0] - 1, d[x][1] + 1), a))
lb = list(map(lambda x: (d[x][0] - 1, d[x][1] - 1), a))

if all([x in d.values() for x in r])\
        or all([x in d.values() for x in l])\
        or all([x in d.values() for x in t])\
        or all([x in d.values() for x in b])\
        or all([x in d.values() for x in rt])\
        or all([x in d.values() for x in rb]) \
        or all([x in d.values() for x in lt])\
        or all([x in d.values() for x in lb]):
    print("NO")
else:
    print("YES")

n = int(input())
s = input()
fill = [[False for i in range(3)] for j in range(4)]
for i in s:
    if i == "0":
        j = 10
    else:
        j = ord(i)-ord('1') #0, 1, 2, 3... 8
    fill[j//3][j%3] = True
#for i in fill:
#    print(i)
top = fill[0][0] or fill[0][1] or fill[0][2]
bottom = fill[2][0] or fill[3][1] or fill[2][2]
left = fill[0][0] or fill[1][0] or fill[2][0]
right = fill[0][2] or fill[1][2] or fill[2][2]
#print(left, right, fill[3][1], (not left or not right)and not fill[3][1])
if ((not left or not right)and not fill[3][1]) or not top or not bottom:
    print("NO")
else:
    print("YES")


n = int(input())
# a, b = map(int, input().split())
number = input()

numpad = [['1', '2', '3'],
          ['4', '5', '6'],
          ['7', '8', '9'],
          [None, '0', None]]


def get_coordinates(digit):
    if digit in ('1', '2', '3'):
        first_coordinate = 0
        second_coordinate = int(digit) - 1
    elif digit in ('4', '5', '6'):
        first_coordinate = 1
        second_coordinate = int(digit) - 4
    elif digit in ('7', '8', '9'):
        first_coordinate = 2
        second_coordinate = int(digit) - 7
    else:
        first_coordinate = 3
        second_coordinate = 1
    return first_coordinate, second_coordinate


def add(v1, v2):
    return v1[0] + v2[0], v1[1] + v2[1]


def sub(v1, v2):
    return v1[0] - v2[0], v1[1] - v2[1]


def try_it(start_digit, what_to_do):
    current_coordinates = get_coordinates(start_digit)
    for move in what_to_do:
        current_coordinates = add(current_coordinates, move)
        if current_coordinates[0] < 0 or current_coordinates[1] < 0:
            return False
        try:
            _ = numpad[current_coordinates[0]][current_coordinates[1]]
        except IndexError:
            return False
        if _ is None:
            return False
    return True


sequence = []
for i in range(n - 1):
    sequence.append(sub(get_coordinates(number[i + 1]), get_coordinates(number[i])))

for digit in set('1234567890') - set(number[0]):
    if try_it(digit, sequence):
        print('NO')
        break
else:
    print('YES')