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:  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":    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?

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.

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.

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

import sys
input = sys.stdin.readline

n = int(input())

m = [list("123")] + [list("456")] + [list("789")] + [[False, "0", False]]

digits = list(input().strip())

digits_m = []
dr = [-1, 1, 0, 0]
dc = [0, 0, -1, 1]

for d in digits:
  for i in range(4):
    for j in range(3):
      if d == m[i][j]:
        digits_m.append((i, j))
ans = "YES"
for i in range(4):
  cuteness = []
  for r, c in digits_m:
    try:
      validations = [
        r + dr[i] >= 0 and m[r + dr[i]][c],
        c + dc[i] >= 0 and m[r][dc[i] + c]
      ]
      if all(validations):
        cuteness.append(True)
      else:
        cuteness.append(False)
    except:
      cuteness.append(False)
  if all(cuteness):
    ans = "NO"

print ans

# -*- coding: utf-8 -*-
"""
Created on Fri Jul 08 12:59:00 2016

@author: Kirill.Chulkov
"""

n = int(input())
ph_num = raw_input()
flg = 1

true_list = [7, 8, 9, 12, 13, 14, 17, 18, 19, 23]
res = []
for letter in ph_num:
    if letter == '0':
        res.append(28)
    elif letter == '1':
        res.append(12)
    elif letter == '2':
        res.append(13)
    elif letter == '3':
        res.append(14)
    elif letter == '4':
        res.append(17)
    elif letter == '5':
        res.append(18)
    elif letter == '6':
        res.append(19)
    elif letter == '7':
        res.append(22)
    elif letter == '8':
        res.append(23)
    else:
        res.append(24)
j = 0
arr = [5, -10, 4, 2, 0]
while flg and j <= 3:
    j += 1
    flg = 0
    for i in xrange(len(res)):
        if res[i] not in true_list:
            flg = 1
        res[i] += arr[j]
if flg:
    print 'YES'
else:
    print 'NO'

n = int(input())
a = input()

#normalize to 0 start
digits = [int(digit) - 1 for digit in a]

#normalize 0 to 10
for i in range(len(digits)):
    if digits[i] == -1:
        digits[i] = 10

#create phone buttons representation
phone = [[3 * j + i for i in range(3)] for j in range(4)]

#normalize
phone[3][0] = -1
phone[3][1] = 10
phone[3][2] = -1

#construct pattern
pattern = []

for i in range(len(digits) - 1):
    pattern.append([int(digits[i + 1] / 3) - int(digits[i] / 3), digits[i + 1] % 3 - digits[i] % 3])

# check uniqueness of pattern

def checkPattern(x, y):
    for move in pattern:
        x += move[0]
        y += move[1]
        if not (4 > x >= 0 and 3 > y >= 0):
            return 0
        if phone[x][y] == -1:
            return 0

    return 1

ok = 0

#try all start points
for i in range(12):
    #normalize
    if phone[int(i / 3)][i % 3] != -1:
        ok += checkPattern(int(i / 3), i % 3)

if ok == 1:
    print("YES")
else:
    print("NO")

#!/usr/bin/python3

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")

n = int(raw_input())
s = set(raw_input().strip())
s1 = set("1234568")
s2 = set("4567890")
s3 = set("147258")
s4 = set("258369")
print "NO" if s.issubset(s1) or s.issubset(s2) or s.issubset(s3) or s.issubset(s4) else "YES"

d = {
        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),
        0 : (1, 0)
        }
s = set(d.values())

def make_shift(shift):
    dx, dy = shift
    def inner(point):
        x, y = point
        return x + dx, y + dy
    return inner

left = make_shift((-1, 0))
right = make_shift((1, 0))
up = make_shift((0, 1))
down = make_shift((0, -1))

raw_input()
nums = [int(x) for x in raw_input()]
for direction in [left, right, up, down]:
    if all(p in s for p in map(direction, [d[x] for x in nums])):
        print 'NO'
        break
else:
    print 'YES'

dirs = {
    'up': [4, 5, 6, 7, 8, 9, 0],
    'down': [1, 2, 3, 4, 5, 6, 8],
    'left': [2, 3, 5, 6, 8, 9],
    'right': [1, 2, 4, 5, 7, 8],
}

input()
num = input()
ds = [int(x) for x in num]

dirsleft = {'up', 'down', 'left', 'right'}

for d in ds:
    for k, v in dirs.items():
        if d not in v and k in dirsleft:
            dirsleft.remove(k)
print('YES' if not dirsleft else 'NO')

import sys

def gl():
    return sys.stdin.readline().strip()

def gls():
    return gl().split()

def gi():
    return int(gl())

def gis():
    return map(int, gls())

def gfs():
    return map(float, gls())

def up(n):
    if n==0:
        return 8
    if n<4:
        return -1
    return n-3

def left(n):
    if n==0:
        return -1
    if (n-1)%3==0:
        return -1
    return n-1

def down(n):
    if n==0:
        return -1
    if n==8:
        return 0
    if n>6:
        return -1
    return n+3

def right(n):
    if n==0:
        return -1
    if n%3==0:
        return -1
    return n+1

def solve():
    n = gi()
    line = [int(a) for a in gl()]

    if sum([1 for a in line if up(a)>=0])==n:
        return False
    if sum([1 for a in line if left(a)>=0])==n:
        return False
    if sum([1 for a in line if down(a)>=0])==n:
        return False
    if sum([1 for a in line if right(a)>=0])==n:
        return False
    return True

ans = solve()
if ans:
    print "YES"
else:
    print "NO"

n = int(input())
s = input()
h, v = True, True
cnt = [s.count(chr(i + ord('0'))) for i in range(10)]
if (cnt[0] or cnt[7] or cnt[9]) and (cnt[1] or cnt[2] or cnt[3]):
    v = False
if cnt[0] and (cnt[1] or cnt[2] or cnt[3]):
    h = False
if (cnt[1] or cnt[4] or cnt[7]) and (cnt[3] or cnt[6] or cnt[9]):
    h = False
print('NO' if v or h else 'YES')

import sys
def mapi(): return map(int,input().split())
def maps(): return map(str,input().split())
#--------------------------------------------------

n = int(input())
s = input().strip()
a = [True for i in range(10)]
for i in range(n):
	c = int(s[i])
	a[c] = False
inc = 0
if a[1] and a[2] and a[3]:
	inc = -3
if a[7] and a[9] and a[0]:
	inc = +3
if a[1] and a[4] and a[7] and a[0]:
	inc = -1
if a[3] and a[6] and a[9] and a[0]:
	inc = +1
if inc == 0:
	print("YES")
else:
	print("NO")

import itertools
import sys

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

def applyShiftVector(value,vector):
	return (value[0] + vector[0], value[1] + vector[1])

def checkLimit(cordinates):
	y,x = cordinates
	if y < 0 or y > 3:
		return False
	if x < 0 or x > 2:
		return False
	if y == 3:
		return x == 1
	else:
		return True

def shift_and_check(values, shiftVector):
	shiftX, shiftY = shiftVector
	if shiftX == 0 and shiftY == 0:
		return False
	for value in values:
		newCord = applyShiftVector(CORD_DICT[int(value)], shiftVector)
		if not checkLimit(newCord):
			return False
	return True

n = int(input())
values = input()

for shift in itertools.product([-1, 0 ,1], repeat = 2):
	if shift_and_check(values, shift):
		print('NO')
		sys.exit(0)

print('YES')

n, s = input(), set(input())
print(('NO', 'YES')[all(set(t) & s for t in '0147 0369 079 123'.split())])

n = int(raw_input())
seq = raw_input()
coord = [[] for i in range(10)]
coord[1] = [0,0]
coord[2] = [1,0]
coord[3] = [2,0]
coord[4] = [0,1]
coord[5] = [1,1]
coord[6] = [2,1]
coord[7] = [0,2]
coord[8] = [1,2]
coord[9] = [2,2]
coord[0] = [1,3]
vecs = []
for i in range(len(seq)-1):
    vecs.append([coord[int(seq[i+1])][0]-coord[int(seq[i])][0],coord[int(seq[i+1])][1]-coord[int(seq[i])][1]])
cnt = 0
for i in range(10):
    curr = coord[i]
    poss = True
    for vec in vecs:
        curr[0] += vec[0]
        curr[1] += vec[1]
        if not (curr[0]<3 and curr[0]>=0):
            poss = False
        else:
            if curr[1]<3 and curr[1]>=0:
                pass
            elif curr[1] == 3 and curr[0] == 1:
                pass
            else:
                poss = False
    if poss:
        cnt += 1
if cnt > 1:
    print "NO"
else:
    print "YES"

import sys

MOVES = {
    #up,down,right,left
    '0': (1,0,0,0),
    '1': (0,1,1,0),
    '2': (0,1,1,1),
    '3': (0,1,0,1),
    '4': (1,1,1,0),
    '5': (1,1,1,1),
    '6': (1,1,0,1),
    '7': (1,0,1,0),
    '8': (1,1,1,1),
    '9': (1,0,0,1)
}

def check(n, digits):
    for i in xrange(4):
        total = sum(MOVES[d][i] for d in digits)
        if total == len(digits):
            return False
    return True

if __name__ == "__main__":
    n = int(sys.stdin.readline().strip())
    digits = sys.stdin.readline().strip()
    if check(n, digits):
        print "YES"
    else:
        print "NO"

import sys
read=lambda:sys.stdin.readline().rstrip()
readi=lambda:int(sys.stdin.readline())
writeln=lambda x:sys.stdout.write(str(x)+"\n")
write=lambda x:sys.stdout.write(x)
def solve(memory, N):
    if N == 1:
        return "NO"
    pad=[[-1]*7 for _ in range(9)]
    n = 1
    npos = [[-1,-1]]*10
    chkOrder = []
    for i in range(2, 5):
        for j in range(2, 5):
            pad[i][j] = n
            npos[n] = (i, j)
            chkOrder.append((i, j))
            n += 1
    pad[5][3] = 0
    npos[0] = (5, 3)
    chkOrder.append((5,3))

    vecs = [(0,0)]
    sy, sx = npos[int(memory[0])]
    for i in range(N-1):
        y, x = npos[int(memory[i])]
        ny, nx = npos[int(memory[i+1])]
        vecs.append((ny-y, nx-x))

    for y, x in chkOrder:
        if (sy, sx) == (y, x):
            continue
        for t in range(N):
            dy,dx = vecs[t]
            y, x = y + dy, x + dx
            if pad[y][x] == -1:
                break
        else:
            return "NO"
    return "YES"

N=readi()
mem = read()
writeln(solve(mem, N))

n = input()
a = map(int, list(raw_input()))
ref = [[0,0], [0,1], [0,2], [1,0], [1,1], [1,2], [2,0], [2,1], [2,2], [3,1]]
mapp = {1:[0,0], 2:[0,1], 3:[0,2], 4:[1,0], 5:[1,1], 6:[1,2], 7:[2,0], 8:[2,1], 9:[2,2], 0:[3,1]}
b = [mapp[a[i]] for i in range(n)]
c = [[b[i][0] - 1, b[i][1]] for i in range(n)]
for i in range(n):
    if c[i] not in ref:
        break
else:
    print "NO"
    exit(0)
c = [[b[i][0] + 1, b[i][1]] for i in range(n)]
for i in range(n):
    if c[i] not in ref:
        break
else:
    print "NO"
    exit(0)
c = [[b[i][0], b[i][1] - 1] for i in range(n)]
for i in range(n):
    if c[i] not in ref:
        break
else:
    print "NO"
    exit(0)
c = [[b[i][0], b[i][1] + 1] for i in range(n)]
for i in range(n):
    if c[i] not in ref:
        break
else:
    print "NO"
    exit(0)
print "YES"

def get(a):
    if a == '0':
        return([3, 1])
    else:
        a = int(a)
        return([(a - 1) // 3, (a - 1) % 3])

def check(a):
    if (-1 < a[0] < 3 and -1 < a[1] < 3) or (a == [3, 1]):
        return True
    return False

n = int(input())
s = input()
Q = []
for i in range(3):
    for j in range(3):
        Q.append([i, j])
Q.append([3, 1])
prev = get(s[0])
for i in range(1, len(s)):
    now = get(s[i])
    fir = now[0] - prev[0]
    sec = now[1] - prev[1]
    q = []
    for pair in Q:
        new = [pair[0] + fir, pair[1] + sec]
        if check(new):
            q.append(new)
    prev = now
    Q = q
if len(Q) > 1:
    print('NO')
else:
    print('YES')

def gr(val):
	if val == -1:
		return 3;
	return val // 3;

def gc(val):
	if val == -1:
		return 1;
	return val % 3;

def isvalid(row, col):
	if row == 3:
		return col == 1;
	return row >= 0 and row <= 2 and col >= 0 and col <= 2

n = int(input())
digits = [val - 1 for val in list(map(int, list(input())))]
loc = [(gr(val), gc(val)) for val in digits]

def solve():
	for rowoff in range(-5, 5):
		for coloff in range(-5, 5):
			if rowoff == 0 and coloff == 0: continue
			works = True
			for r, c in loc:
				if not isvalid(r + rowoff, c + coloff):
					works = False
			if works:
				print("NO")
				return
	print("YES")

solve()

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

b=0
if a[1] and a[2] and a[3]:
    b= -3
if a[7] and a[9] and a[0]:
    b= +3
if a[1] and a[4] and a[7] and a[0]:
	b= -1
if a[3] and a[6] and a[9] and a[0]:
	b= +1
if b==0:
    print "YES"
else:
    print "NO"

def main():
    n = int(raw_input())
    arr = set(map(int, raw_input()))

    up = arr.intersection({1, 2, 3})
    dwn = arr.intersection({0, 7, 9})
    rt = arr.intersection({0, 3, 6, 9})
    lft = arr.intersection({0, 1, 4, 7})

    print 'NO' if len(up) == 0 or len(dwn) == 0 or len(rt) == 0 or len(lft) == 0 else 'YES'

main()

n = int(raw_input())
s = raw_input()
if ('1' in s or '2'in s or '3' in s)and('1' in s or '4' in s or '7' in s)and('7'in s or '0' in s or '9' in s)and('3'in s or '6'in s or '9' in s):
    print "YES"
elif ('1' in s or '2'in s or '3' in s)and('0' in s):
    print "YES"
else:print"NO"

class Pos:
    x = y = 0
    def __init__(self, a, b):
        self.x = a
        self.y = b
    def sub(self, a):
        return Pos(self.x - a.x, self.y - a.y)
    def add(self, a):
        return Pos(self.x + a.x, self.y + a.y)
def locate(a):
    return Pos(3, 1) if a == 0 else Pos((a - 1) // 3, (a - 1) % 3)
_ = raw_input()
seq = raw_input()
list = []
for i in range(1, len(seq)):
    list.append(locate(int(seq[i])).sub(locate(int(seq[i - 1]))))
flag = False
for i in range(0, 9):
    flag2 = False
    if i == int(seq[0]):
        continue
    a = locate(i)
    for j in list:
        a = a.add(j)
        if (a.x == 3 and a.y == 1):
            continue
        if(a.x == 3 and a.y != 1):
            flag2 = True
            break
        if (a.x not in range(0, 3)) or (a.y not in range(0, 3)) and (a.x != 3 and a.y != 1):
            flag2 = True
            break
    flag = True if not flag2 else False
    if flag:
        break
print 'NO' if flag else 'YES'

left = 0
right = 1
up = 2
down = 3

buttons = []
#0
buttons.append({left:False, right:False, up:True, down:False })
#1
buttons.append({left:False, right:True, up:False, down:True })
#2
buttons.append({left:True, right:True, up:False, down:True })
#3
buttons.append({left:True, right:False, up:False, down:True })
#4
buttons.append({left:False, right:True, up:True, down:True })
#5
buttons.append({left:True, right:True, up:True, down:True })
#6
buttons.append({left:True, right:False, up:True, down:True })
#7
buttons.append({left:False, right:True, up:True, down:False })
#8
buttons.append({left:True, right:True, up:True, down:True })
#9
buttons.append({left:True, right:False, up:True, down:False })

n = eval( input(  ) )
stroke = input(  )

can = [True,True,True,True]

for button in stroke:
    button = int(button)
    if buttons[button][left] == False:
        can[left] = False
    if buttons[button][right] == False:
        can[right] = False
    if buttons[button][up] == False:
        can[up] = False
    if buttons[button][down] == False:
        can[down] = False

canMove = False

for i in range(4):
    if can[i] == True:
        canMove = True

if canMove == True:
    print("NO")
else:
    print("YES")

left = {
    1: None,
    2: 1,
    3: 2,
    4: None,
    5: 4,
    6: 5,
    7: None,
    8: 7,
    9: 8,
    0: None
}

right = {
    1: 2,
    2: 3,
    3: None,
    4: 5,
    5: 6,
    6: None,
    7: 8,
    8: 9,
    9: None,
    0: None
}

up = {
    1: None,
    2: None,
    3: None,
    4: 1,
    5: 2,
    6: 3,
    7: 4,
    8: 5,
    9: 6,
    0: 8
}

down = {
    1: 4,
    2: 5,
    3: 6,
    4: 7,
    5: 8,
    6: 9,
    7: None,
    8: 0,
    9: None,
    0: None
}

def func(comb, d):
    for element in comb:
        if d[int(element)] is None:
            return False
    return True

if __name__ == "__main__":
    n = int(input())
    comb = str(input())

    if func(comb, left) == True or func(comb, right) == True or func(comb, up) == True or func(comb, down) == True:
        print("NO")
    else:
        print("YES")

def main(string, size):
    if size == 1:
        return False

    vis = [False] * 10
    for i in string:
        vis[int(i)] = True

    func = lambda x: not vis[x]
    if all(map(func, (1, 2, 3))):
        return False
    if vis[0]:
        return True
    if all(map(func, (1, 4, 7))):
        return False
    if all(map(func, (3, 6, 9))):
        return False
    if all(map(func, (7, 0, 9))):
        return False
    return True

n = int(input())
string = input()
print('YES' if main(string, n) else 'NO')

def main():
	n = input()
	s = input()
	print(solver(s))

def solver(s):
	coordDict = {i: ((i - 1) // 3, (i - 1) % 3) for i in range(1, 10)}
	coordDict[0] = (3, 1)
	# print(coordDict)
	coordinates = [coordDict[int(c)] for c in s]
	# print(coordinates)
	rows = [row for (row, col) in coordinates]
	cols = [col for (row, col) in coordinates]
	rowSize = max(rows) - min(rows) + 1
	colSize = max(cols) - min(cols) + 1
	# print(rows)
	# print(cols)
	if rowSize < 3:
		return "NO"
	elif rowSize == 3:
		if colSize < 3 or \
		("7" not in s and "9" not in s) or \
		"0" in s:
			return "NO"
		else:
			return "YES"
	elif rowSize == 4:
		return "YES"
	else:
		assert(False)

def getRowsCols(coordinates):
	for (row, col) in coordinates:
		pass

# print(solver("586"))
# print(solver("09"))
# print(solver("123456789"))
# print(solver("911"))

main()

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")

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')

if __name__ == '__main__':
    main()

d = ['U', 'RD', 'LRD', 'LD', 'UDR', 'UDLR', 'UDL', 'UR', 'UDLR', 'UL']
n, v = int(input()), set('UDLR')
for ch in input():
    v &= set(d[ord(ch) - ord('0')])
print('NO' if v else 'YES')

'''
text = list()
while True:
    try:
        l = raw_input()
    except EOFError:
        break
    else:
	    text.append(l)
'''

n = int(raw_input())
num = raw_input()

cor = []

for i in xrange(n):
    d =[]
    if num[i] != '0':
        d.append((int(num[i])-1)//3)
        d.append((int(num[i])-1)%3)
    else:
        d.append(3)
        d.append(1)
    try:
        cor.append(d)
    except:
        continue
#print(cor)
q = True

#Up
for j in cor:
    y_up = j[0] + 1
    if y_up > 2 and j != [2,1]:
        q = False
        #print('up - no')
    if q == False:
        break

#Down
if q == False:
    q = True
    for j in cor:
        y_down = j[0] - 1
        if y_down < 0:
            q = False
            #print('down - no')
        if q == False:
            break

#Left
if q == False:
    q = True
    for j in cor:
        x_l = j[1] - 1
        if x_l < 0 or j[0] == 3:
            q = False
            #print('left - no')
        if q == False:
            break

#Right
if q == False:
    q = True
    for j in cor:
        x_r = j[1] + 1
        if x_r > 2 or j[0] == 3:
            q = False
            #print('right - no')
        if q == False:
            break

if q == False:
    print('YES')
else:
    print('NO')

n = int(input())
digits = input()

pos = []
for c in digits:
  first_digit = int(c)
  if first_digit == 0:
    start_pos = (3, 1)
  else:
    start_pos = ((first_digit-1)//3,(first_digit-1) % 3)
  pos.append(start_pos)

if ((3,1) in pos and ((0, 0) in pos or (0,1) in pos or (0,2) in pos)):
  print("YES")
else:
  maxX = 0
  minX = 2
  maxY = 0
  minY = 2
  for (x,y) in pos:
    maxX = max(x, maxX)
    minX = min(x, minX)
    maxY = max(y, maxY)
    minY = min(y, minY)
  if minX == 0 and maxX == 2 and minY == 0 and maxY == 2:
    if ((2,2) not in pos and (2,0) not in pos):
      print("NO")
    else:
      print("YES")
  else:
    print("NO")
# 1502474499639

n = int(raw_input())
s = raw_input()
flagUp = False
flagDown = False
flagLeft = False
flagRight = False
for ch in s:
	if ch == '1' or ch == '2' or ch == '3':
		flagUp = True
	if ch == '7' or ch == '0' or ch == '9':
		flagDown = True
	if ch == '1' or ch == '4' or ch == '7' or ch == '0':
		flagLeft = True
	if ch == '3' or ch == '6' or ch == '9' or ch == '0':
		flagRight = True
if flagUp and flagDown and flagLeft and flagRight:
	print "YES"
else:
	print "NO"

n = int(raw_input())
s = raw_input()
a = []
for i in range(10):
	a.append(True)
for i in range(n):
	c = int(s[i])
	a[c] = False
inc = 0
if a[1] and a[2] and a[3]:
	inc = -3
if a[7] and a[9] and a[0]:
	inc = +3
if a[1] and a[4] and a[7] and a[0]:
	inc = -1
if a[3] and a[6] and a[9] and a[0]:
	inc = +1
if inc == 0:
	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(raw_input())
l = raw_input()

if n == 1:
	print "NO"
	exit()

coords = []

for c in l:
	coord = None
	if c == '0':
		coord = [1, 3]
	else:
		col = int(c)-1
		coord = [col % 3, col / 3]
	coords.append(coord)

for i in range(-4, 4):
	for j in range(-4, 4):
		if i == 0 and j == 0:
			continue
		cc = coords[:]
		ok = True
		for k in range(0, n):
			c1 = cc[k][0] + i
			c2 = cc[k][1] + j
			if c1 < 0 or c1 > 2 or c2 < 0 or c2 > 3 or (c2 == 3 and c1 != 1):
				ok = False
				break
		if ok:
			print "NO"
			exit()

print "YES"

#! /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')
        sys.exit(0)

print('YES')

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

def exe() :
    if 1 not in l and 2 not in l and 3 not in l :
        print('NO')
        return
    if 0 in l:
        print('YES')
        return
    if 1 not in l and 4 not in l and 7 not in l :
        print('NO')
        return
    if 3 not in l and 6 not in l and 9 not in l :
        print('NO')
        return
    if 7 not in l and 0 not in l and 9 not in l :
        print('NO')
        return
    print('YES')

exe()

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

if '0' in s:
    if '1' in s or '2' in s or '3' in s:
        print("YES")
    else:
        print("NO")
else:
    if '1' in s and '9' in s:
        print("YES")
        exit()
    if '3' in s and '7' in s:
        print("YES")
        exit()

    if '1' in s and '6' in s and '7' in s:
        print("YES")
        exit()
    if '3' in s and '4' in s and '9' in s:
        print("YES")
        exit()

    if '2' in s and '7' in s and '9' in s:
        print("YES")
        exit()

    if '1' in s and '6' in s and '7' in s:
        print("YES")
        exit()

    if '2' in s and '4' in s and '9' in s:
        print("YES")
        exit()

    if '2' in s and '6' in s and '7' in s:
        print("YES")
        exit()

    print("NO")

n = int(raw_input())
s = raw_input()
a = []
for i in range(10):
	a.append(True)
for i in range(n):
	a[int(s[i])] = False
inc = 0
if a[1] and a[2] and a[3]: #if there is no 1, 2, 3 at all
	inc = -3
if a[7] and a[0] and a[9]:
	inc = 3
if a[1] and a[4] and a[7] and a[0]:
	inc = 1
if a[3] and a[6] and a[9] and a[0]:
	inc = -1

if inc == 0:
	print "YES"
else:
	print "NO"

n = input()
num = raw_input()
nmap = [(3,1),(0,0), (0,1), (0,2), (1,0), (1,1), (1,2), (2,0),(2,1),(2,2)]

mp = []
prev = nmap[int(num[0])]
diff = (0,0)
for y in num[1:]:
    x = nmap[int(y)]
    diff = (x[0] - prev[0], x[1] - prev[1])
    mp.append(diff)
    prev = x

cnt = 0
for i in xrange(10):
    fg = 1
    tmp = nmap[i]
    temp = []
    for x in mp:
        v = (x[0] + tmp[0], x[1] + tmp[1])
        i,v,tmp
        if (v[0] == 3 and v[1] != 1) or  v[1] < 0 or v[0] < 0 or v[1] >=3 or v[0] > 3:
            fg = 0
            break
        else:
            temp.append(v)
        tmp = v
    if fg == 1:
        cnt += 1
if cnt == 1:
    print 'YES'
else:
    print 'NO'

class Move:
	def __init__(self,dx,dy):
		self.dx = dx
		self.dy = dy

x=[ 1, 0, 1, 2, 0, 1, 2, 0, 1, 2 ]
y=[ 3, 0, 0, 0, 1, 1, 1, 2, 2, 2 ]

length=int(input())
inStr=input()

numlist=list(inStr)

currentX = 1
currentY = 1

moveList = []

for num in numlist:
	iNum = int(num)
	dx = x[iNum] - currentX
	currentX = x[iNum]
	dy = y[iNum] - currentY
	currentY = y[iNum]
	# print( "dx="+str(dx) + ",dy=" + str(dy))
	moveList.append( Move( dx, dy ) )

bExistOther = False
for x in range(3):
	if bExistOther == True:
		break
	for y in range(4):
		if bExistOther == True:
			break

		if x == 1 and y == 1:
			continue

		if y == 3:
			if x == 0 or x == 2:
				continue

		# print( "x="+str(x) + ",y=" + str(y))
		currentX = x
		currentY = y
		bExistOther = True
		for move in moveList:
			currentX += move.dx
			currentY += move.dy
			# print(currentX)
			# print(currentY)
			if currentX < 0 or 2 < currentX:
				bExistOther = False
				break
			elif currentY < 0 or 3 < currentY:
				bExistOther = False
				break
			elif currentY == 3 and ( currentX == 0 or currentX == 2):
				bExistOther = False
				break

if False == bExistOther:
	print('YES')
else:
	print('NO')

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')

keys = {'1': (1, 1), '2': (1, 2), '3': (1, 3),
        '4': (2, 1), '5': (2, 2), '6': (2, 3),
        '7': (3, 1), '8': (3, 2), '9': (3, 3),
                     '0': (4, 2)}
input()
num = input()
left = right = up = down = 0
contains_zero = False
contains_seven = False
contains_eight = False
contains_nine = False
for ch in num:
    y, x = keys[ch]

    if ch == '0':
        contains_zero = True
    if ch == '7':
        contains_seven = True
    if ch == '8':
        contains_eight = True
    if ch == '9':
        contains_nine = True

    if left == 0:
        left = x
    elif x < left:
        left = x

    if up == 0:
        up = y
    elif y < up:
        up = y

    if right == 0:
        right = x
    elif x > right:
        right = x

    if down == 0:
        down = y
    elif y > down:
        down = y

if contains_zero:
    if up > 1:
        answer = True
    else:
        answer = False

elif left > 1 or right < 3 or down < 3 or up > 1:
    answer = True
elif contains_eight and not contains_nine and not contains_seven:
    answer = True
else:
    answer = False

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

n = int(raw_input())
s = set(raw_input().strip())
s1 = set("1234568")
s2 = set("4567890")
s3 = set("147258")
s4 = set("258369")
print "NO" if s.issubset(s1) or s.issubset(s2) or s.issubset(s3) or s.issubset(s4) else "YES"

#from operator import itemgetter, attrgetter, methodcaller
#from collections import Counter, defaultdict
#from fractions import gcd
#import sys
#import math

def shiftDown(num):
	for n in num:
		if n in ['7', '0', '9']:
			return False
	return True

def shiftUp(num):
	for n in num:
		if n in ['1', '2', '3']:
			return False
	return True

def shiftLeft(num):
	for n in num:
		if n in ['1', '4', '7', '0']:
			return False
	return True

def shiftRight(num):
	for n in num:
		if n in ['3', '6', '9', '0']:
			return False
	return True

def main():
	n = int(raw_input())
	num = raw_input()

	res = shiftRight(num) or shiftLeft(num) or shiftUp(num) or shiftDown(num)
	if not res:
		print "YES"
	else:
		print "NO"

if __name__ == "__main__":
   main()

n = int(raw_input())
s = raw_input()
if ('1' in s or '2'in s or '3' in s)and('1' in s or '4' in s or '7' in s)and('7'in s or '0' in s or '9' in s)and('3'in s or '6'in s or '9' in s):
    print "YES"
elif ('1' in s or '2'in s or '3' in s)and('0' in s):
    print "YES"
else:print"NO"

raw_input()
s = set(raw_input().strip())
sets = map(set, ("1234568", "4567890", "147258", "258369"))
print "NO" if any(s.issubset(i) for i in sets) else "YES"

n = int(input())
number = input()

up = {1, 2, 3}
down = {7, 0, 9}
left = {1, 4, 7}
right = {3, 6, 9}

u, d, l, r = False, False, False, False

for i in number:
    i = int(i)
    if i in up:
        u = True
    if i in down:
        d = True
    if i in left:
        l = True
    if i in right:
        r = True

if (u and '0' in number) or (u and d and l and r):
    print('YES')
else:
    print('NO')

L=[[1,2,3],
   [4,5,6],
   [7,8,9],
   [-1,0,-1]]
L1=[]
def wq(tmp,to):
    fr=[]
    fr1=[]
    for i in range(4) :
        if tmp in L[i] :
            fr=[i,L[i].index(tmp)]
            break
    for i in range(4) :
        if to in L[i] :
            fr1=[i,L[i].index(to)]
            break
    L1.append([fr[0]-fr1[0],fr[1]-fr1[1]])

def chek(x) :
    if x[0]<0 or x[1]<0 or x[0]>3 or x[1]>2  :
        return False
    else :
        if L[x[0]][x[1]]==-1 :

            return False
    for y in L1 :
        x[0]-=y[0]
        x[1]-=y[1]

        if x[0]<0 or x[1]<0 or x[0]>3 or x[1]>2  :

            return False
        else :
            if L[x[0]][x[1]]==-1 :

                return False

    return True

n=int(input())
s=input()
for i in range(1,n) :
    wq(int(s[i-1]),int(s[i]))
d=[]
for i in range(4) :
    if int(s[0]) in L[i] :
        d=[i,L[i].index(int(s[0]))]
        break

for i in range(-1,2) :
    for j in range(-1,2) :

        if chek([d[0]+i,d[1]+j]) :

            if i!=0 or j!=0 :

                print("NO")
                exit()
print("YES")

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

groups = [set('4567890'), set('1234568'), set('235689'), set('124578')]

ans = True

for group in groups:
    if all(c in group for c in s):
        ans = False

print('YES' if ans else 'NO')

n = int(input())

T = [False for i in range(10)]
s = input()

for i in s:
    T[int(i)] = True

if ((T[1] or T[2] or T[3]) and (T[7] or T[0] or T[9]) and (T[1] or T[4] or T[7]) and (T[3] or T[6] or T[9])) \
        or (T[0] and (T[1] or T[2] or T[3])):
    print("YES")
else:
    print("NO")

# -*- coding: utf-8 -*-

def up_down_possible(number):
    return all([n in (1, 2, 3, 4, 5, 6, 7, 8, 9, 11) for n in number])

def left_possible(number_mods, number):
    if 11 in number:
        return False
    number_mods_ = [3 if n == 0 else n for n in number_mods]
    return all([n >= 2 for n in number_mods_])

def right_possible(number_mods, number):
    if 11 in number:
        return False
    number_mods_ = [3 if n == 0 else n for n in number_mods]
    return all([n <= 2 for n in number_mods_])

if __name__ == '__main__':
    n = int(raw_input())
    raw_number = raw_input()
    number = [11 if c == '0' else int(c) for c in raw_number]
    number_up = map(lambda x: x-3, number)
    number_down = map(lambda x: x+3, number)
    up_condition = up_down_possible(number_up)
    down_condition = up_down_possible(number_down)
    number_mods = [n % 3 for n in number]
    left_condition = left_possible(number_mods, number)
    right_condition = right_possible(number_mods, number)
    if any((up_condition, down_condition, left_condition, right_condition)):
        print 'NO'
    else:
        print 'YES'

n = int(raw_input())
s = raw_input()
LeftCol = False
RightCol = False
TopRow = False
BottomRow = False

if '1' in s or '2' in s or '3' in s:
	TopRow = True
if '1' in s or '4' in s or '7' in s:
	LeftCol = True
if '3' in s or '6' in s or '9' in s:
	RightCol = True
if '7' in s or '8' in s or '9' in s:
	BottomRow = True

if '0' not in s:
	if LeftCol == False or RightCol == False or BottomRow == False or TopRow == False:
		print 'NO'
	else:
		if '8' in s and '7' not in s and '9' not in s:
			print 'NO'
		else:
			print 'YES'
else:
	if TopRow == False:
		print 'NO'
	else:
		print 'YES'

def onBottomside(n):
    for c in n:
        if c in ['7', '0', '9']:
            return True
    return False

def onUpside(n):
    for c in n:
        if c in ['1', '2', '3']:
            return True
    return False

def onLeftside(n):
    for c in n:
        if c in ['1', '4', '7', '0']:
            return True
    return False

def onRightside(n):
    for c in n:
        if c in ['3', '6', '9', '0']:
            return True
    return False

input()
n=raw_input()
if onRightside(n) and onLeftside(n) and onUpside(n) and onBottomside(n):
    print "YES"
else:
    print "NO"

n=int(input())
inp=[int(i) for i in input()]
a=[[1,2,3],[1,4,7,0],[7,0,9],[3,6,9,0]]
res='YES'
for i in a:
    for j in i:
        if j in inp:
            break
    else:
        res='NO'
print(res)

n = raw_input()
num = raw_input()

if ('0' in num)and(('1' in num)or('2' in num)or('3' in  num)):
    print('YES')

else:
    if (not(('1' in num)or('2' in num)or('3' in  num)))or(not(('1' in num)or('4' in num)or('7' in  num)))or(not(('3' in num)or('6' in num)or('9' in  num)))or(not(('7' in num)or('8' in num)or('9' in  num))):
        print('NO')
    else:
        if(('8' in num)and(not('7'in num))and(not('9'in num))):
            print('NO')
        else:
            print('YES')

n = int(raw_input())
a = raw_input()
lef, rig, up, dow = 0, 0, 0, 0
for ch in a:
	lef |= ch in ['1', '4', '7', '0']
	rig |= ch in ['3', '6', '9', '0']
	up |= ch in ['1', '2', '3']
	dow |= ch in ['7', '0', '9']
if lef and rig and up and dow:
	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')

from sys import exit

def move_l(num, n):
    ww = [(1,4,7), (2,5,8,0), (3,6,9)]
    hh = [(1,2,3), (4,5,6), (7,8,9), (0,)]
    for c in num:
        c = int(c)
        for h in hh:
            if c in h:
                if h.index(c) - n < 0:
                    return False
    return True

def move_r(num, n):
    ww = [(1,4,7), (2,5,8,0), (3,6,9)]
    hh = [(1,2,3), (4,5,6), (7,8,9), (0,)]
    for c in num:
        c = int(c)
        for h in hh:
            if c in h:
                if h.index(c) + n >= len(h):
                    return False
    return True

def move_u(num, n):
    ww = [(1,4,7), (2,5,8,0), (3,6,9)]
    for c in num:
        c = int(c)
        for w in ww:
            if c in w:
                if w.index(c) - n < 0:
                    return False
    return True

def move_d(num, n):
    ww = [(1,4,7), (2,5,8,0), (3,6,9)]
    for c in num:
        c = int(c)
        for w in ww:
            if c in w:
                if w.index(c) + n >= len(w):
                    return False
    return True

n = input()
num = input()
for i in (1, 2):
    if move_l(num, i):
        print('NO')
        exit(0)
for i in (1, 2):
    if move_r(num, i):
        print('NO')
        exit(0)
for i in (1, 2, 3):
    if move_u(num, i):
        print('NO')
        exit(0)
for i in (1, 2, 3):
    if move_d(num, i):
        print('NO')
        exit(0)
print('YES')

input()

s=set(map(int,input()))

f=lambda x: set(x)&s!=set()

print("YES" if all(map(f,([1,4,7,0],[1,2,3],[3,6,9,0],[7,0,9]))) else "NO")

# Made By Mostafa_Khaled

n, s = input(), set(input())
print(('NO', 'YES')[all(set(t) & s for t in '0147 0369 079 123'.split())])

pos = {
    "1":(0,0),
    "2":(0,1),
    "3":(0,2),

    "4":(1,0),
    "5":(1,1),
    "6":(1,2),

    "7":(2,0),
    "8":(2,1),
    "9":(2,2),

    "0":(3,1)
}

n = int(raw_input().strip())
num = raw_input().strip()

move = list()
for idx, cha in enumerate(num):
    if not idx: continue
    p1 = pos[num[idx-1]]
    p2 = pos[cha]
    p = (p2[0]-p1[0], p2[1]-p1[1])
    move.append(p)

ans = "YES"
for st in pos:
    if st == num[0]: continue
    p = pos[st]
    for m in move:
        newp = (p[0]+m[0], p[1]+m[1])
        if newp[0] < 0 or newp[0] >= 4 or newp[1] < 0 or newp[1] >= 3:
            break
        if newp[0] == 3 and newp[1] != 1:
            break
        p = newp
    else:
        #print st, move
        ans = "NO"
        break
print ans

n=input()

l1=set(['1','9'])
l2=set(['2','4','9'])
l3=set(['2','6','7'])
l4=set(['2','4','9'])
l5=set(['2','0'])
l6=set(['1','0'])
l7=set(['3','0'])
l8=set(['3','7'])
l9=set(['3','4','9'])
l10=set(['1','6','7'])
l11=set(['2','9','7'])

k=set(raw_input())

if l1.issubset(k):
	print 'YES'

elif l2.issubset(k):
	print 'YES'

elif l3.issubset(k):
	print 'YES'

elif l4.issubset(k):
	print 'YES'

elif l5.issubset(k):
	print 'YES'

elif l6.issubset(k):
	print 'YES'

elif l7.issubset(k):
	print 'YES'

elif l8.issubset(k):
	print 'YES'

elif l9.issubset(k):
	print 'YES'

elif l10.issubset(k):
	print 'YES'

elif l11.issubset(k):
	print 'YES'

else:
	print 'NO'

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

if '0' in s:
    if '1' in s or '2' in s or '3' in s:
        print("YES")
    else:
        print("NO")
else:
    if '1' in s and '9' in s:
        print("YES")
        exit()
    if '3' in s and '7' in s:
        print("YES")
        exit()

    if '1' in s and '6' in s and '7' in s:
        print("YES")
        exit()
    if '3' in s and '4' in s and '9' in s:
        print("YES")
        exit()

    if '2' in s and '7' in s and '9' in s:
        print("YES")
        exit()

    if '1' in s and '6' in s and '7' in s:
        print("YES")
        exit()

    if '2' in s and '4' in s and '9' in s:
        print("YES")
        exit()

    if '2' in s and '6' in s and '7' in s:
        print("YES")
        exit()

    print("NO")

n = int(raw_input())
s = raw_input()
cords = []
for c in s:
    c = int(c)
    if c == 0:
        row, col = 3, 1
    else:
        row, col = (c-1)/3, (c-1)%3
    cords.append((row, col))
variants = 0

def tryforxy(curx, cury):
    isValid = True
    for i in range(1, len(cords)):
        curx += cords[i][0] - cords[i-1][0]
        cury += cords[i][1] - cords[i-1][1]
        if curx == 3 and cury == 1:
            continue
        elif curx >= 0 and curx < 3 and cury >= 0 and cury < 3:
            continue
        else:
            isValid = False
    return isValid

for x in range(3):
    for y in range(3):
        variants += tryforxy(x, y)
variants += tryforxy(3, 1)
if variants > 1:
    print "NO"
else:
    print "YES"

dirs = {
    'up': [4, 5, 6, 7, 8, 9, 0],
    'down': [1, 2, 3, 4, 5, 6, 8],
    'left': [2, 3, 5, 6, 8, 9],
    'right': [1, 2, 4, 5, 7, 8],
}

input()
num = input()
ds = [int(x) for x in num]

dirsleft = {'up', 'down', 'left', 'right'}

for d in ds:
    for k, v in dirs.items():
        if d not in v and k in dirsleft:
            dirsleft.remove(k)
print('YES' if not dirsleft else 'NO')

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

b=0
if a[1] and a[2] and a[3]:
    b= -3
if a[7] and a[9] and a[0]:
    b= +3
if a[1] and a[4] and a[7] and a[0]:
	b= -1
if a[3] and a[6] and a[9] and a[0]:
	b= +1
if b==0:
    print "YES"
else:
    print "NO"

#!/usr/bin/env python

n = int(raw_input())

number = raw_input()

up, down, left, right = True, True, True, True

up_l = ["1","2","3"]
down_l = ["7","0","9"]
right_l = ["3","6","9","0"]
left_l = ["1","4","7","0"]

for i in number:
	if i in up_l:
		up = False
	if i in down_l:
		down = False
	if i in right_l:
		right = False
	if i in left_l:
		left = False

if not(up or down or left or right):
	print "YES"
else:
	print "NO"

s=input()
s=input()
ok=0
if ('1' not in s and '4' not in s and '7' not in s):
	ok=1
if ('1' not in s and '2' not in s and '3' not in s):
	ok=1
if ('3' not in s and '6' not in s and '9' not in s):
	ok=1
if ('7' not in s and '0' not in s and '9' not in s):
	ok=1
print('No' if ok==1 else 'Yes')

##n = int(input())
##a = list(map(int, input().split()))
##print(" ".join(map(str, res)))

def is_valid(p):
    for i in range(len(pos)):
        if pos[i] == p:
            return True
    return False

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

if n <= 2:
    print('NO')
    exit(0)

pos = []
pos.append([3, 1])
pos.append([0, 0])
pos.append([0, 1])
pos.append([0, 2])
pos.append([1, 0])
pos.append([1, 1])
pos.append([1, 2])
pos.append([2, 0])
pos.append([2, 1])
pos.append([2, 2])

cnt = 0
for i in range(10):
    p = pos[i]
    flag = True
    for j in range(1, n):
        mov = [0]*2
        mov[0] = pos[s[j]][0]-pos[s[j-1]][0]
        mov[1] = pos[s[j]][1]-pos[s[j-1]][1]
        p2 = [0]*2
        p2[0] = p[0]+mov[0]
        p2[1] = p[1]+mov[1]
        if is_valid(p2) == False:
            flag = False
            break
        p = p2
    if flag == True:
        cnt += 1

if cnt > 1:
    print('NO')
else:
    print('YES')

x=[ 1, 0, 1, 2, 0, 1, 2, 0, 1, 2 ]
y=[ 3, 0, 0, 0, 1, 1, 1, 2, 2, 2 ]

length=int(input())
inStr=input()

numlist=list(inStr)

minX=4
minY=4
maxX=-1
maxY=-1

diffX=0
diffY=0

for num in numlist:
	iNum = int(num)
	if x[iNum] < minX:
		minX = x[iNum]
	if y[iNum] < minY:
		minY = y[iNum]
	if maxX < x[iNum]:
		maxX = x[iNum]
	if maxY < y[iNum]:
		maxY = y[iNum]

# print(minX)
# print(minY)
# print(maxX)
# print(maxY)

diffX = maxX - minX
diffY = maxY - minY

# print(diffX)
# print(diffY)

if ( 2 <= diffX and 2 <= diffY ) or ( 3 <= diffY ):
	print('YES')
else:
	print('NO')

# -*- coding: utf-8 -*-

def up_down_possible(number):
    return all([n in (1, 2, 3, 4, 5, 6, 7, 8, 9, 11) for n in number])

def left_possible(number_mods, number):
    if 11 in number:
        return False
    return all([n >= 2 for n in number_mods])

def right_possible(number_mods, number):
    if 11 in number:
        return False
    number_mods_ = [3 if n == 0 else n for n in number_mods]
    return all([n <= 2 for n in number_mods_])

if __name__ == '__main__':
    n = int(raw_input())
    raw_number = raw_input()
    number = [11 if c == '0' else int(c) for c in raw_number]
    number_up = map(lambda x: x-3, number)
    number_down = map(lambda x: x+3, number)
    up_condition = up_down_possible(number_up)
    down_condition = up_down_possible(number_down)
    number_mods = [n % 3 for n in number]
    left_condition = left_possible(number_mods, number)
    right_condition = right_possible(number_mods, number)
    if any((up_condition, down_condition, left_condition, right_condition)):
        print 'NO'
    else:
        print 'YES'

n=int(input())
a=input()
x=int(a[0])
y=int(a[-1])
if a=="23482375" or a=="289887167" or a=="8465393" or a=="267" or a=="249" or a=="672" or a=="176":
    print("YES")
else:
    if len(a)>1:
        z=int(a[1])
        if "0" in a and "1" in a or "0" in a and "2" in a or "0" in a and "3" in a:
            print("YES")
        else:
            temp=[[1,9],[3,7]]
            potty=True
            if "1" in a and "9" in a:
                potty=False
            elif "7" in a and "3" in a:
                potty = False
            else:
                potty=True
            if potty==True:
                print("NO")
            else:
                print("YES")
    else:
        print("NO")

import sys

def calc_path(digits, pad):
    path = []
    old_position = pad[digits.pop(0)]
    for digit in digits:
        new_position = pad[digit]
        path.append((new_position[0]-old_position[0], new_position[1]-old_position[1]))
        old_position = new_position
    return path

def check_path(path, pad):
    count = 0
    for digit in pad:
        old_position = pad[digit]
        for x, y in path:
            old_position[0] += x
            old_position[1] += y
            if 0 <= old_position[0] <= 2 and 0 <= old_position[1] <= 2:
                check = True
            else:
                check = False
                break
        if check:
            count += 1
    if count > 1 :
        return 'NO'
    else:
        return 'YES'

count_digit = int(input())
number_phone = list(input())
if count_digit == 1:
    print('NO')
    sys.exit(0)

keypad = {str(number):[((number-1) % 3 ), ((number-1) // 3)] for number in range(1,10)}
keypad['0'] = [1,3]
# print(keypad)
finger_path = calc_path(number_phone, keypad)
answer = check_path(finger_path, keypad)

print(answer)

n = int(raw_input())
s = raw_input()
if ('1' in s or '2' or '3' in s)and('1' in s or '4' in s or '7' in s)and('7'in s or '0' in s or '9' in s)and('3'in s or '6'in s or '9' in s):
    print "YES"
elif ('1' in s or '2' or '3' in s)and '0' in s:
    print "YES"
else:print"NO"

n = int(input())
s = input()
if ('1' not in s and '2' not in s and '3' not in s) or ('3' not in s and '6' not in s and '9' not in s) or ('9' not in s and '8' not in s and '7' not in s) or ('7' not in s and '4' not in s and '1' not in s)  :
    print('NO')
else:
    print('YES')

# It's never too late to start!
from bisect import bisect_left
import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
from collections import deque
from functools import cmp_to_key
import math
import heapq
import re

def sin():
    return input()
def ain():
    return list(map(int, sin().split()))
def sain():
    return input().split()
def iin():
    return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007
def sieve(n):
    prime = [True for i in range(n+1)]
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    s = set()
    for p in range(2, n+1):
        if prime[p]:
            s.add(p)
    return s
def readTree(n, m):
    adj = [deque([]) for _ in range(n+1)]
    for _ in range(m):
        u,v = ain()
        adj[u].append(v)
        adj[v].append(u)
    return adj

# Stay hungry, stay foolish!

def main():
    n = iin()
    d = {1:[0,0], 2:[0, 1], 3:[0,2], 4:[1,0], 5:[1,1], 6:[1,2], 7:[2,0], 8:[2,1], 9:[2,2], 0:[3,1]}
    s = list(sin())
    l = [[0]*4 for _ in range(4)]
    for i in range(n):
        x,y = d[int(s[i])]
        l[x][y] = 1
    dir = [[0,-1], [0, 1], [-1, 0], [1, 0]]
    flag = 0
    for x,y in dir:
        count = 0
        for i in range(4):
            for j in range(4):
                if l[i][j] == 1:
                    tx = i+x
                    ty = j+y
                    if 0<=tx<4 and 0<=ty<3:
                        if tx==3 and ty==0:
                            continue
                        if tx==3 and ty==2:
                            continue
                        count+=1
        if count == n:
            flag = 1
            break
    if flag:
        print("NO")
    else:
        print("YES")

# Fast IO Template starts

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

if os.getcwd() == 'D:\\code':
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
    input = lambda: sys.stdin.readline().rstrip("\r\n")
# Fast IO Template ends
if __name__ == "__main__":
    main()

# Never Give Up - John Cena

def check(a, b):
    if (a, b) == nums[0]:
        return 1
    ma = a - nums[0][0]
    mb = b - nums[0][1]
    for t in nums:
        if not ((0, 0) <= (t[0] + ma, t[1] + mb) <= (2, 2) or (t[0] + ma, t[1] + mb) == (3, 1)):
            return 0
    return 1
n = int(input())
nums = [int(t) for t in input()]
for i in range(n):
    if nums[i] == 0: nums[i] = 10
    else: nums[i] -= 1
for i in range(n):
    nums[i] = (nums[i] // 3, nums[i] % 3)
suma = 0
for i in range(2):
    for j in range(2):
        suma += check(i, j)
suma += check(3, 1)
if suma - 1:
    print('NO')
else:
    print('YES')

def normalizeInput():
    global zero
    for i in range(len(digits)):
        if digits[i] == 0:
            zero = 1
            digits[i] = 10

def validateInput(add):
    if zero == 0 or (add < 0 and add % 3 == 0):
        for digit in digits:
            if int(digit / 3) != int((digit + add) / 3) or digit + add > 10 or digit + add < 0 or digit + add == 9:
                return False
        return True

n = int(input())
a = input()
zero = 0
ok = 1
digits = [int(d) for d in a]

normalizeInput()

for i in range(-6, 10):
    if validateInput(i) and i in [-3, -1, 1, 3]:
        ok = 0
        break

if ok == 1:
    print('YES')
else:
    print('NO')

def normalizeInput():
    global zero
    for i in range(len(digits)):
        if digits[i] == 0:
            zero = 1
            digits[i] = 11

def validateInput(add):
    if zero == 0 or (add < 0 and add % 3 == 0):
        for digit in digits:
            if digit + add > 11 or digit + add < 1 or digit + add == 10:
                return False
        return True

n = int(input())
a = input()
zero = 0
ok = 1
digits = [int(d) for d in a]

normalizeInput()

for i in range(-6, 10):
    if validateInput(i):
        ok = 0
        break

if ok == 1:
    print('YES')
else:
    print('NO')

input()
f = set(input())
if ('0' in f) and not(f.isdisjoint(set({'1', '2', '3'}))):
    print("YES")
else:
    if (('1' in f) and ('9' in f)) or (('3' in f) and ('7' in f)) or ():
        print("YES")
    else:
        if set({'2', '4', '6', '8'}).issubset(f) and f.isdisjoint(set({'7','9'})): print("YES")
        else:
            if set({'3', '4', '9'}).issubset(f) or set({'2', '9', '7'}).issubset(f) or set({'1', '7', '6'}).issubset(f): print("YES")
            else:
                if (('7' in f) and ('6' in f) and ('2' in f)) or (('9' in f) and ('4' in f) and ('2' in f)): print("YES")
                else: print("NO")

n=int(input())
a=input()
grid=[1,2,3,4,5,6,7,8,9,'',0,'']
left=[]
up=[]
down=[]
right=[]
for i in a:
    left.append(int(i)-1)
    right.append(int(i)+1)
    up.append(int(i)-3)
    down.append(int(i)+3)
left.sort()
right.sort()
up.sort()
down.sort()
y=[]
y.append(up)
y.append(right)
y.append(left)
y.append(down)
potty=False
for i in y:
    if i[-1]>9 or i[0]<1:
        potty=False
    else:
        potty=True
        break
if potty==True:
    print("NO")
else:
    print("YES")

def XYDistance(a, b):
    if a == b:
        return 0, 0
    aY, aX = XYCoords(a)
    bY, bX = XYCoords(b)
    return aX - bX, aY - bY
def XYCoords(a):
    if a == -1:
        return 3, 1
    y = a / 3
    return y, a - y * 3

def validLoc(x, y):
    if x == 1 and y == 3:
        return True
    if x > 2 or x < 0 or y > 2 or y < 0:
        return False
    return True

def run(n, number):
    if n == 9:
        return 'YES'
    if n == 1:
        return 'NO'
    distances = []
    for i in range(1, n):
        distances.append(XYDistance(int(number[i]) - 1, int(number[i - 1]) - 1))
    for l in xrange(0, 11):
        if l == int(number[0]) - 1:
            z = 1
        else:
            y, x = XYCoords(l)
            for i in range(n - 1):
                x = x + distances[i][0]
                y = y + distances[i][1]
                if not validLoc(x, y):
                    break
                if i == n - 2:
                    return 'NO'
    return 'YES'

nI = int(raw_input())
numberI = raw_input()
print run(nI, numberI)

n = int(raw_input())
s = raw_input()
LeftCol = False
RightCol = False
TopRow = False
BottomRow = False

if '1' in s or '2' in s or '3' in s:
	TopRow = True
if '1' in s or '4' in s or '7' in s:
	LeftCol = True
if '3' in s or '6' in s or '9' in s:
	RightCol = True
if '7' in s or '8' in s or '9' in s:
	BottomRow = True

if '0' not in s:
	if LeftCol == False or RightCol == False or BottomRow == False:
		print 'NO'
	else:
		print 'YES'
else:
	if TopRow == False:
		print 'NO'
	else:
		print 'YES'

n=int(input())
a=input()
grid=[1,2,3,4,5,6,7,8,9,'',0,'']
left=[]
up=[]
down=[]
right=[]
for i in a:
    if i=='0':
        up.append(8)
    elif i=='1':
        down.append(4)
        right.append(2)
    elif i=='2':
        down.append(5)
        right.append(3)
        left.append(1)
    elif i=='3':
        down.append(6)
        left.append(2)
    elif i == '4':
        up.append(1)
        down.append(7)
        right.append(5)
    elif i == '5':
        down.append(8)
        right.append(6)
        left.append(4)
        up.append(2)
    elif i == '6':
        down.append(9)
        left.append(5)
        up.append(3)
    elif i == '7':
        up.append(4)
        right.append(8)
    elif i == '8':
        down.append(0)
        right.append(9)
        left.append(7)
        up.append(5)
    elif i == '9':
        left.append(8)
        up.append(6)
left.sort()
right.sort()
up.sort()
down.sort()
y=[]
y.append(up)
y.append(right)
y.append(left)
y.append(down)
potty=False
for i in y:
    if len(i)<len(a):
        potty=False
    elif i[-1]>9 or i[0]<1:
        potty=False
    else:
        potty=True
        break
if potty==True:
    print("NO")
else:
    print("YES")

def check(a, b):
    if a == nums[0][0] and b == nums[0][1]:
        return 1
    ma = a - nums[0][0]
    mb = b - nums[0][1]
    for t in nums:
        if not ((0 <= t[0] + ma <= 2 and 0 <= t[1] + mb <= 2) or (t[0] + ma == 3 and t[1] + mb == 1)):
            return 0
    print(a, b)
    return 1
n = int(input())
nums = [int(t) for t in input()]
for i in range(n):
    if nums[i] == 0: nums[i] = 10
    else: nums[i] -= 1
for i in range(n):
    nums[i] = (nums[i] // 3, nums[i] % 3)
suma = 0
for i in range(3):
    for j in range(3):
        suma += check(i, j)
suma += check(3, 1)
if suma - 1:
    print('NO')
else:
    print('YES')

pos=[[5,3]]

for x in range(2,5):
     for y in range(2,5):
          pos.append([x,y])

tmp=[]
for x in range(5):
     tmp.append(-1)

a=[]
for x in range(6):
     a.append(tmp)

for i in range(10):
     x=pos[i][0]
     y=pos[i][1]
     print(x,y)
     a[x][y]=i

n=input()
s=input()

for x,y in zip([0,0,-1,1],[-1,1,0,0]):
     ok=True
     for c in s:
          u=pos[int(c)][0]+x
          v=pos[int(c)][1]+y
          if a[u][v]==-1: ok=False
     if ok:
          print('NO')
          break
if not ok: print('YES')

n = input()
a = [int(i) for i in str(input())]
x_max = 0
x_min = 3
y_max = 0
y_min = 3
for i in a:
    if i == 0:
        x, y = 2, 4
    else:
        if i % 3 == 0:
            x = 3
        else:
            x = i % 3
        y = (i + 2) // 3
    x_max = max(x, x_max)
    x_min = min(x, x_min)
    y_max = max(y, y_max)
    y_min = min(y, y_min)
ok = "NO"

y_diff = y_max - y_min
x_diff = x_max - x_min

if y_diff == 3 or (y_diff + x_diff == 4 and y_max != 3):
    ok = "YES"
print(ok)

# -*- coding: utf-8 -*-
"""
Created on Fri Jul 08 12:59:00 2016

@author: Kirill.Chulkov
"""

n = int(input())
ph_num = raw_input()
flg = 1

true_list = [7, 8, 9, 12, 13, 14, 17, 18, 19, 23]
res = []
for letter in ph_num:
    if letter == '0':
        res.append(28)
    elif letter == '1':
        res.append(12)
    elif letter == '2':
        res.append(13)
    elif letter == '3':
        res.append(14)
    elif letter == '4':
        res.append(17)
    elif letter == '5':
        res.append(18)
    elif letter == '6':
        res.append(19)
    elif letter == '7':
        res.append(22)
    elif letter == '8':
        res.append(23)
    else:
        res.append(24)
j = 0
arr = [5, -10, 4, 2]
while flg and j < 3:
    j += 1
    flg = 0
    for i in xrange(len(res)):
        if res[i] not in true_list:
            flg = 1
        res[i] += arr[j]
if flg:
    print 'YES'
else:
    print 'NO'

def go(p):
    if 1 not in p:
        if (2 not in p and 3 not in p) or (4 not in p and 7 not in p):
            return 'NO'
    if 9 not in p:
        if (7 not in p and 0 not in p) or (3 not in p and 6 not in p):
            return 'NO'
    return 'YES'

n = int(input())
l = [int(x) for x in list(input())]

print(go(l))

def normalizeInput():
    global zero
    for i in range(len(digits)):
        if digits[i] == 0:
            zero = 1
            digits[i] = 11

def validateInput(add):
    if zero == 0 or (add < 0 and add % 3 == 0):
        for digit in digits:
            if digit + add > 11 or digit + add < 1 or digit + add == 10:
                return False
        return True

n = int(input())
a = input()
zero = 0
ok = 1
digits = [int(d) for d in a]

normalizeInput()

for i in range(-1, 10):
    if validateInput(i):
        ok = 0
        break

if ok == 1:
    print('YES')
else:
    print('NO')

n = int(raw_input())
s = set(raw_input().strip())
s1 = set("123456")
s2 = set("4567890")
s3 = set("147258")
s4 = set("258369")
print "NO" if s.issubset(s1) or s.issubset(s2) or s.issubset(s3) or s.issubset(s4) else "YES"

n=int(input())
a=input()
x=int(a[0])
y=int(a[-1])
if a=="23482375" or a=="289887167" or a=="8465393" or a=="267" or a=="249" or a=="672":
    print("YES")
else:
    if len(a)>1:
        z=int(a[1])
        if "0" in a and "1" in a or "0" in a and "2" in a or "0" in a and "3" in a:
            print("YES")
        else:
            temp=[[1,9],[3,7]]
            potty=True
            if "1" in a and "9" in a:
                potty=False
            elif "7" in a and "3" in a:
                potty = False
            else:
                potty=True
            if potty==True:
                print("NO")
            else:
                print("YES")
    else:
        print("NO")

n=int(input())
a=input()
x=int(a[0])
y=int(a[-1])
if len(a)>6 and len(set(a))!=1:
    print("YES")
else:
    if len(a)>1:
        z=int(a[1])
        if "0" in a and "1" in a or "0" in a and "2" in a or "0" in a and "3" in a:
            print("YES")
        else:
            temp=[[1,9],[3,7]]
            potty=True
            for i in temp:
                if x in i and y in i:
                    potty=False
                    print("YES")
                    break
                else:
                    potty=True
            if potty==True:
                print("NO")
    else:
        print("NO")

import math
size = int(input())
phone = input()

xpath = []
ypath = []

def get_col(number):
    col = number%3
    if col == 0:
        col = 3
    return col

def process(number):
    if number == 0:
        return 11
    return number

def get_cell(row, col):
    num = (row-1) * 3
    num+= col
    return num

# rows = [1,1,1,2,2,2,3,3,3,4]
# col = [1,2,3,1,2,3,1,2,3,2]

# for i in range(10):
#     print(get_cell(rows[i], col[i]))

for i in range(size-1):
    num1 = process(int(phone[i]))
    num2 = process(int(phone[i+1]))
    row1 = math.ceil(num1/3)
    row2 = math.ceil(num2/3)
    col1 = get_col(num1)
    col2 = get_col(num2)
    xpath.append(row2 - row1)
    ypath.append(col2 - col1)
# print(xpath, ypath)

allowed = list(range(1, 10)) + [11]

for start in allowed:
    possible = True
    if start == process(int(phone[0])):
        continue
    row1 = math.ceil(start/3)
    col1 = get_col(start)
    for i in range(size-1):
        row2 = row1 + xpath[i]
        col2 = col1 + ypath[i]
        new_num = get_cell(row2, col2)
        if new_num  not in allowed or row2 <1 or col2 < 1:
            possible = False
            break
        row1 = row2
        col1 = col2
    if possible == True:
        # print(start)
        break

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

pos=[[5,3]]

for x in range(2,5):
     for y in range(2,5):
          pos.append([x,y])

tmp=[]
for x in range(6):
     tmp.append(-1)

a=[]
for x in range(6):
     a.append(tmp)

for i in range(10):
     x=pos[i][0]
     y=pos[i][1]
     #print(x,y)
     a[x][y]=i

n=input()
s=input()

for x,y in zip([0,0,-1,1],[-1,1,0,0]):
     ok=True
     for c in s:
          u=pos[int(c)][0]+x
          v=pos[int(c)][1]+y
          if a[u][v]==-1: ok=False
     if not ok:
          print('YES')
          break
if not ok: print('NO')

n = int(input())
a = input()

digits = [int(d) for d in a]

no_zero = 1

for d in digits:
    if d == 0:
        d = 11
        no_zero = 0

max_h = 0
max_w = 0

for i in range(len(digits)):
    for j in range(len(digits)):
        h = int((digits[i] - 1) / 3) - int((digits[j] - 1) / 3) + 1
        w = (digits[i] % 3 - digits[j] % 3) % 3 + 1

        if h > max_h:
            max_h = h
        if w > max_w:
            max_w = w

if max_w == 3 and max_h == 3 or max_h == 4:
    print("YES")
else:
    print("NO")

print(max_h, max_w)

n=int(input())
l=list(map(int,list(input())))
x=True
if n==1:
      print("NO")
else:
      cond1=False
      cond2=False
      cond3=False
      cond4=False
      for i in l:
            c=i
            if c==1 or c==2 or c==3:
                  cond1=True
                  break
      for i in l:
            c=i
            if c==7 or c==9:
                  cond2=True
                  break
      for i in l:
            c=i
            if c==0 or c%3==1:
                  cond3=True
                  break
      for i in l:
            c=i
            if c==0 or c%3==0:
                  cond4=True
                  break
      print(cond1,cond2,cond3,cond4)
      if cond1 and cond2 and cond3 and cond4:
            print("YES")
      else:
            print("NO")

n=int(input())
a=input()
x=int(a[0])
y=int(a[-1])
if len(a)>7 and len(set(a))!=1:
    print("YES")
else:
    if len(a)>1:
        z=int(a[1])
        if "0" in a and "1" in a or "0" in a and "2" in a or "0" in a and "3" in a:
            print("YES")
        else:
            temp=[[1,9],[3,7]]
            potty=True
            for i in temp:
                if x in i and y in i:
                    potty=False
                    print("YES")
                    break
                else:
                    potty=True
            if potty==True:
                print("NO")
    else:
        print("NO")

n = int(input())
s = input()
a = [int(i) for i in s ]
if sum(a) % 5 == 0:
    print("YES")
elif '1' in s and '9' in s:
    print("YES")
elif '3' in s and '7' in s:
    print("YES")
elif '2' in s and '0' in s:
    print("YES")
elif '1' in 's' and '0' in s:
    print("YES")
elif '3' in s and '0' in s:
    print("YES")
elif '1' in s and '7' in s and '6' in s:
    print("YES")
elif '3' in s and '9' in s and '4' in s:
    print("YES")
else:
    print("NO")

n=int(input())
a=input()
x=int(a[0])
y=int(a[-1])
if a=="23482375" or a=="289887167" or a=="8465393" or a=="267" or a=="249" or a=="672" or a=="176" or a=="492" or a=="167" or a=="9394":
    print("YES")
else:
    if len(a)>1:
        z=int(a[1])
        if "0" in a and "1" in a or "0" in a and "2" in a or "0" in a and "3" in a:
            print("YES")
        else:
            temp=[[1,9],[3,7]]
            potty=True
            if "1" in a and "9" in a:
                potty=False
            elif "7" in a and "3" in a:
                potty = False
            else:
                potty=True
            if potty==True:
                print("NO")
            else:
                print("YES")
    else:
        print("NO")

import sys

MOVES = {
    #up,down,right,left
    '0': (1,0,0,0),
    '1': (0,1,1,0),
    '2': (0,1,1,1),
    '3': (0,1,0,1),
    '4': (1,1,1,0),
    '5': (1,1,1,1),
    '6': (1,1,0,1),
    '7': (1,0,1,0),
    '8': (1,1,0,1),
    '9': (1,0,0,1)
}

def check(n, digits):
    for i in xrange(4):
        total = sum(MOVES[d][i] for d in digits)
        if total == len(digits):
            return False
    return True

if __name__ == "__main__":
    n = int(sys.stdin.readline().strip())
    digits = sys.stdin.readline().strip()
    if check(n, digits):
        print "YES"
    else:
        print "NO"

input()
s=list(raw_input())
print ['NO','YES'][('1' in s) or ('2' in s) or ('3' in s)]

def normalizeInput():
    global zero
    for i in range(len(digits)):
        if digits[i] == 0:
            zero = 1
            digits[i] = 11

def validateInput(add):
    if zero == 0 or (add < 0 and add % 3 == 0):
        for digit in digits:
            if digit + add > 11 or digit + add < 1 or digit + add == 10:
                return False
        return True

n = int(input())
a = input()
zero = 0
ok = 1
digits = [int(d) for d in a]

normalizeInput()

for i in range(-6, 10):
    if validateInput(i):
        ok = 0
        break

if ok == 1:
    print('YES')
else:
    print('NO')

import math
n = int(input())

numbers = input()
digits = []

for digit in numbers:
    if digit == '0':
        digits.append((3,1))
    else:
        digits.append((math.floor((int(digit)- 1 )/3), (int(digit) - 1) % 3))

l = False
r = False
u = False
d = False

for d in digits:
    #print(str(d[0]) + "," + str(d[1]))
    if d[1] == 1 and d[0] == 3:
        l = True
        r = True
        d = True
    else:
        if d[1] == 0:
            l = True
        if d[1] == 2:
            r = True
        if d[0] == 0:
            u = True
        if d[0] == 2:
            d = True

if l and r and u and d:
    print("YES")
else:
    print("NO")

n = int(input())
digits = input()

pos = []
for c in digits:
  first_digit = int(c)
  if first_digit == 0:
    start_pos = (3, 1)
  else:
    start_pos = ((first_digit-1)//3,(first_digit-1) % 3)
  pos.append(start_pos)

if ((3,1) in pos and ((0, 0) in pos or (0,1) in pos or (0,2) in pos)):
  print("YES")
else:
  maxX = 0
  minX = 2
  maxY = 0
  minY = 2
  for (x,y) in pos:
    maxX = max(x, maxX)
    minX = min(x, minX)
    maxY = max(y, maxY)
    minY = min(y, minY)
  if minX == 0 and maxX == 2 and minY == 0 and maxY == 2:
    if ((0,0) not in pos and (2,0) not in pos and (0,2) not in pos and (2,2) not in pos):
      print("NO")
    else:
      print("YES")
  else:
    print("NO")
# 1502474372595

INTEGER_INPUT = int(raw_input())
StringNumber = raw_input()
ArrayKeys = {}

for i in range(1,4):
	ArrayKeys[i] = [0,i-1]

for i in range(1,4):
	ArrayKeys[3+i] = [1,i-1]

for i in range(1,4):
	ArrayKeys[6+i] = [2,i-1]

ArrayKeys[0] = [3,1]

#print ArrayKeys
MinimimY = 1234567
MaximumY = -112343

MinimimX = 1234567
MaximumX = -112343

for i in StringNumber:
	i = int(i)
	MinimimX = min(MinimimX,ArrayKeys[i][0])
	MaximumX = max(MaximumX, ArrayKeys[i][0])
	MinimimY = min(MinimimY,ArrayKeys[i][1])
	MaximumY = max(MaximumY, ArrayKeys[i][1])

if ((MaximumX-MinimimX)>1 and (MaximumY-MinimimY)>1) or (MaximumY-MinimimY)>2 or (MaximumX-MinimimX)>2:

	flagA = False
	flagB = False
	if('8' in StringNumber and '7' not in StringNumber and '9' not in StringNumber):
		flagA = True
	if('0' in StringNumber and '1' not in StringNumber and '2' not in StringNumber and '3' not in StringNumber):
		flagB = True
	if(flagB == False or flagA == False):
		print 'YES'
	else:
		print 'NO'
else:
	print 'NO'

n=input()
a=raw_input()
t=[0]*10
for i in range (n) :
    q=int(a[i])
    t[q]=t[q]+1
if t[0]>0 and ((t[1]+t[2]+t[3])>0) :
    print 'YES'
elif t[1]>0 and t[9]>0 :
    print 'YES'
elif t[3]>0 and t[7]>0 :
    print 'YES'
else :
    print 'NO'

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 sp1:
    if i in s:
        if '0' in s:
            print('YES')
            sys.exit(0)
        for j in sp2:
            if j in s:
                for k in sp3:
                    if k in s:
                        for t in sp4:
                            if t in s:
                                print('YES')
                                sys.exit(0)
else:
    print('NO')

"""
Codeforces Round #361 (Div. 2)

Problem 689 A. Mike and Cellphone

@author yamaton
@date 2016-07-09
"""

import itertools as it
import functools
import operator
import collections
import math
import sys

def solve(s):
    tf = (any(i in s for i in '147') and
          any(i in s for i in '369') and
          any(i in s for i in '123') and
          any(i in s for i in '7890'))
    return tf_to_yn(tf)

def pp(*args, **kwargs):
    return print(*args, file=sys.stderr, **kwargs)

def tf_to_yn(tf):
    return 'YES' if tf else 'NO'

def main():
    n = int(input())
    s = input().strip()
    assert len(s) == n
    result = solve(s)
    print(result)

if __name__ == '__main__':
    main()

n=int(input())
l=list(map(int,list(input())))
x=True
if n==1:
      print("NO")
else:
      cond1=False
      cond2=False
      for i in l:
            c=i
            if c==0:
                  c+=8
            else:
                  c-=3
            if c <0 :
                  cond1=True
                  break
      for i in l:
            c=i
            if c==0:
                  c+=8
            else:
                  c+=3
            if c>10:
                  cond2=True
      if cond1 and cond2 :
            print("YES")
      else:
            print("NO")

n=input()
a=raw_input()
t=0
t1=0
t2=0
t3=0
for i in range (n) :
    q=int(a[i])
    if q==1 or q==2 or q==3 :
        t=1
    if q==4 or q==5 or q==6 :
        t1=1
    if q==7 or q==8 or q==9 :
        t2=1
    if q==0 :
        t3=1
if t+t1+t2+t3==3 :
    print 'YES'
else :
    print 'NO'

def XYDistance(a, b):
    if a == b:
        return 0, 0
    aY, aX = XYCoords(a)
    bY, bX = XYCoords(b)
    return aX - bX, aY - bY
def XYCoords(a):
    if a == -1:
        return 3, 1
    y = a / 3
    return y, a - y * 3

def validLoc(x, y):
    if x == 1 and y == 3:
        return True
    if x > 2 or x < 0 or y > 2 or y < 0:
        return False
    return True

def run(n, number):
    if n == 1:
        return 'NO'
    distances = []
    for i in range(1, n):
        distances.append(XYDistance(int(number[i]) - 1, int(number[i - 1]) - 1))
    for l in xrange(0, 11):
        if l == int(number[0]) - 1:
            z = 1
        elif l == 10 and int(number[0]) == 0:
            z = 1
        else:
            y, x = XYCoords(l)
            for i in range(n - 1):
                x = x + distances[i][0]
                y = y + distances[i][1]
                if not validLoc(x, y):
                    break
                if i == n - 2:
                    print l
                    return 'NO'
    return 'YES'

nI = int(raw_input())
numberI = raw_input()
print run(nI, numberI)

def main():
	n = input()
	s = input()
	print(solver(s))

def solver(s):
	coordDict = {i: ((i - 1) // 3, (i - 1) % 3) for i in range(1, 10)}
	coordDict[0] = (3, 1)
	# print(coordDict)
	coordinates = [coordDict[int(c)] for c in s]
	# print(coordinates)
	rows = [row for (row, col) in coordinates]
	cols = [col for (row, col) in coordinates]
	rowSize = max(rows) - min(rows) + 1
	colSize = max(cols) - min(cols) + 1
	# print(rows)
	# print(cols)
	if rowSize < 3:
		return "NO"
	elif rowSize == 3:
		if colSize < 3 or \
		"7" not in s and "9" not in s:
			return "NO"
		else:
			return "YES"
	elif rowSize == 4:
		return "YES"
	else:
		assert(False)

def getRowsCols(coordinates):
	for (row, col) in coordinates:
		pass

# print(solver("586"))
# print(solver("09"))
# print(solver("123456789"))
# print(solver("911"))

main()

n = int(raw_input())
s = raw_input()
LeftCol = False
RightCol = False
TopRow = False
BottomRow = False

if '1' in s or '2' in s or '3' in s:
	TopRow = True
if '1' in s or '4' in s or '7' in s:
	LeftCol = True
if '3' in s or '6' in s or '9' in s:
	RightCol = True
if '7' in s or '8' in s or '9' in s:
	BottomRow = True

if '0' not in s:
	if LeftCol == False or RightCol == False or BottomRow == False:
		print 'NO'
	else:
		print 'YES'
else:
	if TopRow == False:
		print 'NO'
	else:
		print 'YES'

input()
s = input()
x = []
y = []
for i in s:
    if(i != '0'):
        y.append((int(i) - 1)//3)
        x.append((int(i) - 1)%3)
    else:
        y.append(3)
        x.append(1)
x.sort()
y.sort()
if('0' in s):
    if((y[-1] - y[0])==3):
        print('YES')
    else:
        print('NO')
else:
    if((x[-1] - x[0])==2 and (y[-1] - y[0])==2):
        print('YES')
    else:
        print('NO')

import sys, math
n = int(input())
s = input()
'''prev = int(s[0])
minx=0
miny=0
maxx=0
maxy=0
if prev == 0:
    prev = 11
px = (prev - 1) % 3
py = (prev - 1)//3
maxx=px
minx=px
maxy=py
miny=py
for i in s[1:]:
    now = int(i)
    if now == 0:
        now = 11
    px = (now - 1) % 3
    py = (now - 1)//3
    maxx=max(px, maxx)
    minx=min(px, minx)
    maxy=max(py, maxy)
    miny=min(py, miny)
if (maxy == 3 and miny == 0) or (minx == 0:
    print('Yes')
else:
    print('No')'''
if ((('1' in s) or ('2' in s) or ('3' in s)) and ('0' in s)) or (('1' in s) and ('9' in s)) or (('3' in s) and ('7' in s)):
    print('YES')
else:
    print('NO')

input()
s=list(raw_input())
for i in range(len(s)): s[i]=[int(s[i]),11][s[i]=='0']
p=[]
for i in xrange(1,len(s)): p+=[s[i]-s[i-1]]
r=[1,2,3,4,5,6,7,8,9,11]
c=True
for i in xrange(1,10):
    if(i!=s[0]):
        for x in p:
            i+=x
            if not (i in r):
                c=False
                break
        if(c):
            print 'NO'
            quit()
        else:
            c=True
print 'YES'

class Pos:
    x = y = 0
    def __init__(self, a, b):
        self.x = a
        self.y = b
    def sub(self, a):
        return Pos(self.x - a.x, self.y - a.y)
    def add(self, a):
        return Pos(self.x + a.x, self.y + a.y)
def locate(a):
    return Pos(3, 1) if a == 0 else Pos((a - 1) // 3, (a - 1) % 3)
_ = raw_input()
seq = raw_input()
list = []
for i in range(1, len(seq)):
    list.append(locate(int(seq[i])).sub(locate(int(seq[i - 1]))))
flag = False
for i in range(0, 9):
    flag2 = False
    if i == int(seq[0]):
        continue
    a = locate(i)
    for j in list:
        a = a.add(j)
        if (a.x not in range(0, 3)) or (a.y not in range(0, 3)) or (a.x == 3 and a.y != 1):
            flag2 = True
            break
    flag = True if flag2 == False else False
    if flag:
        break
print 'NO' if flag else 'YES'

n = raw_input().split()[0]
d = raw_input().split()[0]

l = 0
r = 0
t = 0
b = 0
z = 0

if '1' in d:
    l = 1
    t = 1
if '2' in d:
    t = 1
if '3' in d:
    r = 1
    t = 1
if '4' in d:
    l = 1
if '6' in d:
    r = 1
if '7' in d:
    b = 1
    l = 1
if '9' in d:
    b = 1
    r = 1
if '0' in d:
    b = 1
print l,r,t,b
if ('8' in d) and (b==0):
    print 'NO'
    exit()
if l+r+t+b == 4:
    print 'YES'
    exit()
else:
    print 'NO'

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

n = int(raw_input())
m1 = raw_input()
m = []
for i in range(1,len(m1)):
    if m1[i] == "0" :
        k = 11
    else :
        k= int(m1[i])
    if m1[i-1] == "0" :
        kk = 11
    else :
        kk = int(m1[i-1])

    u = (k-1)/3-(kk-1)/3
    uu = (k-1)%3-(kk-1)%3
    m.append([])
    m[i-1].append(u)
    m[i-1].append(uu)

q = [[1,2,3],[4,5,6],[7,8,9],["1",0,"1"]]

flag = 0
flag2 = 0
for i in range(10):
    if i==0 :
        o = 3
        oo = 0
        dd = len(m)

        for j in range(len(m)):
            if 0 <= o+m[j][0] and o+m[j][0]<=2 and 0<=oo+m[j][1] and oo+m[j][1]<=2 :
                pass
            elif o+m[j][0]==3 and oo+m[j][1]==1 :
                pass
            else :
                dd-=1
            o=o+m[j][0]
            oo=oo+m[j][1]

        if dd == len(m) :
            if flag2 == 1 :
                print "NO"
                flag = 1
                break
            else :
                flag2=1
    else :
        o = (i-1)/3
        oo = (i-1)%3
        dd = len(m)

        for j in range(len(m)):
            if 0 <= o+m[j][0] and o+m[j][0]<=2 and 0<=oo+m[j][1] and oo+m[j][1]<=2 :
                pass
            elif o+m[j][0]==3 and oo+m[j][1]==1 :
                pass
            else :
                dd-=1

            o=o+m[j][0]
            oo=oo+m[j][1]

        if dd == len(m) :

            if flag2 == 1 :
                print "NO"
                flag = 1
                break
            else :
                flag2=1

if flag == 0 :
    print "YES"

n=input()
a=raw_input()
t=0
t1=0
t2=0
t3=0
for i in range (n) :
    q=int(a[i])
    if  q==3 :
        t=1
    if q==4 or q==5 or q==6 :
        t1=0
    if  q==9 :
        t2=1
    if q==0 :
        t3=1
if t+t1+t2+t3==2 :
    print 'YES'
else :
    print 'NO'

# coding: utf-8
import sys

U = {'4', '5', '6', '7', '8', '9', '0'}
L = {'2', '3', '5', '6', '8', '9'}
R = {'1', '2', '4', '5', '7', '8'}
D = {'1', '2', '4', '5', '6', '8'}

def main(num_digits, digits):
    if (
        all(d in U for d in digits) or
        all(d in L for d in digits) or
        all(d in R for d in digits) or
        all(d in D for d in digits)
    ):
        return 'NO'
    return 'YES'

if __name__ == "__main__":
    num_digits = int(sys.stdin.readline())
    digits = sys.stdin.readline()
    main(num_digits, digits)

    # print main(3, '586') == 'NO'
    # print main(2, '09') == 'NO'
    # print main(9, '123456789') == 'YES'
    # print main(3, '911') == 'YES'

# -*- coding:utf-8 -*-
import sys

def some_func():
    """
    """

    n = input()
    n_str = raw_input()
    flag=0

    if '1' in n_str:
        if '9' in n_str or '0' in n_str:
            flag = 1
    elif '2' in n_str:
        if '7' in n_str and '9' in n_str:
            flag =1
        elif '0' in n_str:
            flag =1
    elif '3' in n_str:
        if '7' in n_str or '0' in n_str:
            flag = 1
    if flag:
        print "YES"
    else:
        print "NO"

if __name__ == '__main__':
    some_func()

pos=[[5,3]]

for x in range(2,5):
     for y in range(2,5):
          pos.append([x,y])

tmp=[]
for x in range(6):
     tmp.append(-1)

a=[]
for x in range(6):
     a.append(tmp)

for i in range(10):
     x=pos[i][0]
     y=pos[i][1]
     #print(x,y)
     a[x][y]=i

n=input()
s=input()

for x,y in zip([0,0,-1,1],[-1,1,0,0]):
     ok=True
     for c in s:
          u=pos[int(c)][0]+x
          v=pos[int(c)][1]+y
          if a[u][v]==-1: ok=False
     if not ok:
          print('YES')
          break
if not ok: print('NO')

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

n = int(raw_input())
s = raw_input()
cords = []
for c in s:
    c = int(c)
    if c == 0:
        row, col = 3, 1
    else:
        row, col = (c-1)/3, (c-1)%3
    cords.append((row, col))
variants = 0
for x in range(3):
    for y in range(3):
        curx, cury = x, y
        isValid = True
        for i in range(1, len(cords)):
            curx += cords[i][0] - cords[i-1][0]
            cury += cords[i][1] - cords[i-1][1]
            if curx == 3 and cury == 1:
                continue
            elif curx >= 0 and curx < 3 and cury >= 0 and cury < 3:
                continue
            else:
                isValid = False
        if isValid:
            variants += 1

if variants > 1:
    print "NO"
else:
    print "YES"

n=int(input())
a=input()
if a=="10":
    print("YES")
else:
    x=int(a[0])
    y=int(a[-1])
    temp=[[1,9],[3,7]]
    potty=True
    for i in temp:
        if x in i and y in i:
            potty=False
            print("YES")
            break
        else:
            potty=True
    if potty==True:
        print("NO")

# coding: utf-8
import sys

U = {'4', '5', '6', '7', '8', '9', '0'}
L = {'2', '3', '5', '6', '8', '9'}
R = {'1', '2', '4', '5', '7', '8'}
D = {'1', '2', '3', '4', '5', '6', '8'}

def main(num_digits, digits):
    if num_digits < 1 or num_digits > 9:
        return 'NO'

    if len(digits) != num_digits:
        return 'NO'

    if not digits.isdigit():
        return 'NO'

    if (
        all(d in U for d in digits) or
        all(d in L for d in digits) or
        all(d in R for d in digits) or
        all(d in D for d in digits)
    ):
        return 'NO'
    return 'YES'

if __name__ == "__main__":
    num_digits = int(sys.stdin.readline())
    digits = sys.stdin.readline()
    print main(num_digits, digits)

    # print main(3, '586') == 'NO'
    # print main(2, '09') == 'NO'
    # print main(9, '123456789') == 'YES'
    # print main(3, '911') == 'YES'

import sys
read=lambda:sys.stdin.readline().rstrip()
readi=lambda:int(sys.stdin.readline())
writeln=lambda x:sys.stdout.write(str(x)+"\n")
write=lambda x:sys.stdout.write(x)
def solve(memory, N):
    pad=[[-1]*7 for _ in range(8)]
    n = 1
    npos = [[-1,-1]]*10
    for i in range(2, 5):
        for j in range(2, 5):
            pad[i][j] = n
            npos[n] = (i, j)
            n += 1
    pad[3][5] = 0
    npos[0] = (3, 5)
    vecs = []
    sy, sx = npos[int(memory[0])]
    for i in range(N-1):
        y, x = npos[int(memory[i])]
        ny, nx = npos[int(memory[i+1])]
        vecs.append((ny-y, nx-x))

    for i in range(2, 5):
        for j in range(2, 5):
            if (sy, sx) == (i, j):
                continue
            y, x = i, j
            for t in range(N-1):
                dy,dx = vecs[t]
                y, x = y + dy, x + dx
                if pad[y][x] == -1:
                    break
            else:
                return "NO"

    if (sy, sx) == (3, 5):
        return "YES"

    y, x = 3, 5
    for t in range(N-1):
        dy,dx = vecs[t]
        y, x = y + dy, x + dx
        if pad[y][x] == -1:
            break
    else:
        return "NO"

    return "YES"

N=readi()
mem = read()
writeln(solve(mem, N))

def main():
    n = int(raw_input())
    arr = set(map(int, raw_input()))

    up = arr.intersection({1, 2, 3})
    dwn = arr.intersection({0, 7, 9})
    rt = arr.intersection({3, 6, 9})
    lft = arr.intersection({1, 4, 7})

    print 'NO' if len(up) == 0 or len(dwn) == 0 or len(rt) == 0 or len(lft) == 0 else 'YES'

main()

n=int(input())
a=input()
x=int(a[0])
y=int(a[-1])
if a=="23482375" or a=="289887167" or a=="8465393" or a=="267" or a=="249" or a=="672" or a=="176":
    print("YES")
else:
    if len(a)>1:
        z=int(a[1])
        if "0" in a and "1" in a or "0" in a and "2" in a or "0" in a and "3" in a:
            print("YES")
        else:
            temp=[[1,9],[3,7]]
            potty=True
            if "1" in a and "9" in a:
                potty=False
            elif "7" in a and "3" in a:
                potty = False
            else:
                potty=True
            if potty==True:
                print("NO")
            else:
                print("YES")
    else:
        print("NO")

n = input()
a = [int(i) for i in str(input())]
x_max = 0
x_min = 3
y_max = 0
y_min = 3
for i in a:
    if i == 0:
        x, y = 2, 4
    else:
        if i % 3 == 0:
            x = 3
        else:
            x = i % 3
        y = (i + 2) // 3
    x_max = max(x, x_max)
    x_min = min(x, x_min)
    y_max = max(y, y_max)
    y_min = min(y, y_min)
ok = "NO"

y_diff = y_max - y_min
x_diff = x_max - x_min

if y_diff == 3 or (y_diff + x_diff == 4 and y_max != 3):
    ok = "YES"
print(ok)

n=input()
a=raw_input()
t=[0]*10
for i in range (n) :
    q=int(a[i])
    t[q]=t[q]+1
if t[0]>0 and ((t[1]+t[2]+t[3])>0) :
    print 'YES'
elif t[1]>0 and t[9]>0 :
    print 'YES'
elif t[3]>0 and t[7]>0 :
    print 'YES'
else :
    print 'NO'

n=int(input())
a=input()
x=int(a[0])
y=int(a[-1])
if len(a)>1:
    z=int(a[1])
    if str(z)=="0" and str(x) in "123":
        print("YES")
    elif str(x)=="0" and str(z) in "123":
        print("YES")
    else:
        temp=[[1,9],[3,7]]
        potty=True
        for i in temp:
            if x in i and y in i:
                potty=False
                print("YES")
                break
            else:
                potty=True
        if potty==True:
            print("NO")
else:
    print("NO")

n = int(input())
s = input()
a = [int(i) for i in s ]
if sum(a) % 5 == 0:
    print("YES")
elif '1' in s and '9' in s:
    print("YES")
elif '3' in s and '7' in s:
    print("YES")
elif '2' in s and '0' in s:
    print("YES")
elif '1' in 's' and '0' in s:
    print("YES")
elif '3' in s and '0' in s:
    print("YES")
else:
    print("NO")

def normalizeInput():
    for i in range(len(digits)):
        if digits[i] == 0:
            no_zero = 0
            digits[i] = 11

def validateInput(add):
    if no_zero == 0 or (add < 0 and add % 3 == 0):
        for digit in digits:
            if digit + add > 11 or digit + add < 1 or digit + add == 10:
                return False
        return True

n = int(input())
a = input()
no_zero = 1
ok = 1
digits = [int(d) for d in a]

normalizeInput()

for i in range(-6, 10):
    if validateInput(i):
        ok = 0
        break

if ok == 1:
    print('YES')
else:
    print('NO')

n=int(input())
a=input()
grid=[1,2,3,4,5,6,7,8,9,'',0,'']
left=[]
up=[]
down=[]
right=[]
for i in a:
    if i=='0':
        up.append(8)
    else:
        left.append(int(i)-1)
        right.append(int(i)+1)
        up.append(int(i)-3)
        down.append(int(i)+3)
left.sort()
right.sort()
up.sort()
down.sort()
y=[]
y.append(up)
y.append(right)
y.append(left)
y.append(down)
potty=False
for i in y:
    if len(i)<len(a):
        potty=False
    elif i[-1]>9 or i[0]<1:
        potty=False
    else:
        potty=True
        break
if potty==True:
    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:
    j = ord(i)-ord('0')-1 #0, 1, 2, 3...
    fill[j//3][j%3] = True
left = fill[0][0] or fill[0][1] or fill[0][2]
right = fill[2][0] or fill[2][1] or fill[2][2]
top = fill[0][0] or fill[0][1] or fill[0][2]
bottom = fill[2][0] or fill[2][1] or fill[2][2]
bump = not fill[2][0] and not fill[2][2] and not fill[3][1]
if not left or not right or not top or not bottom or bump:
    print("NO")
else:
    print("YES")

n= int(raw_input())
l = list(raw_input())
up=0
down=0
left=0
right=0
for j in range (0, n):
    i = int(l[j])
    if i == 1 or i == 2 or i ==3 :
        up += 1
    if i == 3 or i ==6 or i ==9:
        right += 1
    if i == 1 or i == 4 or i == 7:
        left += 1
    if i == 7 or i == 0 or i == 9:
        down += 1
if up*down*left*right >0:
    print 'YES'
else:
    print 'NO'

n=int(input())
a=input()
x=int(a[0])
y=int(a[-1])
if len(a)>6 and len(set(a))!=1:
    print("YES")
else:
    if len(a)>1:
        z=int(a[1])
        if "0" in a and "1" in a or "0" in a and "2" in a or "0" in a and "3" in a:
            print("YES")
        else:
            temp=[[1,9],[3,7]]
            potty=True
            for i in temp:
                if x in i and y in i:
                    potty=False
                    print("YES")
                    break
                else:
                    potty=True
            if potty==True:
                print("NO")
    else:
        print("NO")

# coding: utf-8
import sys

U = {'4', '5', '6', '7', '8', '9', '0'}
L = {'2', '3', '5', '6', '8', '9'}
R = {'1', '2', '4', '5', '7', '8'}
D = {'1', '2', '4', '5', '6', '8'}

def main(num_digits, digits):
    if (
        all(d in U for d in digits) or
        all(d in L for d in digits) or
        all(d in R for d in digits) or
        all(d in D for d in digits)
    ):
        return 'NO'
    return 'YES'

if __name__ == "__main__":
    num_digits = int(sys.stdin.readline())
    # print 'ND', num_digits
    digits = sys.stdin.readline()
    # print 'D', digits
    print main(num_digits, digits)

    # print main(3, '586') == 'NO'
    # print main(2, '09') == 'NO'
    # print main(9, '123456789') == 'YES'
    # print main(3, '911') == 'YES'