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

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

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


-----Input-----

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

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


-----Output-----

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

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


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

Output
NO

Input
2
09

Output
NO

Input
9
123456789

Output
YES

Input
3
911

Output
YES



-----Note-----

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

Difficulty: MEDIUM
Tags: Complete search

Implementation

Constructive algorithms
Skill types: Complete search

Starter code:

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


def getpos(digit):
	digit = int(digit)
	if digit == 0:
		return (3, 1)
	digit -= 1
	return (digit // 3, digit % 3)

def main():
	ndig = int(input())
	number = input().strip()
	assert ndig == len(number)
	rlo = clo = 4
	rhi = chi = 0
	for digit in number:
		(row, col) = getpos(digit)
		rlo = min(row, rlo)
		rhi = max(row, rhi)
		clo = min(col, clo)
		chi = max(col, chi)
	rdiff = rhi - rlo
	if rdiff == 3:
		print('YES')
	elif rdiff < 2:
		print('NO')
	elif chi - clo < 2:
		print('NO')
	elif '0' in number:
		print('NO')
	elif '7' in number or '9' in number:
		print('YES')
	else:
		print('NO')
main()


input()
s = set(list(input()))
t = 1
for i in [{'1', '9'}, {'7', '3'}, {'0', '2'}, {'0', '1'}, {'0', '3'}, {'9', '3', '4'}, {'1', '7', '6'}, {'9', '4', '2'}, {'7', '2', '6'}, {'7', '2', '9'}]:
	if s & i == i:
		t = 0
print('YNEOS'[t::2])


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


n = int(input())
p = [int(x) for x in list(input())]
if (1 in p or 2 in p or 3 in p) and 0 in p:
	print('YES')
elif 1 not in p and 2 not in p and (3 not in p):
	print('NO')
elif 1 not in p and 4 not in p and (7 not in p):
	print('NO')
elif 3 not in p and 6 not in p and (9 not in p):
	print('NO')
elif 7 not in p and 0 not in p and (9 not in p):
	print('NO')
else:
	print('YES')


import sys

def canMoveLeft(digit):
	index = [False, False, True, True, False, True, True, False, True, True]
	return index[digit]

def canMoveRight(digit):
	index = [False, True, True, False, True, True, False, True, True, False]
	return index[digit]

def canMoveUp(digit):
	index = [True, False, False, False, True, True, True, True, True, True]
	return index[digit]

def canMoveDown(digit):
	index = [False, True, True, True, True, True, True, False, True, False]
	return index[digit]
n = int(input())
number = [int(i) for i in input()]
movedown = [all([canMoveDown(i) for i in number]), all([canMoveUp(i) for i in number]), all([canMoveLeft(i) for i in number]), all([canMoveRight(i) for i in number])]
if any(movedown):
	print('NO')
else:
	print('YES')


left = 0
right = 1
up = 2
down = 3
buttons = []
buttons.append({left: False, right: False, up: True, down: False})
buttons.append({left: False, right: True, up: False, down: True})
buttons.append({left: True, right: True, up: False, down: True})
buttons.append({left: True, right: False, up: False, down: True})
buttons.append({left: False, right: True, up: True, down: True})
buttons.append({left: True, right: True, up: True, down: True})
buttons.append({left: True, right: False, up: True, down: True})
buttons.append({left: False, right: True, up: True, down: False})
buttons.append({left: True, right: True, up: True, down: True})
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')


def in_range(x):
	a0 = x[0] >= 0 and x[0] <= 2
	a1 = x[1] >= 0 and x[1] <= 2
	b = x == [1, 3]
	return a0 and a1 or b

def add(a, b):
	c = [0, 0]
	c[0] = a[0] + b[0]
	c[1] = a[1] + b[1]
	return c
n = int(input())
num = input()
loc = [[1, 3], [0, 0], [1, 0], [2, 0], [0, 1], [1, 1], [2, 1], [0, 2], [1, 2], [2, 2]]
flag = False
up = [0, -1]
down = [0, 1]
left = [-1, 0]
right = [1, 0]
counts = [0] * 4
for x in num:
	if in_range(add(loc[int(x)], up)):
		counts[0] += 1
for x in num:
	if in_range(add(loc[int(x)], down)):
		counts[1] += 1
for x in num:
	if in_range(add(loc[int(x)], left)):
		counts[2] += 1
for x in num:
	if in_range(add(loc[int(x)], right)):
		counts[3] += 1
flag = counts[0] == n or counts[1] == n or counts[2] == n or (counts[3] == n)
if flag:
	print('NO')
else:
	print('YES')


input()

def p(x):
	x = int(x) - 1
	if x == -1:
		return (3, 1)
	return (x // 3, x % 3)
s = list(map(p, input()))
f = False
for (di, dj) in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
	f = f or not [1 for (i, j) in s if i + di < 0 or i + di >= 4 or j + dj < 0 or (j + dj >= 3) or (i + di == 3 and j + dj != 1)]
print('NO' if f else 'YES')


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

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())
	ln = len(set(s))
	l = [[0] * 3 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(3):
				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 == ln:
			flag = 1
			break
	if flag:
		print('NO')
	else:
		print('YES')
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')
main()


n = int(input())
g = input()
res = [0] * 4
for i in g:
	if i in ['1', '2', '3']:
		res[0] = 1
	if i in ['3', '6', '9']:
		res[1] = 1
	if i in ['7', '0', '9']:
		res[2] = 1
	if i in ['1', '4', '7']:
		res[3] = 1
if sum(res) == 4 or (res[0] and '0' in g):
	print('YES')
else:
	print('NO')


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


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


3
n = int(input())
str = input()
L = [1, 4, 7]
R = [3, 6, 9]
T = [1, 2, 3]
B = [7, 9]
bl = False
br = False
bt = False
bb = False
b0 = False
for s in str:
	symb = int(s)
	bl = bl or symb in L
	br = br or symb in R
	bt = bt or symb in T
	bb = bb or symb in B
	b0 = b0 or symb == 0
if bl and br and bt and bb or (bt and b0):
	print('YES')
else:
	print('NO')


input()
a = list(map(int, str(input())))
d = {1: (0, 0), 2: (1, 0), 3: (2, 0), 4: (0, 1), 5: (1, 1), 6: (2, 1), 7: (0, 2), 8: (1, 2), 9: (2, 2), 0: (1, 3)}
r = list(map(lambda x: (d[x][0] + 1, d[x][1]), a))
l = list(map(lambda x: (d[x][0] - 1, d[x][1]), a))
t = list(map(lambda x: (d[x][0], d[x][1] + 1), a))
b = list(map(lambda x: (d[x][0], d[x][1] - 1), a))
rt = list(map(lambda x: (d[x][0] + 1, d[x][1] + 1), a))
rb = list(map(lambda x: (d[x][0] + 1, d[x][1] - 1), a))
lt = list(map(lambda x: (d[x][0] - 1, d[x][1] + 1), a))
lb = list(map(lambda x: (d[x][0] - 1, d[x][1] - 1), a))
if all([x in d.values() for x in r]) or all([x in d.values() for x in l]) or all([x in d.values() for x in t]) or all([x in d.values() for x in b]) or all([x in d.values() for x in rt]) or all([x in d.values() for x in rb]) or all([x in d.values() for x in lt]) or all([x in d.values() for x in lb]):
	print('NO')
else:
	print('YES')


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)
	coordinates = [coordDict[int(c)] for c in s]
	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
	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
main()


pos = [[4, 2]]
for x in range(1, 4):
	for y in range(1, 4):
		pos.append([x, y])
a = [[-1, -1, -1, -1, -1], [-1, 1, 2, 3, -1], [-1, 4, 5, 6, -1], [-1, 7, 8, 9, -1], [-1, -1, 0, -1, -1], [-1, -1, -1, -1, -1]]
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 = int(input())
s = list(map(int, list(input())))
m = [(3, 1)]
for i in range(3):
	for j in range(3):
		m.append((i, j))
add = lambda x, a: (x[0] + a[0], x[1] + a[1])
sub = lambda x, a: (x[0] - a[0], x[1] - a[1])
mov = [sub(m[s[i]], m[s[i - 1]]) for i in range(1, n)]
res = 'YES'
for i in range(10):
	if s[0] == i:
		continue
	c = m[i]
	suc = True
	for mo in mov:
		c = add(c, mo)
		if c not in m:
			suc = False
			break
	if suc:
		res = 'NO'
print(res)


n = int(input())
s = list(input())
c = [0] * 4
d = 0
for i in s:
	if i in ['1', '2', '3']:
		c[0] = 1
		d += 1
	if i in ['1', '4', '7']:
		c[1] = 1
	if i in ['3', '6', '9']:
		c[2] = 1
	if i in ['7', '0', '9']:
		c[3] = 1
if sum(c) == 4 or ('0' in s and d):
	print('YES')
	exit(0)
else:
	print('NO')
	exit(0)


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

def __starting_point():
	main()
__starting_point()


n = int(input())
s = input()
l = [[[-1, -3], [0, -3], [1, -3], [-1, -2], [0, -2], [1, -2], [-1, -1], [0, -1], [1, -1], [0, 0]], [[0, 0], [1, 0], [2, 0], [0, 1], [1, 1], [2, 1], [0, 2], [1, 2], [2, 2], [2, 3]], [[-1, 0], [0, 0], [1, 0], [-1, 1], [0, 1], [1, 1], [-1, 2], [0, 2], [1, 2], [0, 3]], [[-2, 0], [-1, 0], [0, 0], [-2, 1], [-1, 1], [0, 1], [-2, 2], [-1, 2], [0, 2], [-1, 3]], [[0, -1], [1, -1], [2, -1], [0, 0], [1, 0], [2, 0], [0, 1], [1, 1], [2, 1], [1, 2]], [[-1, -1], [0, -1], [1, -1], [-1, 0], [0, 0], [1, 0], [-1, 1], [0, 1], [1, 1], [0, 2]], [[-2, -1], [-1, -1], [0, -1], [-2, 0], [-1, 0], [0, 0], [-2, 1], [-1, 1], [0, 1], [-1, 2]], [[0, -2], [1, -2], [2, -2], [0, -1], [1, -1], [2, -1], [0, 0], [1, 0], [2, 0], [1, 1]], [[-1, -2], [0, -2], [1, -2], [-1, -1], [0, -1], [1, -1], [-1, 0], [0, 0], [1, 0], [0, 1]], [[-2, -2], [-1, -2], [0, -2], [-2, -1], [-1, -1], [0, -1], [-2, 0], [-1, 0], [0, 0], [-1, 1]]]
pos = [[1, 3], [0, 0], [1, 0], [2, 0], [0, 1], [1, 1], [2, 1], [0, 2], [1, 2], [2, 2]]

def bad(i, j):
	if i < 0 or j < 0:
		return 1
	if i > 2 or j > 3:
		return 1
	if [i, j] == [0, 3] or [i, j] == [2, 3]:
		return 1
	return 0
ll = []
for i in range(n - 1):
	(x, y) = (int(s[i]), int(s[i + 1]) - 1)
	ll.append(l[x][y])
res = 'YES'
z = []
for num in range(10):
	(i, j) = (pos[num][0], pos[num][1])
	c = 1
	for k in range(n - 1):
		i += ll[k][0]
		j += ll[k][1]
		if bad(i, j):
			c = 0
	z.append(c)
z[int(s[0])] = 0
if 1 in z:
	res = 'NO'
print(res)


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


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 <= 1:
	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')


n = int(input())
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')


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


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


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


import sys
n = int(sys.stdin.readline())
digits = [int(x) for x in sys.stdin.readline().strip()]

def can_go_left(digits):
	return all((x not in digits for x in [0, 1, 4, 7]))

def can_go_right(digits):
	return all((x not in digits for x in [0, 3, 6, 9]))

def can_go_up(digits):
	return all((x not in digits for x in [1, 2, 3]))

def can_go_down(digits):
	return all((x not in digits for x in [0, 7, 9]))
if can_go_left(digits) or can_go_right(digits) or can_go_up(digits) or can_go_down(digits):
	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
	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')


input()
s = set(map(int, input()))
print('YES' if all(map(lambda x: x & s != set(), ({1, 4, 7, 0}, {1, 2, 3}, {3, 6, 9, 0}, {7, 0, 9}))) else 'NO')


moves = eval(input())
numlist = list(map(int, [w for w in input()]))
changedlist = []
numPad = {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]}
for i in range(1, moves):
	temp = [numPad[numlist[i]][0] - numPad[numlist[0]][0], numPad[numlist[i]][1] - numPad[numlist[0]][1]]
	changedlist.append(temp)
answer = 'YES'
for i in range(10):
	canMove = [False for _ in range(moves - 1)]
	exitByBreak = False
	for j in range(moves - 1):
		if numPad[i] != numPad[numlist[0]]:
			row = numPad[i][0] + changedlist[j][0]
			col = numPad[i][1] + changedlist[j][1]
			if col == 1:
				if row <= 3 and row >= 0:
					canMove[j] = True
				else:
					exitByBreak = True
					break
			elif (row <= 2 and row >= 0) and (col >= 0 and col <= 2):
				canMove[j] = True
			else:
				exitByBreak = True
				break
		else:
			exitByBreak = True
			break
	if exitByBreak == True:
		continue
	else:
		answer = 'NO'
		break
print(answer)


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


n = int(input())
s = input()
a = []
for i in range(0, 10):
	a.append(False)
for i in range(n):
	a[int(s[i])] = True
if (a[1] or a[2] or a[3]) and (a[1] or a[4] or a[7] or a[0]) and (a[9] or a[0] or a[7]) and (a[3] or a[6] or a[9] or a[0]):
	print('YES')
else:
	print('NO')


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 or c == 0:
			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
	if cond1 and cond2 and cond3 and cond4:
		print('YES')
	else:
		print('NO')


m = {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)}
n = int(input())
k = input()
p = []
for i in k:
	p.append(m[int(i)])

def valid(i, j):
	if i >= 1 and i <= 3 and (j >= 1) and (j <= 3):
		return True
	return i == 4 and j == 2
dx = [-1, 1, 0, 0, -1, -1, 1, 1]
dy = [0, 0, 1, -1, -1, 1, -1, 1]
for i in range(len(dx)):
	fl = True
	for z in range(len(p)):
		x = p[z][0]
		y = p[z][1]
		if not valid(x + dx[i], y + dy[i]):
			fl = False
			break
	if fl:
		print('NO')
		exit(0)
print('YES')


n = int(input())
s = input()
can_move_hor = True
can_move_ver = True
if (s.count('0') or s.count('7') or s.count('9')) and (s.count('1') or s.count('2') or s.count('3')):
	can_move_ver = False
if s.count('0') and (s.count('1') or s.count('2') or s.count('3')):
	can_move_hor = False
if (s.count('1') or s.count('4') or s.count('7')) and (s.count('3') or s.count('6') or s.count('9')):
	can_move_hor = False
if can_move_ver or can_move_hor:
	print('NO')
else:
	print('YES')


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


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


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
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)
allowed = list(range(1, 10)) + [11]
possible = False
for start in allowed:
	cur_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]
		if row2 < 1 or col2 < 1 or row2 > 4 or (col2 > 3) or (row2 == 4 and col2 != 2):
			cur_possible = False
			break
		row1 = row2
		col1 = col2
	if cur_possible == True:
		possible = True
		break
if possible:
	print('NO')
else:
	print('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')


input()
f = set(input())
if '0' in f and (not f.isdisjoint(set({'1', '2', '3'}))):
	print('YES')
elif '1' in f and '9' in f or ('3' in f and '7' in f) or ():
	print('YES')
elif set({'2', '4', '6', '8'}).issubset(f) and (not f.isdisjoint(set({'7', '9'}))):
	print('YES')
elif set({'3', '4', '9'}).issubset(f) or set({'2', '9', '7'}).issubset(f) or set({'1', '7', '6'}).issubset(f):
	print('YES')
elif '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')


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]
	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
		currentX = x
		currentY = y
		bExistOther = True
		for move in moveList:
			currentX += move.dx
			currentY += move.dy
			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')


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')
elif '8' in s and '7' not in s and ('9' not in s):
	print('NO')
elif x[-1] - x[0] == 2 and y[-1] - y[0] == 2:
	print('YES')
else:
	print('NO')


n = input()
s = input()
up = len([i for i in ['1', '2', '3'] if i in s]) == 0
right = len([i for i in ['3', '6', '9', '0'] if i in s]) == 0
left = len([i for i in ['1', '4', '7', '0'] if i in s]) == 0
down = len([i for i in ['7', '9', '0'] if i in s]) == 0
ok = not (up or right or left or down)
if ok:
	print('YES')
else:
	print('NO')


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

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

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

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

def exists_right(s):
	l1 = [x + 1 for x in s]
	return all((x in l for x in l1))
if exists_up(s) or exists_down(s) or exists_left(s) or exists_right(s):
	print('NO')
else:
	print('YES')


import sys
n = int(sys.stdin.readline())
s = str(sys.stdin.readline()[:-1])

def answer(s):
	ans = 'NO'
	col1 = ['1', '4', '7']
	col2 = ['2', '5', '8', '0']
	col3 = ['3', '6', '9']
	posNums = [[0, 0] for x in s]
	added = 0
	for digit in s:
		if digit == '0':
			posNums[added] = [2, 3]
		elif digit in col1:
			posNums[added] = [1, int(digit) // 3]
		elif digit in col2:
			posNums[added] = [2, int(digit) // 3]
		elif digit in col3:
			posNums[added] = [3, (int(digit) - 1) // 3]
		added = added + 1
	ans = 'YES'
	toNo = True
	for pos in posNums:
		tmp = pos[1] + 1
		if pos[0] == 2:
			if tmp >= 4:
				toNo = False
				break
		elif tmp >= 3:
			toNo = False
			break
	if toNo:
		ans = 'NO'
		return ans
	toNo = True
	for pos in posNums:
		tmp = pos[1] - 1
		if tmp < 0:
			toNo = False
			break
	if toNo:
		ans = 'NO'
		return ans
	if not '0' in s:
		toNo = True
		for pos in posNums:
			tmp = pos[0] + 1
			if tmp > 3:
				toNo = False
				break
		if toNo:
			ans = 'NO'
			return ans
		toNo = True
		for pos in posNums:
			tmp = pos[0] - 1
			if tmp < 1:
				toNo = False
				break
		if toNo:
			ans = 'NO'
			return ans
	return ans
print(answer(s))


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(input())
num = input()
keyb = [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9'], [-1, '0', -1]]

def findKey(key):
	for k in range(4):
		for k1 in range(3):
			if keyb[k][k1] == key:
				return [k, k1]
movements = []
keys = []
for a in range(n):
	keys.append(findKey(num[a]))
for a in range(1, n):
	key = keys[a - 1]
	key1 = keys[a]
	mov0 = 0
	mov1 = 0
	if key[0] < key1[0]:
		mov0 = abs(key[0] - key1[0])
	else:
		mov0 = key1[0] - key[0]
	if key[1] == key1[1]:
		mov1 = 0
	elif key1[1] > key[1]:
		mov1 = key1[1] - key[1]
	elif key[1] > key1[1]:
		mov1 = key1[1] - key[1]
	movements.append([mov0, mov1])

def check(a, b):
	for m in movements:
		a += m[0]
		b += m[1]
		if a < 0 or b < 0 or a > 3 or (b > 2):
			return False
		if keyb[a][b] == -1:
			return False
	return True
done = 0
for k1 in range(4):
	for k2 in range(3):
		if keyb[k1][k2] == -1:
			continue
		if [k1, k2] == keys[0]:
			continue
		if check(k1, k2) == True:
			print('NO')
			done = 1
			break
	if done == 1:
		break
if done == 0:
	print('YES')


input()
l = input()
for s in ('0456789', '124578', '1234568', '235689'):
	if all((c in s for c in l)):
		print('NO')
		break
else:
	print('YES')


input()
s = input()
a = [0] * 10
for i in s:
	a[int(i)] = 1
ok = 'YES'
if a[1] + a[2] + a[3] == 0 or a[1] + a[4] + a[7] + a[0] == 0 or a[3] + a[6] + a[9] + a[0] == 0 or (a[7] + a[0] + a[9] == 0):
	ok = 'NO'
print(ok)


KEYS = {1: (0, 0), 2: (1, 0), 3: (2, 0), 4: (0, 1), 5: (1, 1), 6: (2, 1), 7: (0, 2), 8: (1, 2), 9: (2, 2), 0: (1, 3)}
BOARD = set(KEYS.values())
n = int(input())
number = list(map(int, list(input())))

def add_offset(cell, offset):
	return (cell[0] + offset[0], cell[1] + offset[1])
uniq = True
for posible_starts in BOARD:
	if KEYS[number[0]] != posible_starts:
		all_fit = True
		off = (posible_starts[0] - KEYS[number[0]][0], posible_starts[1] - KEYS[number[0]][1])
		for num_part in number:
			if add_offset(KEYS[num_part], off) not in BOARD:
				all_fit = False
				break
		if all_fit:
			uniq = False
if uniq:
	print('YES')
else:
	print('NO')


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


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


n = int(input())
s = input()
haszero = 0
for x in s:
	if x == '0':
		haszero = 1
hasup = 0
hasleft = 0
hasright = 0
hasdown = 0
for x in s:
	if x == '1' or x == '2' or x == '3':
		hasup = 1
	if x == '1' or x == '4' or x == '7':
		hasleft = 1
	if x == '3' or x == '6' or x == '9':
		hasright = 1
	if x == '7' or x == '0' or x == '9':
		hasdown = 1
if hasup and hasleft and hasright and hasdown:
	print('YES')
elif hasup and haszero:
	print('YES')
else:
	print('NO')


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())
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
	else:
		potty = True
		break
if potty == True:
	print('NO')
else:
	print('YES')


class b_1:
	id = 1
	sides = [3, 4, 5]

class b_2:
	id = 2
	sides = [3, 4, 5, 6, 7]

class b_3:
	id = 3
	sides = [5, 6, 7]

class b_4:
	id = 4
	sides = [1, 2, 3, 4, 5]

class b_5:
	id = 5
	sides = [0, 1, 2, 3, 4, 5, 6, 7]

class b_6:
	id = 6
	sides = [1, 0, 7, 6, 5]

class b_7:
	id = 7
	sides = [1, 2, 3, 4]

class b_8:
	id = 8
	sides = [0, 1, 2, 3, 5, 7]

class b_9:
	id = 9
	sides = [1, 0, 7, 6]

class b_0:
	id = 0
	sides = [0, 1, 2]

def check(digit, check_list):
	answer_list = list(check_list)
	for button in buttons:
		if int(digit) == button.id:
			for side in check_list:
				if side not in button.sides:
					answer_list.remove(side)
			return answer_list
n = int(input())
number = input()
buttons = [b_1, b_2, b_3, b_4, b_5, b_6, b_7, b_8, b_9, b_0]
check_list_ = [0, 1, 2, 3, 4, 5, 6, 7]
for digit in number:
	check_list_ = check(digit, check_list_)
if not check_list_:
	print('YES')
else:
	print('NO')


input()
s = input()
h1 = '1' in s or '4' in s or '7' in s
h2 = '3' in s or '6' in s or '9' in s
v1 = '1' in s or '2' in s or '3' in s
v2 = '7' in s or '0' in s or '9' in s
nl = '0' in s
print('YES' if h1 and h2 and v1 and v2 or (v1 and nl) else 'NO')


n = int(input())
a = input()
L = [char for char in a]
X = [[0, 0], [-1, 3], [0, 3], [1, 3], [-1, 2], [0, 2], [1, 2], [-1, 1], [0, 1], [1, 1]]
dp = [[[0, 0] for i in range(10)] for j in range(10)]
for i in range(10):
	for j in range(10):
		dp[i][j] = [X[j][0] - X[i][0], X[j][1] - X[i][1]]
res = []
for k in range(n - 1):
	x = dp[ord(a[k]) - ord('0')][ord(a[k + 1]) - ord('0')]
	res.append(x)
ans = []
for i in range(10):
	(in_0, in_1) = (X[i][0], X[i][1])
	add = [i]
	for j in res:
		(in_0, in_1) = (in_0 + j[0], in_1 + j[1])
		for k in range(10):
			if X[k] == [in_0, in_1]:
				add.append(k)
	if len(add) == n:
		ans.append(add)
if len(ans) == 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')


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


n = int(input())
a = input()
digits = [int(digit) - 1 for digit in a]
for i in range(len(digits)):
	if digits[i] == -1:
		digits[i] = 10
phone = [[3 * j + i for i in range(3)] for j in range(4)]
phone[3][0] = -1
phone[3][1] = 10
phone[3][2] = -1
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])

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
for i in range(12):
	if phone[int(i / 3)][i % 3] != -1:
		ok += checkPattern(int(i / 3), i % 3)
if ok == 1:
	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') or (a == '729'):
	print('YES')
elif 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')


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


input()
l = list(map(int, list(input())))
if (1 in l or 4 in l or 7 in l or (0 in l)) and (1 in l or 2 in l or 3 in l) and (3 in l or 6 in l or 9 in l or (0 in l)) and (7 in l or 0 in l or 9 in l):
	print('YES')
else:
	print('NO')


n = int(input())
s = input()
r = [0, 0, 0, 0]
c = [0, 0, 0]
os = ['NO', 'YES']
ans = 0
cs = rs = 0
for i in s:
	if i == 0:
		if not f0:
			r[3] = 1
			rs += 1
		continue
	t = int(i)
	if r[(t - 1) // 3] == 0:
		rs += 1
		r[(t - 1) // 3] = 1
	if c[(t - 1) % 3] == 0:
		cs += 1
		c[(t - 1) % 3] = 1
if not r[3]:
	if r[0] == r[2] == c[0] == c[2] and ('7' in s or '9' in s):
		ans = 1
else:
	ans = r[0] == 1
print(os[ans])


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 = input()
s = set(map(int, input()))
f = lambda x: x & s != set()
print('NO' if sum([f({1, 4, 7, 0}), f({1, 2, 3}), f({3, 6, 9, 0}), f({7, 0, 9})]) < 4 else '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')


def f(x):
	if x == 0:
		return (4, 2)
	else:
		return ((x - 1) // 3 + 1, (x - 1) % 3 + 1)
t = [-1] * 5
t2 = [-1, 1, 1, 1, -1]
d = [t, t2, t2, t2, [-1, -1, 1, -1, -1], t]
n = int(input())
offset = [[1, 0], [0, 1], [-1, 0], [0, -1]]
coord = [f(int(i)) for i in input()]
for (dx, dy) in offset:
	if all((d[x + dx][y + dy] == 1 for (x, y) in coord)):
		print('NO')
		break
else:
	print('YES')


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

def solve(s):
	if '0' in s:
		tf = any((i in s for i in '123'))
	elif all((i not in s for i in '79')):
		tf = False
	else:
		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 '789'))
	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)
main()


s = input()
s = input()
ok = 0
if '1' not in s and '4' not in s and ('7' not in s) and ('0' 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) and ('0' 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')


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 or (old_position[0] == 1 and old_position[1] == 3):
				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]
finger_path = calc_path(number_phone, keypad)
answer = check_path(finger_path, keypad)
print(answer)


def is_pos_correct(x, y):
	return 0 <= x <= 2 and 0 <= y <= 2 or (x == 1 and y == 3)

def is_v_correct(v, x, y):
	if not is_pos_correct(x, y):
		return False
	for (vx, vy) in v:
		x += vx
		y += vy
		if not is_pos_correct(x, y):
			return False
	return True

def move_v(v, dx, dy):
	return [(x + dx, y + dy) for (x, y) in v]

def get_row(x):
	return 3 if x == 0 else (x - 1) // 3

def get_col(x):
	return 1 if x == 0 else (x - 1) % 3

def get_pos(x):
	return (get_col(x), get_row(x))

def get_shift(x, y):
	(x, y) = (int(x), int(y))
	return (get_col(y) - get_col(x), get_row(y) - get_row(x))

def create_v(s):
	return [get_shift(x, y) for (x, y) in zip(s, s[1:])]

def main():
	input()
	n = [int(x) for x in input()]
	base_v = create_v(n)
	for (x, y) in [(xx, yy) for xx in (-1, 0, 1) for yy in (-1, 0, 1) if not (xx == 0 and yy == 0)]:
		new_pos = move_v([get_pos(n[0])], x, y)[0]
		if is_v_correct(base_v, new_pos[0], new_pos[1]):
			print('NO')
			return
	print('YES')
main()


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(input())
s = input()
fill = [[False for i in range(3)] for j in range(4)]
for i in s:
	if i == '0':
		j = 10
	else:
		j = ord(i) - ord('1')
	fill[j // 3][j % 3] = True
top = fill[0][0] or fill[0][1] or fill[0][2]
bottom = fill[2][0] or fill[3][1] or fill[2][2]
left = fill[0][0] or fill[1][0] or fill[2][0]
right = fill[0][2] or fill[1][2] or fill[2][2]
if (not left or not right) and (not fill[3][1]) or not top or (not bottom):
	print('NO')
else:
	print('YES')


n = input()
set_of_keys = input()

def up(x):
	return True if x > 3 or x == 0 else False

def down(x):
	return True if x not in [7, 9, 0] else False

def left(x):
	return True if x not in [1, 4, 7, 0] else False

def right(x):
	return True if x not in [3, 6, 9, 0] else False
f = f2 = f3 = f4 = False
for e in set_of_keys:
	if not up(int(e)):
		f = True
		break
for e in set_of_keys:
	if not down(int(e)):
		f2 = True
		break
for e in set_of_keys:
	if not left(int(e)):
		f3 = True
		break
for e in set_of_keys:
	if not right(int(e)):
		f4 = True
		break
if f and f2 and f3 and f4:
	print('YES')
else:
	print('NO')


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

def canMove(moves, dx, dy):
	for (x, y) in moves:
		tx = x + dx
		ty = y + dy
		if not (0 <= tx < 3 and 0 <= ty < 3):
			if not (tx == 3 and ty == 1):
				return False
	return True
l = [[3, 1], [0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]]
move = []
for x in s:
	move.append(l[int(x)])
cnt = 0
for i in range(10):
	for j in range(10):
		dx = i - 5
		dy = j - 5
		if canMove(move, dx, dy):
			cnt += 1
if cnt == 1:
	print('YES')
else:
	print('NO')


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


def getpos(mov):
	return (3, 1) if mov == 0 else ((mov - 1) // 3, (mov - 1) % 3)
len = int(input())
inp = input()
pos = []
first = None
prev = None
for i in inp:
	mov = int(i)
	curr = getpos(mov)
	if prev == None:
		prev = curr
		first = mov
		continue
	pos.append((curr[0] - prev[0], curr[1] - prev[1]))
	prev = curr
sol = 'YES'
for x in range(10):
	if x == first:
		continue
	curr_pos = getpos(x)
	success = True
	for p in pos:
		new_pos = (curr_pos[0] + p[0], curr_pos[1] + p[1])
		if new_pos != getpos(0) and (new_pos[0] < 0 or new_pos[0] > 2 or new_pos[1] < 0 or (new_pos[1] > 2)):
			success = False
			break
		curr_pos = new_pos
	if success:
		sol = 'NO'
		break
print(sol)


n = int(input())
seq = input()
d = [False] * 10
for i in seq:
	d[int(i)] = True

def main():
	if not (d[7] or d[9] or d[0]):
		print('NO')
		return
	elif d[0] and (d[1] or d[2] or d[3]):
		print('YES')
		return
	elif ((d[1] or d[4] or d[7]) and (d[3] or d[6] or d[9])) and ((d[1] or d[2] or d[3]) and (d[7] or d[8] or d[9])):
		print('YES')
		return
	else:
		print('NO')
		return
main()


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 di in digits:
	if di[1] == 1 and di[0] == 3:
		l = True
		r = True
		d = True
	else:
		if di[1] == 0:
			l = True
		if di[1] == 2:
			r = True
		if di[0] == 0:
			u = True
		if di[0] == 2 and di[1] != 1:
			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 (2, 2) not in pos and (2, 0) not in pos:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


import sys
import os
n = int(input())
str = input()
mat = [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9'], ['-1', '0', '-1']]
for i in range(0, 4):
	for j in range(0, 3):
		if str[0] == mat[i][j]:
			cur = [i, j]
dis = []
for z in range(1, n):
	for i in range(0, 4):
		for j in range(0, 3):
			if str[z] == mat[i][j]:
				dis.append([i - cur[0], j - cur[1]])
				cur = [i, j]
cnt = 0
for z in range(0, 10):
	for i in range(0, 4):
		for j in range(0, 3):
			if chr(z + ord('0')) == mat[i][j]:
				cur = [i, j]
	flag = True
	for i in range(0, len(dis)):
		cur[0] = cur[0] + dis[i][0]
		cur[1] = cur[1] + dis[i][1]
		if cur[0] >= 4 or cur[0] < 0 or cur[1] >= 3 or (cur[1] < 0) or (mat[cur[0]][cur[1]] == '-1'):
			flag = False
			break
	if flag:
		cnt = cnt + 1
if cnt == 1:
	print('YES')
else:
	print('NO')


n = input()
s = set(map(int, input()))
arr1 = {1, 4, 7, 0}
arr2 = {1, 2, 3}
arr3 = {3, 6, 9, 0}
arr4 = {7, 0, 9}
print('YES' if all(map(lambda x: x & s != set(), (arr1, arr2, arr3, arr4))) else 'NO')


p = [True] * 10
n = int(input())
num = input()
grid = [(3, 1), (0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]
start = int(num[0])
prev = grid[int(num[0])]
p[start] = False
moves = grid
for i in num[1:]:
	l = grid[int(i)]
	dx = l[0] - prev[0]
	dy = l[1] - prev[1]
	prev = l
	moves = [(m[0] + dx, m[1] + dy) for m in moves]
	for m in range(len(moves)):
		if p[m]:
			if moves[m] not in grid:
				p[m] = False
if True in p:
	print('NO')
else:
	print('YES')


import traceback
import math
from collections import defaultdict
from functools import lru_cache

def main():
	N = int(input())
	nums = input()
	locs = '31 00 01 02 10 11 12 20 21 22'.split()
	data = {str(k): (int(r), int(c)) for (k, (r, c)) in zip(range(10), locs)}
	dirs = []
	(pr, pc) = data[nums[0]]
	for n in nums[1:]:
		(r, c) = data[n]
		(dr, dc) = (r - pr, c - pc)
		dirs.append([dr, dc])
		(pr, pc) = (r, c)
	for n in range(10):
		n = str(n)
		if n == nums[0]:
			continue
		(pr, pc) = data[n]
		done = True
		for (dr, dc) in dirs:
			(r, c) = (pr + dr, pc + dc)
			if not (r == 3 and c == 1 or (0 <= r < 3 and 0 <= c < 3)):
				done = False
				break
			(pr, pc) = (r, c)
		if done:
			return True
	return False
try:
	ans = main()
	ans = 'YES' if not ans else 'NO'
	print(ans)
except Exception as e:
	print(e)
	traceback.print_exc()


def works(numbers):
	if numbers[1] or numbers[2] or numbers[3]:
		if numbers[7] or numbers[0] or numbers[9]:
			if numbers[1] or numbers[4] or numbers[7] or numbers[0]:
				if numbers[3] or numbers[6] or numbers[9] or numbers[0]:
					return True
				else:
					return False
			else:
				return False
		else:
			return False
	else:
		return False
n = int(input())
line = input()
numbers = {}
for i in range(10):
	numbers[i] = False
for ch in line:
	numbers[int(ch)] = True
if works(numbers):
	print('YES')
else:
	print('NO')


n = int(input())
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 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 = int(input())
d = list(map(int, input()))
l = all([i not in d for i in [1, 4, 7, 0]])
r = all([i not in d for i in [3, 6, 9, 0]])
u = all([i not in d for i in [1, 2, 3]])
d = all([i not in d for i in [7, 0, 9]])
print('NO' if l or r or u or d else 'YES')


n = int(input())
a = list(map(int, input()))
b = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [-1, 0, -1]]
p = [0] * 10
p[0] = (4, 2)
p[1] = (1, 1)
p[2] = (1, 2)
p[3] = (1, 3)
p[4] = (2, 1)
p[5] = (2, 2)
p[6] = (2, 3)
p[7] = (3, 1)
p[8] = (3, 2)
p[9] = (3, 3)
path = []
for i in range(1, n):
	dx = p[a[i]][0] - p[a[i - 1]][0]
	dy = p[a[i]][1] - p[a[i - 1]][1]
	path.append((dx, dy))

def go(x, y, i):
	if i == n - 1:
		print('NO')
		exit()
	(nx, ny) = (x + path[i][0], y + path[i][1])
	if 1 <= nx <= 4 and 1 <= ny <= 3 and (b[nx - 1][ny - 1] != -1):
		go(nx, ny, i + 1)
for (x, y) in p:
	if b[x - 1][y - 1] != a[0] and b[x - 1][y - 1] != -1:
		go(x, y, 0)
print('YES')


n = int(input())
s = input()
s = list(s)
l1 = 0
l3 = 0
l4 = 0
l11 = 0
l22 = 0
l33 = 0
for j in range(n):
	if s[j] == '1' or s[j] == '2' or s[j] == '3':
		l1 += 1
	elif s[j] == '7' or s[j] == '8' or s[j] == '9':
		l3 += 1
	elif s[j] == '0':
		l4 += 1
	if s[j] == '1' or s[j] == '4' or s[j] == '7':
		l11 += 1
	elif s[j] == '2' or s[j] == '5' or s[j] == '8':
		l22 += 1
	elif s[j] == '3' or s[j] == '6' or s[j] == '9':
		l33 += 1
if l1 != 0 and l4 != 0:
	print('YES')
elif l1 != 0 and l3 != 0:
	if l11 != 0 and l33 != 0:
		if '7' in s or '9' in s:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
else:
	print('NO')


n = input()
s = input()
zero = s.count('0')
one = s.count('1')
two = s.count('2')
three = s.count('3')
four = s.count('4')
five = s.count('5')
six = s.count('6')
seven = s.count('7')
eight = s.count('8')
nine = s.count('9')
count = 0
if one > 0:
	count += 1
if three > 0:
	count += 1
if seven > 0:
	count += 1
if nine > 0:
	count += 1
if count >= 3:
	print('YES')
elif one > 0 and (nine > 0 or zero > 0):
	print('YES')
elif three > 0 and (seven > 0 or zero > 0):
	print('YES')
elif two > 0 and zero > 0:
	print('YES')
elif (one > 0 and two > 0 or (four > 0 and five > 0) or (seven > 0 and eight > 0)) and three > 0 and (six > 0) and (nine > 0):
	print('YES')
elif (two > 0 and three > 0 or (five > 0 and six > 0) or (eight > 0 and nine > 0)) and one > 0 and (four > 0) and (seven > 0):
	print('YES')
elif nine > 0 and (one > 0 and five > 0 or (two > 0 and four > 0)):
	print('YES')
elif seven > 0 and (two > 0 and six > 0 or (three > 0 and five > 0)):
	print('YES')
elif one > 0 and seven > 0 and (six > 0):
	print('YES')
elif three > 0 and nine > 0 and (four > 0):
	print('YES')
elif two > 0 and seven > 0 and (nine > 0):
	print('YES')
else:
	print('NO')


def main():
	input()
	l = list(map(int, input()))
	for s in ({0, 4, 5, 6, 7, 8, 9}, {1, 2, 4, 5, 7, 8}, {1, 2, 3, 4, 5, 6, 8}, {2, 3, 5, 6, 8, 9}):
		if all((x in s for x in l)):
			print('NO')
			return
	print('YES')
main()


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


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


a = input()
number = input()
bot = False
top = False
left = False
right = False
topS = {'1', '2', '3'}
botS = {'7', '0', '9'}
leftS = {'1', '4', '7', '0'}
rightS = {'3', '6', '9', '0'}
for c in number:
	if c in topS:
		top = True
	if c in botS:
		bot = True
	if c in leftS:
		left = True
	if c in rightS:
		right = True
if top and bot and right and left:
	print('YES')
else:
	print('NO')


a = input()
s = str(input())
r = 0
u = 0
d = 0
z = 0
l = 0
f = 0
for i in range(len(s)):
	if s[i] == '0':
		z = 1
	if s[i] == '1' or s[i] == '2' or s[i] == '3':
		u = 1
	if s[i] == '3' or s[i] == '6' or s[i] == '9':
		r = 1
	if s[i] == '7' or s[i] == '8' or s[i] == '9':
		d = 1
	if s[i] == '1' or s[i] == '4' or s[i] == '7':
		l = 1
	if s[i] == '7' or s[i] == '9':
		f = 1
if (u == 1 and r == 1 and (d == 1) and (l == 1)) and f == 1 or (z == 1 and u == 1):
	print('YES')
else:
	print('NO')


import os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	s = input()
	positions = [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2), (-1, -1), (3, 1), (-1, -1)]
	vectors = []
	for i in range(n - 1):
		digit1 = int(s[i])
		digit2 = int(s[i + 1])
		digit1 = digit1 - 1 if digit1 != 0 else 10
		digit2 = digit2 - 1 if digit2 != 0 else 10
		vectors.append((positions[digit2][0] - positions[digit1][0], positions[digit2][1] - positions[digit1][1]))
	count = 0
	for pos in positions:
		if pos == (-1, -1):
			continue
		else:
			pos_aux = pos
			i = 0
			completed = True
			while i < n - 1:
				pos_aux = (pos_aux[0] + vectors[i][0], pos_aux[1] + vectors[i][1])
				i += 1
				if pos_aux not in positions or pos_aux == (-1, -1):
					completed = False
					break
			if completed:
				count += 1
				if count >= 2:
					break
	if count >= 2:
		print('NO')
	else:
		print('YES')
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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(_, s) = (input(), set(input()))
print(('NO', 'YES')[all((set(t) & s for t in ('123', '709', '1470', '3690')))])


g = [(2, 4), (1, 1), (2, 1), (3, 1), (1, 2), (2, 2), (3, 2), (1, 3), (2, 3), (3, 3)]
n = int(input())
s = input()
path = []
for i in range(n - 1):
	dx = g[int(s[i + 1])][0] - g[int(s[i])][0]
	dy = g[int(s[i + 1])][1] - g[int(s[i])][1]
	path.append((dx, dy))
for i in range(10):
	if i == int(s[0]):
		continue
	(curr_x, curr_y) = (g[i][0], g[i][1])
	cnt = 0
	while cnt != n - 1 and (curr_x, curr_y) in g:
		curr_x += path[cnt][0]
		curr_y += path[cnt][1]
		cnt += 1
	if cnt == n - 1 and (curr_x, curr_y) in g:
		print('NO')
		exit()
print('YES')


import sys
n = int(input())
s = input()
way = []
for x in s:
	if x == '0':
		way.append(10)
	else:
		way.append(int(x) - 1)
count = 0
for i in range(10):
	if i == 9:
		now = 10
	else:
		now = i
	flag = 0
	for j in range(n - 1):
		dif = way[j + 1] - way[j]
		div1 = way[j + 1] // 3 - way[j] // 3
		div2 = (now + dif) // 3 - now // 3
		mod1 = way[j + 1] % 3 - way[j] % 3
		mod2 = (now + dif) % 3 - now % 3
		if not (div1 == div2 and mod1 == mod2):
			flag = 1
		now += dif
		if not (now == 10 or -1 < now < 9):
			flag = 1
	if flag == 0:
		count += 1
if count <= 1:
	print('YES')
else:
	print('NO')


n = int(input())
f = input()
a = [0] * 10
for i in range(n):
	a[int(f[i])] = 1
if a[1] + a[2] + a[3] == 0 or a[7] + a[9] + a[0] == 0 or a[1] + a[4] + a[7] + a[0] == 0 or (a[3] + a[6] + a[9] + a[0] == 0):
	print('NO')
else:
	print('YES')


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


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


n = int(input())
c = [0] * 10
for i in input():
	c[int(i)] = 1
f1 = sum((c[1], c[2], c[3]))
f2 = sum((c[1], c[4], c[7], c[0]))
f3 = sum((c[3], c[6], c[9], c[0]))
f4 = sum((c[7], c[9], c[0]))
print('NO' if 0 in (f1, f2, f3, f4) else 'YES')


n = int(input())
s = input()
a = [s.find(str(i)) != -1 for i in range(10)]
print('YES' if (a[1] or a[4] or a[7] or a[0]) and (a[1] or a[2] or a[3]) and (a[3] or a[6] or a[9] or a[0]) and (a[7] or a[0] or a[9]) else 'NO')