Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December.

A year is leap in one of two cases: either its number is divisible by 4, but not divisible by 100, or is divisible by 400. For example, the following years are leap: 2000, 2004, but years 1900 and 2018 are not leap.

In this problem you are given n (1 ≤ n ≤ 24) integers a_1, a_2, ..., a_{n}, and you have to check if these integers could be durations in days of n consecutive months, according to Gregorian calendar. Note that these months could belong to several consecutive years. In other words, check if there is a month in some year, such that its duration is a_1 days, duration of the next month is a_2 days, and so on.


-----Input-----

The first line contains single integer n (1 ≤ n ≤ 24) — the number of integers.

The second line contains n integers a_1, a_2, ..., a_{n} (28 ≤ a_{i} ≤ 31) — the numbers you are to check.


-----Output-----

If there are several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes).

You can print each letter in arbitrary case (small or large).


-----Examples-----
Input
4
31 31 30 31

Output
Yes


Input
2
30 30

Output
No


Input
5
29 31 30 31 30

Output
Yes


Input
3
31 28 30

Output
No


Input
3
31 31 28

Output
Yes




-----Note-----

In the first example the integers can denote months July, August, September and October.

In the second example the answer is no, because there are no two consecutive months each having 30 days.

In the third example the months are: February (leap year) — March — April – May — June.

In the fourth example the number of days in the second month is 28, so this is February. March follows February and has 31 days, but not 30, so the answer is NO.

In the fifth example the months are: December — January — February (non-leap year).

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
n = int(input())
l = [int(x) for x in input().split()]
p1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
p2 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
cp1 = p2 + p1 + p1
cp2 = p1 + p2 + p1
cp3 = p1 + p1 + p2
for i in range(12):
	if cp1[i] == l[0]:
		j = i + 1
		length = 1
		while length < n and j < 36:
			if l[length] != cp1[j]:
				break
			length += 1
			j += 1
		if length == n:
			print('Yes')
			exit(0)
for i in range(n + 11):
	if cp2[i] == l[0]:
		j = i + 1
		length = 1
		while length < n and j < 35:
			if l[length] != cp2[j]:
				break
			length += 1
			j += 1
		if length == n:
			print('Yes')
			exit(0)
for i in range(n + 11):
	if cp3[i] == l[0]:
		j = i + 1
		length = 1
		while length < n and j < 35:
			if l[length] != cp3[j]:
				break
			length += 1
			j += 1
		if length == n:
			print('Yes')
			exit(0)
print('No')


import sys
import math

def main():
	n = int(sys.stdin.readline().strip())
	leap = '31 29 31 30 31 30 31 31 30 31 30 31 '
	notleap = '31 28 31 30 31 30 31 31 30 31 30 31 '
	s = sys.stdin.readline().strip()
	print('Yes' if s in (notleap * 3 + leap) * 2 else 'No')
	print()
main()


sim = '31 28 31 30 31 30 31 31 30 31 30 31 '
l = '31 29 31 30 31 30 31 31 30 31 30 31 '
new = sim + sim + sim + l + sim + sim + sim + l
input()
s = input().strip()
if s in new:
	print('Yes')
else:
	print('No')


n = int(input())
lst = list(map(int, input().strip().split(' ')))
l1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] * 12
l1[13] = 29
l1[61] = 29
l1[97] = 29
l1[133] = 29
f = 0
for i in range(144 - n + 1):
	if l1[i:i + n] == lst:
		f = 1
		print('yes')
		break
if f == 0:
	print('no')


a = '31 28 31 30 31 30 31 31 30 31 30 31 ' * 3
b = '31 28 31 30 31 30 31 31 30 31 30 31 ' * 2 + '31 29 31 30 31 30 31 31 30 31 30 31 ' + '31 28 31 30 31 30 31 31 30 31 30 31 ' * 2
input()
c = input()
if c in a or c in b:
	print('Yes')
else:
	print('No')


Year = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n = int(input())
Seq = list(map(int, input().split()))
for i in range(len(Year)):
	if Year[i] == Seq[0] or Year[i] + Seq[0] == 57:
		febr = False
		j = i
		h = 0
		while h < n:
			if Seq[h] + Year[j] == 57:
				if not febr:
					h += 1
					j += 1
					febr = True
				else:
					break
			elif Seq[h] == Year[j]:
				h += 1
				j += 1
			else:
				break
			j %= 12
		if h == n:
			print('Yes')
			break
else:
	print('No')


n = int(input())
arr = input().split()
s = ''.join(arr)
ch = '312831303130313130313031312831303130313130313031312831303130313130313031312931303130313130313031' * 2
if s in ch:
	print('YES')
else:
	print('NO')


n = int(input())
days = list(map(int, input().split()))
l = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if str(days)[1:-1] in str(l)[1:-1]:
	print('Yes')
else:
	print('No')


months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n = int(input())
arr = list(map(int, input().split()))
flag = 0
count = 0
count2 = 0
for i in range(12):
	count = i
	for j in range(n):
		flag = 0
		if months[count] != arr[j]:
			if months[count] < 30 and arr[j] < 30:
				if arr[j] == 29:
					count2 += 1
			else:
				flag = 1
				break
		if count < 11:
			count += 1
		else:
			count = 0
	if flag == 0:
		break
if flag == 1:
	print('NO')
elif count2 >= 2:
	print('NO')
else:
	print('YES')


def find(array, sub):
	for i in range(len(array) - len(sub)):
		if array[i:i + len(sub)] == sub:
			return True
	return False
a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
b = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
aa = a + a + a + b + a + a + a
input()
num = [int(i) for i in input().split()]
flag = find(aa, num)
if flag:
	print('Yes')
else:
	print('No')


import sys

def readlines(type=int):
	return list(map(type, sys.stdin.readline().split()))

def read(type=int):
	return type(sys.stdin.readline().strip())
joint = lambda it, sep=' ': sep.join([str(i) if type(i) != list else sep.join(map(str, i)) for i in it])

def solve(days):
	l1 = '31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31'
	l2 = '31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31'
	l3 = '31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31'
	l4 = '31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31'
	daystr = ','.join(days)
	if daystr in l1 or daystr in l2 or daystr in l3 or (daystr in l4):
		return 'Yes'
	return 'No'

def main():
	read()
	days = readlines(str)
	print(solve(days))
main()


leap = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
nonLeap = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
years = nonLeap * 3 + leap + nonLeap * 3
n = int(input())
days = list(map(int, input().split()))
for i in range(len(years)):
	if days == years[i:i + n]:
		print('Yes')
		break
else:
	print('No')


n = int(input())
a = list(map(str, input().split()))
s = ''
s = s.join(a)
l1 = '312931303130313130313031'
l2 = '312831303130313130313031'
ans = l2 + l2 + l1 + l2 + l2
if ans.find(s) != -1:
	print('YES')
else:
	print('NO')


a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] * 4
b = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] * 2
n = int(input())
xx = list(map(int, input().split()))
for i in range(24):
	if xx == a[i:i + n] or xx == b[i:i + n]:
		print('Yes')
		exit()
print('No')


import sys
n = int(sys.stdin.readline())
months = sys.stdin.readline().strip().split()

def truePosition(month, days):
	month += 1
	if days == '28' or days == '29':
		if month == 2:
			return True
		else:
			return False
	if days == '30':
		if month in [4, 6, 9, 11]:
			return True
		else:
			return False
	if days == '31':
		if month in [1, 3, 5, 7, 8, 10, 12]:
			return True
		else:
			return False

def isSubYear(n, months):
	if months.count('29') > 1:
		return 'No'
	for monthStart in range(0, 12):
		inYear = True
		for monthPos in range(len(months)):
			if truePosition((monthPos + monthStart) % 12, months[monthPos]) == False:
				inYear = False
		if inYear:
			return 'Yes'
	return 'No'
print(isSubYear(n, months))


n = int(input())
a = [int(i) for i in input().split()]
final_year = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
flag = False
for i in range(108 - n):
	k = final_year[i:i + n]
	if k == a:
		flag = True
		break
if flag:
	print('Yes')
else:
	print('No')


def sublistExists(list1, list2):
	return ''.join(map(str, list2)) in list1
N = int(input())
Z = list(map(int, input().split()))
B = '312931303130313130313031312831303130313130313031312831303130313130313031'
C = '312831303130313130313031312831303130313130313031312931303130313130313031'
D = '312831303130313130313031312931303130313130313031312831303130313130313031'
if sublistExists(B, Z) or sublistExists(C, Z) or sublistExists(D, Z):
	print('YES')
else:
	print('NO')


n = int(input())
x = input()
normyear = '31 28 31 30 31 30 31 31 30 31 30 31 '
leapyear = '31 29 31 30 31 30 31 31 30 31 30 31 '
ans = 3 * normyear + leapyear + 3 * normyear
print('Yes' if ans.count(x) else 'No')


n = int(input())
a = input()
p1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
p2 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
p = ' '.join([str(i) for i in p1 + p1 + p2 + p1 + p1])
if a in p:
	print('YES')
else:
	print('NO')


a1 = '31 28 31 30 31 30 31 31 30 31 30 31 '
a2 = '31 29 31 30 31 30 31 31 30 31 30 31 '
s = a1 + a1 + a1 + a2 + a1 + a1
n = input()
ss = input().strip()
print(['NO', 'YES'][ss in s])


arr = '31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31'
n = int(input())
s = input()
if s in arr:
	print('YES', end='')
else:
	print('NO', end='')


n = input()
a = '31 28 31 30 31 30 31 31 30 31 30 31 '
b = '31 29 31 30 31 30 31 31 30 31 30 31 '
years = a + a + a + b + a + a + a + b
if input().strip() in years:
	print('yes')
else:
	print('no')


n = int(input())
a = [int(x) for x in input().split()]
s = '312831303130313130313031312831303130313130313031312931303130313130313031312831303130313130313031312831303130313130313031'
s2 = ''
for i in a:
	s2 += str(i)
if s2 in s:
	print('YES')
else:
	print('NO')


e = ['31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31']
e_v = ['31', '29', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31']
e_1 = e_v + e + e
e_2 = e + e_v + e
e_3 = e + e + e_v
e_4 = e + e + e
input()
s = input().split()
b = False
for i in range(36 - len(s)):
	if e_1[i:i + len(s)] == s or e_2[i:i + len(s)] == s or e_3[i:i + len(s)] == s or (e_4[i:i + len(s)] == s):
		b = True
		break
if b:
	print('Yes')
else:
	print('No')


calendar = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] * 3 + [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
calendar = calendar + calendar
n = int(input())
l = [int(x) for x in input().split()]
ans = 'NO'
for i in range(len(calendar)):
	if i + n > len(calendar):
		break
	if l == calendar[i:i + n]:
		ans = 'YES'
		break
print(ans)


n = int(input())
l = input()
ynormal = ' 31 28 31 30 31 30 31 31 30 31 30 31'
yleap = ' 31 29 31 30 31 30 31 31 30 31 30 31'
year = yleap + ynormal * 3 + yleap + ynormal * 3 + yleap
if l in year:
	print('Yes')
else:
	print('No')


m = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
m2 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

def isSubarray(a, b):
	if len(a) == len(b):
		return a == b
	for i in range(0, len(b) - len(a)):
		if a == b[i:i + len(a)]:
			return True
	return False
n = int(input())
days = list(map(int, input().split(' ')))
result = isSubarray(days, m * 2) or isSubarray(days, m2 + m) or isSubarray(days, m + m2) or isSubarray(days, m * 3) or isSubarray(days, m2 + m * 2) or isSubarray(days, m + m2 + m) or isSubarray(days, m * 2 + m2)
print('Yes' if result else 'No')


def inl(a, b):
	for i in range(len(b) - len(a)):
		if a == b[i:i + len(a)]:
			return True
	return False
n = int(input())
A = list(map(int, input().split()))
d = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
u = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
ddd = d + d + d
ddu = d + d + u
dud = d + u + d
udd = u + d + d
if inl(A, ddd) or inl(A, ddu) or inl(A, dud) or inl(A, udd):
	print('Yes')
else:
	print('No')


l1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
l2 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n = int(input())
l = list(map(int, input().split()))
l3 = 3 * l1 + l2
l3 = l3 * n
s = ''
for x in l:
	s = s + str(x)
t = ''
for x in l3:
	t = t + str(x)
if t.find(s) != -1:
	print('YES\n')
else:
	print('NO\n')


s = ['31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31'] * 4
sx = ['31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31', '31', '29', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31'] * 2
n = int(input())
a = list(map(int, input().split()))
if a.count(29) > 1:
	print('NO')
	exit()
k = 0
l = 0
for i in a:
	if i == 29:
		l = 1
	if i == 28:
		k = 1
a = ''.join((str(e) for e in a))
if l == k == 0 or k == 1:
	s = ''.join((str(e) for e in s))
	if a in s:
		print('YES')
		exit()
if l == k == 1 or l == 1:
	sx = ''.join((str(e) for e in sx))
	if a in sx:
		print('YES')
		exit()
if k:
	s = ''.join((str(e) for e in s))
	if a in s:
		print('YES')
		exit()
print('NO')


s1 = '31 28 31 30 31 30 31 31 30 31 30 31 '
s2 = '31 29 31 30 31 30 31 31 30 31 30 31 '
input()
print(['NO', 'YES'][input() in s1 * 3 + s2 + s1 * 3])


nl = '31 28 31 30 31 30 31 31 30 31 30 31'
l = '31 29 31 30 31 30 31 31 30 31 30 31'
years = nl + ' ' + nl + ' ' + nl + ' ' + l + ' ' + nl + ' ' + nl + ' ' + nl + ' ' + l + ' ' + nl
n = int(input())
x = input()
if x in years:
	print('YES')
else:
	print('NO')


a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n = int(input().strip())
arr = [int(i) for i in input().strip().split(' ')]
found = False
for i in range(36):
	val = True
	for j in range(n):
		val = val and arr[j] == a[(i + j) % 36]
	found = found or val
if found:
	print('Yes')
else:
	print('No')


n = int(input())
num = list(map(int, input().split()))
year = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if num.count(29) > 1:
	print('NO')
	exit()
if 29 in num:
	i = num.index(29)
	num[i] = 28
for j in range(len(year)):
	if year[j] == num[0]:
		t = True
		l = 0
		for k in range(j + 1, j + n):
			l += 1
			k = k % 12
			if num[l] != year[k]:
				t = False
		if t is True:
			print('YES')
			exit()
print('NO')


n = int(input())
l = input()
normal = '31 28 31 30 31 30 31 31 30 31 30 31 '
leap = '31 29 31 30 31 30 31 31 30 31 30 31 '
year = normal + leap + normal * 3 + leap + normal
if l in year:
	print('Yes')
else:
	print('No')


a = '31 28 31 30 31 30 31 31 30 31 30 31 '
b = '31 29 31 30 31 30 31 31 30 31 30 31 '
s = a + a + a + b + a + a
input()
print(['No', 'Yes'][input() in s])


import sys
from calendar import monthrange
n = int(input())
a = list(map(int, input().split(' ')))

def count_of_days(year, month):
	return monthrange(year, month)[1]

def solve(a):
	a29 = a.count(29)
	if a29 > 1:
		return 'NO'
	if a29 == 0:
		seq = []
		for year in range(2100, 2100 + 3):
			for month in range(1, 1 + 12):
				seq.append(count_of_days(year, month))
		return 'YES' if str.join(' ', map(str, a)) in str.join(' ', map(str, seq)) else 'NO'
	idx = a.index(29)
	year = 2000
	month = 2
	for i in range(idx - 1, -1, -1):
		month -= 1
		if month == 0:
			month = 12
			year -= 1
		if count_of_days(year, month) != a[i]:
			return 'NO'
	year = 2000
	month = 2
	for i in range(idx + 1, len(a)):
		month += 1
		if month == 13:
			month = 1
			year += 1
		if count_of_days(year, month) != a[i]:
			return 'NO'
	return 'YES'
print(solve(a))

def generate(year, month, n):
	a = [0] * n
	for i in range(n):
		a[i] = count_of_days(year, month)
		month += 1
		if month == 13:
			month = 1
			year += 1
	return a


n = int(input())
a = [int(i) for i in input().split()]
d = '312831303130313130313031312831303130313130313031312931303130313130313031312831303130313130313031'
e = '312931303130313130313031312831303130313130313031312831303130313130313031312831303130313130313031'
s = ''
for i in range(0, len(a)):
	s = s + str(a[i])
if s in d or s in e:
	print('YES')
else:
	print('NO')


a = ([31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] * 4 + [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]) * 100
n = int(input())
b = list(map(int, input().split()))
m = len(a)
for i in range(len(a)):
	if b == a[i:i + n]:
		print('Yes')
		exit(0)
print('No')


n = int(input())
a = [int(x) for x in input().strip().split(' ')]
from collections import Counter
import sys
c = Counter(a)
if c[28] > 3 or c[29] > 1:
	print('No')
	sys.exit()
for (i, x) in enumerate(a):
	if x == 29:
		a[i] = 28
b = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
c = b * 10
flag = False
for i in range(len(c)):
	if a == c[i:i + len(a)]:
		flag = True
if flag == True:
	print('Yes')
else:
	print('No')


n = int(input())
x = '312831303130313130313031'
b = x[-1:]
y = '312931303130313130313031'
c = y[-1:]
ch = b + x
ch1 = y + x
a = ''
l = list(map(int, input().split()))
for i in range(len(l)):
	a += str(l[i])
if ((y + y + y).find(a) != -1 or (x + x + x).find(a) != -1 or (x + x + y + y).find(a) != -1 or ((y + y + x + x).find(a) != -1)) and a.count('29') < 2:
	print('yes')
else:
	print('No')


cal = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n = int(input())
d = list(map(int, input().split()))
for i in range(len(cal) - n):
	if cal[i:i + n] == d:
		print('YES')
		exit()
print('NO')


y1 = '31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31'
n = int(input())
data = input()
if data.count('29') > 1:
	print('NO')
else:
	data = data.replace('29', '28')
	if data not in y1:
		print('NO')
	else:
		print('YES')


d = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
d1 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
da = d + d + d + d1 + d + d + d1 + d + d
n = int(input())
a = list(map(int, input().split()))
found = False
for i in range(n):
	for s in range(len(da) - n):
		if a == da[s:s + n]:
			print('YES')
			found = True
			break
	if found:
		break
if not found:
	print('NO')


n = int(input())
a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
b = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
a = list(map(str, a))
b = list(map(str, b))
c = a * 3 + b
c = c * 10
c = ''.join(c)
lis = list(map(str, input().split()))
lis = ''.join(lis)
if c.find(lis) == -1:
	print('NO')
else:
	print('YES')


l = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
l += l
n = int(input())
k = list(map(int, input().split()))
lim = 12 * 4 * 2 - n + 1
for i in range(0, lim):
	if k == l[i:i + n]:
		print('YES')
		exit()
print('NO')


n = int(input())
b = '31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31 30 31 31 28 31 30 31 30 31 31 30 31 30 31'
b = b.replace(',', ' ')
a = input()
if b.count(a) >= 1:
	print('Yes')
else:
	print('No')


n = int(input())
a = [int(i) for i in input().split()]
b = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
flag = 0
for i in range(0, 48):
	if b[i:n + i] == a:
		flag = 1
		break
	elif b[i:] + b[:(n + i) % 48] == a:
		flag = 1
		break
if flag == 0:
	print('NO')
else:
	print('YES')


import sys
c1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n = int(input())
a = [int(i) for i in input().split()]
if a.count(29) >= 2:
	print('NO')
	sys.exit(0)
elif a.count(29):
	a[a.index(29)] = 28
for i in range(12):
	if c1[i:i + n] == a:
		print('YES')
		break
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
up = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for i in range(len(up)):
	for j in range(len(up)):
		if up[i:j + 1] == a:
			print('YES')
			exit()
print('NO')


from sys import stdin as cin
from sys import stdout as cout
b = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

def main():
	n = int(cin.readline())
	a = list(map(int, cin.readline().split()))
	for i in range(len(b) - n):
		if b[i:i + n] == a:
			print('YES')
			return
	print('NO')
main()


n = int(input())
a = [int(i) for i in input().split()]
f = 0
mon = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for i in range(12):
	ff = 1
	leap = False
	for j in range(n):
		ind = (i + j) % 12
		if a[j] != mon[ind]:
			if not leap and mon[ind] == 28 and (a[j] == 29):
				leap = True
			else:
				ff = 0
	if ff:
		f = 1
if f:
	print('YES')
else:
	print('NO')


str = '31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 '
str += str
n = int(input())
s = input()
print('YES' if s in str else 'NO')


a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n = int(input())
b = list(map(int, input().split()))
for i in range(108 - n + 1):
	if b == a[i:i + n]:
		print('YES')
		exit()
print('NO')


import os
n = int(input())
arr = list(map(int, input().split()))
x = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if 29 in arr:
	x[1] = 29
else:
	x[1] = 28
check = 0
for i in range(0, 24):
	z = 0
	for j in range(n):
		if arr[j] != x[(i + j) % 24]:
			z = 1
			break
	if z == 0:
		check = 1
		break
if check == 1:
	print('Yes')
else:
	print('No')


n = int(input().strip())
arr = [int(i) for i in input().strip().split(' ')]
dic = {}
m = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
x = str(m)[1:-1]
y = str(arr)[1:-1]
r = y.replace('29', '28')
if (y in x or r in x) and arr.count(29) < 2:
	print('YES')
else:
	print('NO')


input()
print('Yes' if input() in ('31 28 31 30 31 30 31 31 30 31 30 31 ' * 3 + '31 29 31 30 31 30 31 31 30 31 30 31 ') * 2 else 'No')


nnn = '312831303130313130313031312831303130313130313031312831303130313130313031'
nnl = '312831303130313130313031312831303130313130313031312931303130313130313031'
nln = '312831303130313130313031312931303130313130313031312831303130313130313031'
lnn = '312931303130313130313031312831303130313130313031312831303130313130313031'
N = int(input())
s = input().split()
s = ''.join(s)
if s in nnn or s in nnl or s in nln or (s in lnn):
	print('YES')
else:
	print('NO')


n = int(input())
ai = list(map(int, input().split()))
ai2 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n2 = len(ai2)
ans = 0
for i in range(n2 - n):
	er = 0
	for j in range(n):
		if ai2[i + j] != ai[j]:
			er = 1
			break
	if er == 0:
		ans = 1
		break
print('YES' * ans + 'NO' * (1 - ans))


month1 = '312831303130313130313031312831303130313130313031312831303130313130313031312931303130313130313031312831303130313130313031312831303130313130313031'
n = int(input())
lines = [str(i) for i in input().split()]
if ''.join(lines) in month1:
	print('Yes')
else:
	print('No')


a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n = input()
b = list(map(int, input().split()))
for i in range(len(b)):
	if b[i] == 29:
		b[i] = 28
		break
for i in range(len(a) - len(b) + 1):
	e = 1
	for j in range(len(b)):
		if a[i + j] != b[j]:
			e = 0
			break
	if e:
		print('YES')
		exit(0)
print('NO')


ld = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n = int(input())
l = input().split()
r = 'No'
br = 0
pr = 0
for i in range(n):
	l[i] = int(l[i])
for i in range(len(ld) - n):
	k = i
	pr = 0
	for j in range(n):
		if l[j] == ld[k]:
			k += 1
			br += 1
		if ld[k] == 28:
			if l[j] == 29:
				pr += 1
				k += 1
				br += 1
	if pr > 1:
		r = 'No'
		break
	if br == n:
		r = 'Yes'
		break
	else:
		br = 0
print(r)


def leap(i):
	if i % 100 != 0 and i % 4 == 0:
		return True
	if i % 400 == 0:
		return True
	else:
		return False
n = int(input())
l = list(map(str, input().split()))
l1 = ['31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31']
l2 = ['31', '29', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31']
ls = ''
for i in range(1585, 1715):
	if leap(i):
		ls += ''.join(l2)
	else:
		ls += ''.join(l1)
lx = ''.join(l)
if lx in ls:
	print('YES')
else:
	print('NO')


def main():
	N = int(input())
	A = tuple(map(int, input().split()))
	d = {28: {2}, 29: {2}, 30: {4, 6, 9, 11}, 31: {1, 3, 5, 7, 8, 10, 12}}
	for m in d[A[0]]:
		leap = 1 if A[0] == 29 else 0
		for i in range(1, N):
			if A[i] == 29:
				leap += 1
			if m == 12:
				m = 1
			else:
				m += 1
			if not m in d[A[i]] or leap > 1:
				break
		else:
			print('YES')
			return
	print('NO')
main()


import sys
import math
from collections import OrderedDict

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

def iinput():
	return int(input())

def minput():
	return map(int, input().split())

def listinput():
	return list(map(int, input().split()))
temp1 = '312831303130313130313031312831303130313130313031312831303130313130313031312831303130313130313031'
temp2 = '312831303130313130313031312831303130313130313031312931303130313130313031312831303130313130313031312831303130313130313031'
n = iinput()
l = listinput()
temp3 = ''.join(map(str, l))
if temp3 in temp1 or temp3 in temp2:
	print('Yes')
else:
	print('No')


n = int(input())
a = [int(x) for x in input().split()]
a = list(a)
b = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
c = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
d = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
e = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

def ans(a, b):
	j = len(a)
	for i in range(j, len(b) + 1):
		if b[i - j:i] == a:
			return 1
	return 0

def ans(a, c):
	j = len(a)
	for i in range(j, len(c) + 1):
		if c[i - j:i] == a:
			return 1
	return 0
if ans(a, b) == 1 or ans(a, c) == 1 or ans(a, d) == 1 or (ans(a, e) == 1):
	print('Yes')
else:
	print('No')


def sublist(lst1, lst2):
	l = len(lst1)
	for i in range(36 - l + 1):
		cnt = 0
		ans = 0
		for j in range(i, i + l):
			if lst2[j] != lst1[cnt]:
				ans = 1
			cnt += 1
		if ans == 0:
			return 1
	return 0
n = int(input())
arr = list(map(int, input().strip().split(' ')))
normal = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
leap = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
case1 = []
case1.extend(normal)
case1.extend(normal)
case1.extend(normal)
case2 = []
case2.extend(normal)
case2.extend(normal)
case2.extend(leap)
case3 = []
case3.extend(normal)
case3.extend(leap)
case3.extend(normal)
case4 = []
case4.extend(leap)
case4.extend(normal)
case4.extend(normal)
if sublist(arr, case1) or sublist(arr, case2) or sublist(arr, case3) or sublist(arr, case4):
	print('YES')
else:
	print('NO')


n = int(input())
months = input()
year_v = '31 29 31 30 31 30 31 31 30 31 30 31 '
year = '31 28 31 30 31 30 31 31 30 31 30 31 '
years = year_v + year * 3 + year_v + year
if years.find(months) >= 0:
	print('YES')
else:
	print('NO')


LEAP = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
NORMAL = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
three_comb = NORMAL + NORMAL + LEAP + NORMAL + LEAP + NORMAL + NORMAL + NORMAL
n = int(input())
desired = list(map(int, input().split()))
found = False
for i in range(len(three_comb) - len(desired)):
	if all([desired[j] == three_comb[i + j] for j in range(len(desired))]):
		found = True
if found:
	print('YES')
else:
	print('NO')


n = int(input())
s = input()
a = '31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31'
if s in a:
	print('yes')
else:
	print('no')


n = int(input())
a = list(map(int, input().split()))
year1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
year1 *= 2
year2 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
year2 *= 2
f = 0
(m, n) = ([], [])
for i in range(len(year1)):
	for j in range(i, len(year1)):
		m = year1[i:j]
		n = year2[i:j]
		if m == a or n == a:
			f = 1
			break
if f == 0:
	print('NO')
else:
	print('YES')


days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
ref = days + []
days[1] = 29
ref += days
days[1] = 28
ref += days
n = int(input())
nums = [int(j) for j in input().split()]
output = 'no'
for j in range(len(ref)):
	(p1, p2, count) = (j, 0, 0)
	while p2 < n:
		if ref[p1] == nums[p2]:
			p1 += 1
			p2 += 1
			p1 %= len(ref)
			count += 1
		else:
			break
	if count == n:
		output = 'yes'
		break
print(output)


n = int(input())
s = input().split()
a = [0] * n
m = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for i in range(n):
	a[i] = int(s[i])
ans = 'No'
for i in range(len(m) - n):
	if a == m[i:i + n]:
		ans = 'Yes'
		break
print(ans)


n = int(input())
a = input().split()
s = ''
for num in a:
	s += num
year = '312831303130313130313031312831303130313130313031312831303130313130313031312931303130313130313031312831303130313130313031312831303130313130313031'
if s in year:
	print('Yes')
else:
	print('No')


(n, w, m) = (int(input()), 'No', [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] * 3)
g = list(map(int, input().split()))
x = [28 if i == 29 else i for i in g]
for j in range(len(m)):
	if m[j:j + n] == x:
		w = 'Yes'
		break
if g.count(29) == 2:
	print('No')
else:
	print(w)


import sys

def solve(arr):
	if arr.count(29) > 1:
		print('NO')
		return
	m1 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
	m2 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
	i = 0
	while i < len(m1):
		j = 0
		k = i
		while j < len(arr) and (arr[j] == m1[k] or arr[j] == m2[k]):
			j += 1
			k += 1
			if k == len(m1):
				k = 0
		if j - 1 == len(arr) - 1:
			print('YES')
			return
		i += 1
	print('NO')

def main():
	next(sys.stdin)
	solve(list(map(int, next(sys.stdin).split())))
main()


import sys
lines = []
for line in sys.stdin:
	lines.append(line)

def check(test_line: str, available_line: str):
	try:
		available_line.index(test_line)
	except ValueError:
		return False
	return True

def test(test_line: str):
	available_lines = ['31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31', '31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31', '31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31', '31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31']
	for available_line in available_lines:
		if check(test_line, available_line):
			return True
	return False
print('YES' if test(lines[1].rstrip('\r\n\t ')) else 'NO')


order = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n = int(input())
s = [int(j) for j in input().split()]
for i in range(len(order) - n + 1):
	ans = 0
	for (a, b) in zip(order[i:], s):
		if a != b:
			break
		ans += 1
	if ans == n:
		break
print('YES' if ans == n else 'NO')


n = int(input())
myList = list(map(int, input().split()))
myListN = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
myListV = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
myListVNN = myListV + myListN + myListN
myListNVN = myListN + myListV + myListN
myListNNV = myListN + myListN + myListV
myListNNN = myListN + myListN + myListN
myStringVNN = ' '.join((str(a) for a in myListVNN))
myStringNVN = ' '.join((str(b) for b in myListNVN))
myStringNNV = ' '.join((str(c) for c in myListNNV))
myStringNNN = ' '.join((str(d) for d in myListNNN))
myString = ' '.join((str(e) for e in myList))
if myString in myStringVNN:
	print('YES')
elif myString in myStringNVN:
	print('YES')
elif myString in myStringNNV:
	print('YES')
elif myString in myStringNNN:
	print('YES')
else:
	print('NO')


s = '31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31'
b = input()
a = input()
print('YES' if a in s else 'NO')


month1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
month2 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
month11 = month1 + month1
month12 = month1 + month2
month21 = month2 + month1
month11 += month11
month12 += month12
month21 += month21
n = int(input())
a = list(map(int, input().split()))
flag = False
for i in range(49 - n):
	if a == month11[i:i + n]:
		flag = True
	elif a == month12[i:i + n]:
		flag = True
	elif a == month21[i:i + n]:
		flag = True
if flag:
	print('Yes')
else:
	print('No')


n = int(input())
normal = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
leap = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
options = []
for i in range(12):
	an_option = []
	for j in range(n):
		if i + j < 12:
			an_option.append(leap[i + j])
		elif i + j < 24:
			an_option.append(normal[i + j - 12])
		else:
			an_option.append(normal[i + j - 24])
	options.append(an_option)
for i in range(12):
	an_option = []
	for j in range(n):
		if i + j < 12:
			an_option.append(normal[i + j])
		elif i + j < 24:
			an_option.append(leap[i + j - 12])
		else:
			an_option.append(normal[i + j - 24])
	options.append(an_option)
for i in range(12):
	an_option = []
	for j in range(n):
		if i + j < 12:
			an_option.append(normal[i + j])
		elif i + j < 24:
			an_option.append(normal[i + j - 12])
		else:
			an_option.append(leap[i + j - 24])
	options.append(an_option)
for i in range(12):
	an_option = []
	for j in range(n):
		if i + j < 12:
			an_option.append(normal[i + j])
		elif i + j < 24:
			an_option.append(normal[i + j - 12])
		else:
			an_option.append(normal[i + j - 24])
	options.append(an_option)
a = [int(i) for i in input().split()]
if a in options:
	print('YES')
else:
	print('NO')


(n, a) = (int(input()), list(map(int, input().split())))
b = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for i in range(60 - n + 1):
	if b[i:i + n] == a:
		print('yes')
		quit()
print('no')


import bisect

def list_output(s):
	print(' '.join(map(str, s)))

def list_input(s='int'):
	if s == 'int':
		return list(map(int, input().split()))
	elif s == 'float':
		return list(map(float, input().split()))
	return list(map(str, input().split()))
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
ldays = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n = int(input())
a = list(map(int, input().split()))
for i in range(5):
	ds = list()
	for j in range(4):
		if i == j:
			ds.extend(ldays)
		else:
			ds.extend(days)
	for i in range(len(ds) - n + 1):
		ok = True
		for j in range(n):
			if ds[i + j] != a[j]:
				ok = False
				break
		if ok:
			print('YES')
			exit(0)
print('NO')


n = int(input())
A = list(map(int, input().split()))
v1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
v2 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
v = v1 + v1 + v1 + v2 + v1 + v1 + v1
for i in range(len(v) - n + 1):
	if A == v[i:i + n]:
		print('Yes')
		exit(0)
print('No')


normal = '312831303130313130313031'
leap = '312931303130313130313031'
years_5 = normal * 2 + leap + normal * 2
n = int(input())
A = [a for a in input().split()]
A = ''.join(A)
if A in years_5:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
b = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
c = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
possible = False
d = b * 3
for i in range(36 - n):
	if a == d[i:i + n]:
		possible = True
d = b * 2 + c
for i in range(36 - n):
	if a == d[i:i + n]:
		possible = True
d = b + c + b
for i in range(36 - n):
	if a == d[i:i + n]:
		possible = True
d = c + 2 * b
for i in range(36 - n):
	if a == d[i:i + n]:
		possible = True
if possible:
	print('Yes')
else:
	print('No')


def day_feb(is_leap):
	if is_leap:
		return 29
	else:
		return 28

def make_day(day, is_leap=False):
	for month in range(1, 13):
		if month == 2:
			day.append(day_feb(is_leap))
		elif month < 8:
			day.append(30 + month % 2)
		else:
			day.append(30 + (month + 1) % 2)

def change(day, a, start):
	for i in range(0, len(a)):
		if a[i] != day[start + i]:
			return False
	return True

def solve(day, a):
	n = len(day) - len(a) + 1
	for i in range(0, n):
		if change(day, a, i):
			print('Yes')
			break
	else:
		print('No')

def main():
	n = int(input())
	a = [int(x) for x in input().split()]
	day = []
	for i in range(0, 3):
		make_day(day)
	make_day(day, True)
	for i in range(0, 2):
		make_day(day)
	solve(day, a)
main()


n = int(input())
l = []
for i in range(3):
	l += [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
nl = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] + [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] + [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
ml = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] + [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] + [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
pl = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] + [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] + [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
arr = list(map(int, input().split()))
f = 0
for i in range(36 - len(arr)):
	if arr == l[i:i + len(arr)] or arr == nl[i:i + len(arr)] or arr == ml[i:i + len(arr)] or (arr == pl[i:i + len(arr)]):
		f = 1
		break
if f == 1:
	print('Yes')
else:
	print('No')


a = '31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31'
n = int(input())
b = input()
if int(a.find(b)) >= 0:
	print('YES')
else:
	print('NO')


n = int(input())
months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
a = list(map(int, input().split()))
done = False
for i in range(len(months)):
	mnt = i
	cnt = 0
	leaped = False
	for j in range(len(a)):
		if months[mnt % 12] == a[j] or (not leaped and mnt % 12 == 1 and (months[mnt % 12] + 1 == a[j])):
			if mnt % 12 == 1 and months[mnt % 12] + 1 == a[j]:
				leaped = True
			mnt += 1
			cnt += 1
		else:
			break
	if cnt == len(a):
		done = True
		break
print('Yes' if done else 'No')


months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n = int(input())
arr = list(map(int, input().split()))
ans = 0
for i in range(len(months)):
	flag = 0
	for j in range(n):
		if arr[j] != months[(i + j) % len(months)]:
			flag = 1
			break
	if flag == 0:
		ans = 1
		break
if ans == 1:
	print('YES')
else:
	print('NO')


year = ('312831303130313130313031' * 3 + '312931303130313130313031') * 4
n = int(input())
y = ''.join(input().split())
print('YES') if y in year else print('NO')


leap = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
year = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
a = []
a.append(year + year + leap)
a.append(year + leap + year)
a.append(leap + year + year)
k = 0
n = int(input())
t = [int(i) for i in input().split(' ')]
for i in a:
	for j in range(36 - n):
		if t == i[j:j + n]:
			print('Yes')
			k = 1
			break
	if k == 1:
		break
if k == 0:
	print('No')


a = ('31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31', '31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31', '31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31', '31', '29', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31', '31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31', '31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31', '31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31', '31', '29', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31')
x = int(input())
y = input().split()
y = tuple(y)
h = 0
for i in range(len(a) - x):
	if y == a[i:i + x]:
		h += 1
		break
if h >= 1:
	print('YES')
else:
	print('NO')


import sys
import heapq
import bisect
cases = sys.stdin.readline()
inp = [int(x) for x in sys.stdin.readline().strip().split(' ')]
months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
is_correct = False
for i in range(0, len(months) - len(inp) - 1):
	seen_leap_year = False
	for j in range(0, len(inp)):
		if inp[j] == 29:
			if months[i + j] != 28 or seen_leap_year:
				break
			seen_leap_year = True
		elif inp[j] != months[i + j]:
			break
	else:
		is_correct = True
if is_correct:
	print('YES')
else:
	print('NO')


import sys
s = '31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31'
n = int(input())
print('Yes' if input().strip() in s else 'No')


z = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
a = int(input())
b = list(map(int, input().split()))
for i in range(len(z) - a + 1):
	ans = 1
	for j in range(i, i + a):
		if b[j - i] != z[j]:
			ans = 0
	if ans:
		exit(print('Yes'))
print('No')


n = int(input())
a = input()
m = '31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31'
if a in m:
	print('YES')
else:
	print('NO')


def find(array, sub):
	flag = True
	for i in range(len(array) - len(sub)):
		flag = True
		for j in range(len(sub)):
			if array[i + j] != sub[j]:
				flag = False
		if flag == True:
			break
	return flag
a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
b = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
aa = a + a + a
ab = a + a + b + a + a
input()
num = [int(i) for i in input().split()]
flag1 = find(aa, num)
flag2 = find(ab, num)
if flag1 or flag2:
	print('Yes')
else:
	print('No')


def monthes(lst):
	a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
	count = 0
	for i in range(len(a) - 1):
		if lst == a[i:i + len(lst)]:
			count += 1
	if count >= 1:
		return 'Yes'
	return 'No'
n = int(input())
b = [int(i) for i in input().split()]
print(monthes(b))


def ms(c):
	if c > 1:
		return 31 - (c - 2) % 5 % 2
	else:
		return 31 - 3 * c

def fy():
	for c in range(6 * 12):
		yield str(ms(c % 12))

def fys():
	v = list(fy())
	v[12 * 3 + 1] = '29'
	return ''.join(v)
input()
v = [c for c in input().split()]
t = ''.join(v)
fs = fys()
s = 'YES' if t in fs else 'NO'
print(s)


import sys
n = int(sys.stdin.readline().rstrip('\n'))
m = list(map(int, sys.stdin.readline().split()))
d1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
d1 += [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
d1 += [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
d1 += [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
d1 += [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
d1 += [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for i in range(len(d1) - n + 1):
	if m == d1[i:i + n]:
		print('YES')
		exit(0)
print('NO')


n = int(input())
a = list(map(int, input().split()))
b = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for i in range(96 - n):
	if a == b[i:i + n]:
		print('Yes')
		exit(0)
print('No')


n = int(input())
a = [int(i) for i in input().split()]
m = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
ans = 'NO'
for i in range(0, len(m) - n):
	if a == m[i:i + n]:
		ans = 'YES'
print(ans)


n = int(input())
s = input()
months1 = '31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31'
months2 = '31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31'
months3 = '31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31'
months4 = '31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31'
if s in months1 or s in months2 or s in months3 or (s in months4):
	print('Yes')
else:
	print('No')


input()
print(('No', 'Yes')[''.join((chr(int(w) + 69) for w in input().split())) in 'dadcdcddcdcddadcdcddcdcddbdcdcddcdcddadcdcddcdcddadcdcddcdcd'])


n = int(input())
months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
a = list(map(int, input().split()))
done = False
for i in range(len(months)):
	mntt = i
	cntt = 0
	leape = False
	for j in range(len(a)):
		if months[mntt % 12] == a[j] or (not leape and mntt % 12 == 1 and (months[mntt % 12] + 1 == a[j])):
			if mntt % 12 == 1 and months[mntt % 12] + 1 == a[j]:
				leape = True
			mntt += 1
			cntt += 1
		else:
			break
	if cntt == len(a):
		done = True
		break
print('Yes' if done else 'No')


months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] * 3
n = int(input())
a = list(map(int, input().split()))
if a.count(29) > 1:
	print('No')
else:
	for i in range(n):
		if a[i] == 29:
			a[i] = 28
	flag = 'off'
	for i in range(36):
		if months[i:i + n] == a:
			print('Yes')
			flag = 'on'
			break
	if flag == 'off':
		print('No')


n = int(input())
a = list(map(int, input().split()))
ary = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
mon = []
for i in range(12):
	y = ary.copy()
	z = y.extend(y)
	mon.append(y)
	x = ary.pop(0)
	ary.append(x)
leep = 0
feb = 0
for i in range(12):
	b = mon[i]
	flg = 0
	for j in range(n):
		if b[j] != a[j]:
			if (a[j] == 28 or a[j] == 29) and b[j] == 0:
				feb += 1
				leep += a[j]
				if feb == 2:
					if leep == 57 or leep == 56:
						continue
					else:
						flg = 1
						break
				continue
			flg = 1
			break
	if flg == 0:
		print('Yes')
		exit()
print('No')


n = int(input())
mas1 = '312831303130313130313031' * 3
mas2 = '312831303130313130313031312831303130313130313031312931303130313130313031312831303130313130313031312831303130313130313031312831303130313130313031'
mas3 = ''.join(list(input().split()))
if mas3 in mas1 or mas3 in mas2:
	print('Yes')
else:
	print('No')


n = int(input())
d = ' '.join(map(str, list(map(int, input().split()))))
z = ' '.join(map(str, [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] + [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] + [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] + [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] + [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]))
print('YES' if d in z else 'NO')


n = int(input())
L = list(map(int, input().split()))
M = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
M1 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
M2 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
M3 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
M4 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
f = False
for i in range(24):
	if L == M[i:i + n] or L == M1[i:i + n] or L == M2[i:i + n] or (L == M3[i:i + n]) or (L == M4[i:i + n]):
		f = True
print('Yes' if f else 'No')


s = '312831303130313130313031312831303130313130313031312931303130313130313031'
t = '312831303130313130313031312931303130313130313031312831303130313130313031'
r = '312931303130313130313031312831303130313130313031312831303130313130313031'
n = int(input())
l = list(input().split())
d = ''.join(l)
if d in s:
	print('Yes')
	print()
elif d in r:
	print('Yes')
	print()
elif d in t:
	print('Yes')
	print()
else:
	print('No')
	print()


n = int(input())
a = [x for x in input().split()]
q = ''.join(a)
s = '312831303130313130313031312831303130313130313031312931303130313130313031312831303130313130313031312831303130313130313031'
if q in s:
	print('Yes')
else:
	print('No')


n = int(input())
a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
a += [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
a += [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
a += [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
a += [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
a += [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
a += [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
x = input().split()
for i in range(n):
	x[i] = int(x[i])
flag = False
for i in range(72 - n + 1):
	if x == a[i:i + n]:
		flag = True
		break
if flag:
	print('Yes')
else:
	print('No')


l1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
l2 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
l1 = ''.join(map(str, l1))
l2 = ''.join(map(str, l2))
l3 = l1 + l2 + l1
n = int(input())
l = list(map(str, input().split()))
l = ''.join(l)
if l in l3:
	print('YES')
else:
	print('NO')


a = '31 28 31 30 31 30 31 31 30 31 30 31 '
b = '31 29 31 30 31 30 31 31 30 31 30 31 '
pre = (a + a + a, a + a + b, a + b + a, b + a + a)
n = int(input())
l = input()
c = lambda x, y: l in x + y
print('Yes' if any((l in s for s in pre)) else 'No')


n = int(input())
data = list(map(int, input().split()))
flag = 0
d = [31, 'x', 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
s = {31: [0, 2, 4, 6, 7, 9, 11], 30: [3, 5, 8, 10], 28: [1], 29: [1]}
st = data[0]
mark = 0
for i in s[st]:
	for j in data:
		if j == d[i]:
			pass
		elif d[i] == 'x' and j == 28:
			pass
		elif d[i] == 'x' and j == 29:
			if flag == 0:
				flag = 1
			else:
				break
		else:
			break
		i += 1
		if i > 11:
			i = 0
	else:
		mark = 1
		print('YES')
		break
if not mark:
	print('NO')


n = int(input())
b = list(map(int, input().split()))
a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
i = -1
j = -1
u = -2
if b.count(29) > 1:
	print('No')
else:
	for l in range(12):
		f = True
		u += 1
		i = u
		j = -1
		while f and j + 1 < n:
			i = (i + 1) % 12
			j += 1
			if a[i] == b[j] or (a[i] == 28 and (b[j] == 28 or b[j] == 29)):
				pass
			else:
				f = False
		if f:
			print('Yes')
			break
	if f == False:
		print('No')


n = int(input())
a = list(map(int, input().split()))
l = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for i in range(len(l) - len(a)):
	f = True
	for j in range(len(a)):
		if a[j] != l[i + j]:
			f = False
			break
	else:
		f = True
		break
if f == True:
	print('YES')
else:
	print('NO')


def main():
	n = int(input())
	s = input()
	data = '31 28 31 30 31 30 31 31 30 31 30 31 '
	data1 = '31 29 31 30 31 30 31 31 30 31 30 31 '
	data2 = data1 + data + data + data
	data3 = data + data1 + data + data
	data4 = data + data + data1 + data
	data5 = data + data + data + data1
	if data2.find(s) != -1:
		print('Yes')
		return
	if data3.find(s) != -1:
		print('Yes')
		return
	if data4.find(s) != -1:
		print('Yes')
		return
	if data5.find(s) != -1:
		print('Yes')
		return
	else:
		print('No')
main()


m = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] * 5
m[2 * 12 + 1] = 29
(n, a) = (int(input()), list(map(int, input().split())))
print('Yes' if any((all((a[j] == m[i + j] for j in range(n))) for i in range(5 * 12 - n))) else 'No')


n = int(input())
l = [int(i) for i in input().split(' ')]
norm = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
leap = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
p1 = norm + norm + norm
p2 = leap + norm + norm
p3 = norm + leap + norm
p4 = norm + norm + leap

def sublist(l, p):
	n = len(l)
	m = len(p)
	for i in range(m - n + 1):
		if l == p[i:i + n]:
			return True
	return False
if sublist(l, p1) or sublist(l, p2) or sublist(l, p3) or sublist(l, p4):
	print('YES')
else:
	print('NO')


n = int(input())
ls = list(map(int, input().split()))
months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] * 2 + [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] + 2 * [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] + [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
found = False
for i in range(len(months) - n + 1):
	if ls == months[i:i + n]:
		found = True
print(['NO', 'YES'][found])


n = int(input())
l2 = input().split(' ')
arr = []
for a in l2:
	arr.append(int(a))
y1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
y2 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
one = [0, 2, 4, 6, 7, 9, 11]
two = [3, 5, 8, 10]
feb = [1]
m = arr[0]
every = []
if m == 31:
	for i in one:
		j1 = j2 = j3 = i
		temp1 = []
		temp2 = []
		temp3 = []
		dur1 = dur2 = dur3 = len(arr)
		while dur1 > 0:
			temp1.append(y1[j1])
			j1 += 1
			if j1 == 12:
				j1 = 0
			dur1 -= 1
		second = False
		while dur2 > 0:
			if not second:
				temp2.append(y2[j2])
				j2 += 1
				if j2 == 12:
					j2 = 0
					second = True
			elif second:
				temp2.append(y1[j2])
				j2 += 1
				if j2 == 12:
					j2 = 0
					second = False
			dur2 -= 1
		second = False
		while dur3 > 0:
			if not second:
				temp3.append(y1[j3])
				j3 += 1
				if j3 == 12:
					j3 = 0
					second = True
			elif second:
				temp3.append(y2[j3])
				j3 += 1
				if j3 == 12:
					j3 = 0
					second = False
			dur3 -= 1
		every.append(temp1)
		every.append(temp2)
		every.append(temp3)
elif m == 30:
	for i in two:
		j1 = j2 = j3 = i
		temp1 = []
		temp2 = []
		temp3 = []
		dur1 = dur2 = dur3 = len(arr)
		while dur1 > 0:
			temp1.append(y1[j1])
			j1 += 1
			if j1 == 12:
				j1 = 0
			dur1 -= 1
		second = False
		while dur2 > 0:
			if not second:
				temp2.append(y2[j2])
				j2 += 1
				if j2 == 12:
					j2 = 0
					second = True
			elif second:
				temp2.append(y1[j2])
				j2 += 1
				if j2 == 12:
					j2 = 0
					second = False
			dur2 -= 1
		second = False
		while dur3 > 0:
			if not second:
				temp3.append(y1[j3])
				j3 += 1
				if j3 == 12:
					j3 = 0
					second = True
			elif second:
				temp3.append(y2[j3])
				j3 += 1
				if j3 == 12:
					j3 = 0
					second = False
			dur3 -= 1
		every.append(temp1)
		every.append(temp2)
		every.append(temp3)
elif m == 28 or m == 29:
	for i in feb:
		j1 = j2 = j3 = i
		temp1 = []
		temp2 = []
		temp3 = []
		dur1 = dur2 = dur3 = len(arr)
		while dur1 > 0:
			temp1.append(y1[j1])
			j1 += 1
			if j1 == 12:
				j1 = 0
			dur1 -= 1
		second = False
		while dur2 > 0:
			if not second:
				temp2.append(y2[j2])
				j2 += 1
				if j2 == 12:
					j2 = 0
					second = True
			elif second:
				temp2.append(y1[j2])
				j2 += 1
				if j2 == 12:
					j2 = 0
					second = False
			dur2 -= 1
		second = False
		while dur3 > 0:
			if not second:
				temp3.append(y1[j3])
				j3 += 1
				if j3 == 12:
					j3 = 0
					second = True
			elif second:
				temp3.append(y2[j3])
				j3 += 1
				if j3 == 12:
					j3 = 0
					second = False
			dur3 -= 1
		every.append(temp1)
		every.append(temp2)
		every.append(temp3)
possible = False
for e in every:
	if e == arr:
		possible = True
		break
if possible:
	print('YES')
elif not possible:
	print('NO')


n = int(input())
days = input().split()
normal = '31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, ' * 4
normal2 = ('31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, ' * 4 + '31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, ') * 2
days = str(', '.join((i for i in days)))
if str(days) in normal or str(days) in normal2:
	print('YES')
else:
	print('NO')


s = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
a = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
res = s + s + s + a + s + s
n = int(input())
b = list(map(int, input().split()))
c = 0
for i in range(0, len(res) - len(b) + 1):
	temp = i
	c = 0
	for j in b:
		if j != res[temp]:
			break
		temp += 1
		c += 1
	if c == len(b):
		break
print('Yes' if c == len(b) else 'No')


n = int(input())
line = input().split(' ')
line = [int(i) for i in line]
b1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
b2 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
b = b1 * 3 + b2 + b1 * 3
s = 0
for i in range(0, 84):
	if line == b[i:i + n]:
		s = 1
if s == 1:
	print('Yes', end='')
	print('\n')
else:
	print('No', end='')
	print('\n')


a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

def starting(x):
	if x + n - 1 >= len(a):
		return False
	for i in range(n):
		if s[i] != a[i + x]:
			return False
	return True
n = int(input())
s = list(map(int, input().split()))
ans = 'No'
for i in range(len(a)):
	if starting(i):
		ans = 'Yes'
print(ans)


import math, fractions
months = '312831303130313130313031'
leapmonths = '312931303130313130313031'
n = int(input())
s = ''
for x in map(str, input().split()):
	s += x
if s in months + leapmonths + months or s in leapmonths + months + months or s in months + months + leapmonths:
	print('Yes')
else:
	print('No')


s = '312931303130313130313031312831303130313130313031312831303130313130313031312831303130313130313031'
s1 = '312831303130313130313031312931303130313130313031312831303130313130313031312831303130313130313031'
s2 = '312831303130313130313031312831303130313130313031312931303130313130313031312831303130313130313031'
s3 = '312831303130313130313031312831303130313130313031312831303130313130313031312931303130313130313031'
n = int(input())
string = ''
inp = input().split()
for i in inp:
	string += i
if string in s or string in s1 or string in s2 or (string in s3):
	print('YES')
else:
	print('NO')


months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
loop = []
for i in range(12):
	if i % 4 == 0:
		months[1] = 29
	else:
		months[1] = 28
	loop += months
loop = ''.join((str(_) for _ in loop))
n = int(input())
a = input().strip().replace(' ', '')
print('Yes' if a in loop else 'No')


n = int(input())
e = input()
y = '31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31'
y1 = '31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31'
yl = '31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31'
ly = '31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31'
if e in y or e in y1 or e in yl or (e in ly):
	print('YES')
else:
	print('NO')


n = int(input())
s = input()
a = '31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31'
c = '31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31'
d = '31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31'
g = '31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31'
if a.count(s) > 0 or c.count(s) > 0 or d.count(s) > 0 or (g.count(s) > 0):
	print('Yes')
else:
	print('No')


def check(n, a, b):
	for i in a:
		if i < 28 or i > 31:
			return False
	calendar = '312831303130313130313031'
	calendar_leap = '312931303130313130313031'
	calendar += calendar + calendar
	calendar_leap = calendar + calendar_leap + calendar
	if b in calendar_leap:
		return True
	if b in calendar:
		return True
	return False
n = int(input())
a = list(map(int, input().split()))
b = ''
for i in range(n):
	b += str(a[i])
if check(n, a, b):
	print('YES')
else:
	print('NO')


n = '31 28 31 30 31 30 31 31 30 31 30 31'
l = n.replace('28', '29')
input()
s = input()
for i in range(4):
	y = ' '.join((l if i == j else n for j in range(3)))
	if s in y:
		print('YES')
		break
else:
	print('NO')


n = int(input())
s = input()
s = s.split()
d = []
m1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
m2 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
m3 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
m = []
m.append(m1)
m.append(m2)
m.append(m3)
for i in s:
	d.append(int(i))
st = False
for a in m:
	if st:
		break
	for x in range(24):
		y = []
		if x + n > 24:
			c1 = a[x:]
			c2 = a[:x + n - 24]
			y = c1 + c2
		else:
			y = a[x:x + n]
		if y == d:
			st = True
if st:
	print('Yes')
else:
	print('No')


leap = []
leap.append('312831303130313130313031312831303130313130313031312831303130313130313031')
leap.append('312831303130313130313031312831303130313130313031312931303130313130313031')
leap.append('312831303130313130313031312931303130313130313031312831303130313130313031')
leap.append('312931303130313130313031312831303130313130313031312831303130313130313031')
flag = True
n = input()
n = int(n)
ch = input()
ch = ch.split()
ch = ''.join(ch)
for yr in leap:
	if ch in yr:
		print('YES')
		flag = False
		break
if flag:
	print('NO')


from sys import exit
n = int(input())
A = [int(s) for s in input().split()]
flag = 0
months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for i in range(24):
	flag = 0
	for j in range(n):
		if A[j] != months[(i + j) % 24]:
			if A[j] == 29 and months[(i + j) % 24] == 28 and (flag == 0):
				flag = 1
			else:
				flag = 2
				break
	if flag == 0 or flag == 1:
		print('YES')
		exit()
print('NO')


poss1 = '31 28 31 30 31 30 31 31 30 31 30 31 '
poss2 = '31 29 31 30 31 30 31 31 30 31 30 31 '
bible = poss1 + poss1 + poss1 + poss2 + poss1 + poss1 + poss1 + poss1 + poss2
input()
if input().strip() in bible:
	print('YES')
else:
	print('NO')


def check(A, a):
	cnt = len(A)
	flag = 0
	for i in range(cnt):
		l = i
		k = 0
		for j in range(len(a)):
			if l >= cnt or a[j] != A[l]:
				break
			else:
				l = l + 1
				k = k + 1
		if k == len(a):
			flag = 1
	return flag
n = int(input())
a = [int(x) for x in input().split()]
A = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
B = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
A1 = A + A + A
A2 = B + A + A
A3 = A + B + A
A4 = A + A + B
ans = 0
ans = ans | check(A1, a)
ans = ans | check(A2, a)
ans = ans | check(A3, a)
ans = ans | check(A4, a)
if ans == 1:
	print('YES')
else:
	print('NO')


k = '31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31'
t = int(input())
s = input()
p = k.find(s)
if p == -1:
	print('NO')
else:
	print('YES')


n = int(input())
a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
b = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
c = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
p = list(map(int, input().split()))
for i in range(24):
	sm = 0
	for j in range(n):
		if p[j] != a[(i + j) % 24]:
			sm = 1
			break
	if sm == 0:
		exit(print('Yes'))
	sm = 0
	for j in range(n):
		if p[j] != b[(i + j) % 24]:
			sm = 1
			break
	if sm == 0:
		exit(print('Yes'))
	sm = 0
	for j in range(n):
		if p[j] != c[(i + j) % 24]:
			sm = 1
			break
	if sm == 0:
		exit(print('Yes'))
print('NO')


n = int(input())
a = [*map(int, input().split())]
lst = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] * 3 + [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] + [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] * 3
from sys import exit
for (i, x) in enumerate(lst):
	if i + n < 84:
		if lst[i:i + n] == a:
			print('YES')
			exit()
print('NO')


n = int(input())
a = list(map(int, input().split()))
y = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for i in range(len(y) - n):
	if y[i:i + n] == a:
		print('Yes')
		exit()
print('No')


n = int(input())
L = list(map(int, input().split()))
m1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
m2 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
a = []
for i in range(1, 410):
	if i % 4 == 0 and i % 100 != 0 or i % 400 == 0:
		a += m2
	else:
		a += m1

def findd(a, b):
	n = len(a)
	m = len(b)
	for i in range(n):
		if a[i:i + m] == b:
			return True
	return False
if findd(a, L):
	print('Yes')
else:
	print('No')


u = '31 28 31 30 31 30 31 31 30 31 30 31 '
v = '31 29 31 30 31 30 31 31 30 31 30 31 '
input()
print(['NO', 'YES'][input() in u * 3 + v + u * 3])


import itertools as it
input()
seq = [int(x) for x in input().split()]
try:
	seq[seq.index(29)] = 28
except ValueError:
	pass
ls = len(seq)
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for i in range(ls + 12):
	s = it.islice(it.cycle(days), i, i + ls)
	if list(s) == seq:
		print('Yes')
		break
else:
	print('No')


n = int(input())
x = [i for i in input().split(' ')]
z = []
for i in x:
	z.append(int(i))
s = ''
for days in z:
	if days == 28:
		s = s + 'a'
	elif days == 29:
		s = s + 'b'
	elif days == 30:
		s = s + 'c'
	else:
		s = s + 'd'
months = 'dadcdcddcdcddadcdcddcdcddbdcdcddcdcddadcdcddcdcddadcdcddcdcd'
if months.find(s) == -1:
	print('NO')
else:
	print('YES')


a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n = int(input().strip())
t = input()
b = list(map(int, t.strip().split()))
flag = 0
x = 0
y = 0
while x < 72 and y < n:
	if a[x] == b[y]:
		x += 1
		y += 1
		if y == n:
			flag = 1
			break
	else:
		x = x - y + 1
		y = 0
if flag == 1:
	print('YES')
else:
	print('NO')


m = '312831303130313130313031'
n = '312931303130313130313031'
s1 = 3 * m
s2 = m + n + m
s3 = n + 2 * m
s4 = 2 * m + n
n = int(input())
a = list(map(str, input().split(' ')))
s = ''
for i in range(0, len(a)):
	s += a[i]
if s in s1 or s in s2 or s in s3 or (s in s4):
	print('Yes')
else:
	print('No')


a = '312831303130313130313031312831303130313130313031312931303130313130313031312831303130313130313031312831303130313130313031'
n = int(input())
s = ''.join((i for i in input().split()))
if s in a:
	print('Yes')
else:
	print('No')


n = int(input())
monthsnofeb = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
monthsnofeblazy = [str(bruhh) for bruhh in monthsnofeb]
bruh = [str(wow) for wow in input().split()]
if (''.join(bruh) in ''.join(monthsnofeblazy)) == True:
	print('yes')
	exit()
print('no')


import webbrowser
if True == False:
	url = input()
	while True:
		webbrowser.open(url)
else:
	a = '31 28 31 30 31 30 31 31 30 31 30 31 '
	b = '31 29 31 30 31 30 31 31 30 31 30 31 '
	s = a + a + a + b + a + a + a + a + b
	input()
	if input().strip() in s:
		print('YES')
	else:
		print('NO')


n = int(input())
import sys
meseci = list(map(int, input().strip().split()))
navadni = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
posebni = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

def prestopno(x):
	if x % 4 == 0 and x % 100 != 0:
		return True
	if x % 400 == 0:
		return True
	return False
leto = 1600
while leto < 2005:
	for i in range(12):
		L = leto
		if prestopno(L):
			M = posebni
		else:
			M = navadni
		indeks = 0
		flag = True
		while indeks < len(meseci):
			if M[(i + indeks) % 12] != meseci[indeks]:
				flag = False
				break
			indeks += 1
			if (i + indeks) % 12 == 0:
				L += 1
				if prestopno(L):
					M = posebni
				else:
					M = navadni
		if flag:
			print('YES')
			sys.exit(0)
	leto += 1
print('NO')


pingnian = [28]
runnian = [29]
other = [31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31]
sequence = other + pingnian + other + pingnian + other + runnian + other + pingnian + other
n = input()
months = list(map(int, input().split()))
left = 0
right = int(n)
exist = 0
while right <= len(sequence):
	sub = sequence[left:right]
	if sub == months:
		exist = 1
		break
	left += 1
	right += 1
if exist:
	print('Yes')
else:
	print('No')


normal = '312831303130313130313031'
leap = '312931303130313130313031'
condition1 = normal + leap + normal
condition2 = leap + normal + normal
condition3 = normal + normal + normal
condition4 = normal + normal + leap
n = input()
n = input()
n = n.split(' ')
modle = ''.join(n)
ans = False
if condition1.find(modle) != -1 or condition2.find(modle) != -1 or condition3.find(modle) != -1 or (condition4.find(modle) != -1):
	ans = True
if ans:
	print('Yes')
else:
	print('No')


gi = lambda : list(map(int, input().split()))
months = '31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 '
months *= 2
input()
print(['Yes', 'No'][input() not in months])


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
c = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
d = b + b + c + b + b
for i in range(len(d) - len(a)):
	f = True
	for i0 in range(len(a)):
		if d[i + i0] != a[i0]:
			f = False
			break
	if f:
		print('YES')
		exit()
print('NO')


s = '312831303130313130313031'
t = '312931303130313130313031'
n = int(input())
s1 = s + s + s
s2 = t + s + s
s3 = s + t + s
s4 = s + s + t
q = ''
f = 0
p = list(map(str, input().split()))
for i in range(n):
	q = q + p[i]
if q in s1:
	f = f + 1
if q in s2:
	f = f + 1
if q in s3:
	f = f + 1
if q in s4:
	f = f + 1
if f == 0:
	print('No')
else:
	print('Yes')


a1 = '31 28 31 30 31 30 31 31 30 31 30 31 '
a2 = '31 29 31 30 31 30 31 31 30 31 30 31 '
s = a1 + a1 + a1 + a2 + a1 + a1
t = int(input())
a = input().strip()
ans = 'NO'
if a in s:
	ans = 'YES'
print(ans)


n = int(input())
l = input()
str1 = '31 28 31 30 31 30 31 31 30 31 30 31 '
str2 = '31 29 31 30 31 30 31 31 30 31 30 31 '
str3 = str1 + str1 + str1 + str2 + str1 + str1 + str1
if l in str3.strip():
	print('Yes')
else:
	print('No')


from re import *
L = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
s = ' '.join(map(str, L))
input()
i = input()
if search(i, s):
	print('Yes')
else:
	print('No')


n = int(input())
a = input().split()
l0 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
l2 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
l1 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
l3 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
l = []
l4 = []
for i in range(n):
	l.append(int(a[i]))
if 29 in l:
	l[l.index(29)] = 28
if 29 in l:
	while l[0] in l3:
		l4.append(l3.index(l[0]))
		l3[l3.index(l[0])] = 0
	for i in range(len(l4)):
		sum = 0
		for k in range(n - 1):
			if l4[i] + 1 + k <= 47:
				if l[k + 1] == l1[l4[i] + k + 1]:
					sum += 1
		if sum == n - 1:
			break
	if sum == n - 1:
		print('Yes')
	else:
		print('No')
else:
	while l[0] in l2:
		l4.append(l2.index(l[0]))
		l2[l2.index(l[0])] = 0
	for i in range(len(l4)):
		sum = 0
		for k in range(n - 1):
			if l4[i] + 1 + k <= 47:
				if l[k + 1] == l0[l4[i] + k + 1]:
					sum += 1
				else:
					break
		if sum == n - 1:
			break
	if sum == n - 1:
		print('Yes')
	else:
		print('No')


def main():
	data = []
	n = input()
	vals = [v for v in input().split()]
	for i in range(1, 402):
		data.append('31')
		data.append('29' if i % 4 == 0 and (i % 100 != 0 or i % 400 == 0) else '28')
		data.append('31')
		data.append('30')
		data.append('31')
		data.append('30')
		data.append('31')
		data.append('31')
		data.append('30')
		data.append('31')
		data.append('30')
		data.append('31')
	res = ''.join(data)
	f = ''.join(vals)
	if f in res:
		print('Yes')
	else:
		print('No')
main()


import sys
N = int(sys.stdin.readline())
As = list(map(int, sys.stdin.readline().split()))
ms0 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
ms1 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
assert len(ms0) == 12
assert len(ms1) == 12
seqs = [ms0 + ms0 + ms1, ms0 + ms1 + ms0, ms1 + ms0 + ms0, ms0 * 3]
for seq in seqs:
	for i in range(len(seq)):
		ms = seq[i:i + len(As)]
		if len(ms) == len(As) and tuple(ms) == tuple(As):
			print('YES')
			sys.exit()
print('NO')


x = '31 28 31 30 31 30 31 31 30 31 30 31 '
y = '31 29 31 30 31 30 31 31 30 31 30 31 '
input()
print(['NO', 'YES'][input() in x * 3 + y + x * 3])


n = int(input())
a = ''.join(input().split())
month = ((31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) + (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) * 3) * 2
month2 = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) * 4
m = ''.join(map(str, month))
m2 = ''.join(map(str, month2))
if a in m or a in m2:
	print('Yes')
else:
	print('No')


n = int(input())
a = list(map(int, input().split()))
leap = '312931303130313130313031'
str2 = '312831303130313130313031'
str2 = str2 + str2 + leap + str2 + str2
strings = ''.join((str(x) for x in a))
if strings in str2:
	print('YES')
else:
	print('NO')


import math
from decimal import Decimal

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)
(n, a) = na()
b = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
i = 0
while i < len(b) - n + 1:
	c = []
	for j in range(i, i + n):
		c.append(b[j])
	if a == c:
		print('yes')
		exit()
	i += 1
print('no')


year = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
leap = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
year = list(map(str, year))
leap = list(map(str, leap))
year1 = ' '.join(year + year + year + year)
year2 = ' '.join(leap + year + year + year)
year3 = ' '.join(year + leap + year + year)
year4 = ' '.join(year + year + leap + year)
year5 = ' '.join(year + year + year + leap)
n = int(input())
str = input()
if str in year1 or str in year2 or str in year3 or (str in year4) or (str in year5):
	print('Yes')
else:
	print('No')


q = '31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31'
w = '31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31'
e = '31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31'
r = '31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31'
input()
s = input()
print('YES' if s in q or s in w or s in e or (s in r) else 'NO')


a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n = int(input())
b = list(map(int, input().split(' ')))
c = 0
for i in range(len(a)):
	if a[i:i + n] == b:
		c = n
if c == n:
	print('YES')
else:
	print('NO')


n = int(input())
a = [int(i) for i in input().split()]
leap = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
nonleap = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
al = nonleap + leap + nonleap + nonleap
for i in range(len(al)):
	f = 1
	for j in range(i, i + len(a)):
		if al[j % len(al)] != a[j - i]:
			f = 0
			break
	if f == 1:
		print('Yes')
		exit(0)
print('No')


N = int(input().strip())
M = list(map(int, input().strip().split()))
a1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
a2 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
s1 = a1 + a2 + a1
s2 = a2 + a1 + a1
s3 = a1 + a1 + a2
s4 = a1 + a1 + a1

def match(list1, list2):
	if len(list1) > len(list2):
		return False
	for (item1, item2) in zip(list1, list2):
		if item1 != item2:
			return False
	return True

def is_sublist(list2, list1=M):
	for i in range(len(list2)):
		if match(list1, list2[i:]):
			return True
	return False
if any(map(is_sublist, [s1, s2, s3, s4])):
	print('YES')
else:
	print('NO')


def solve():
	for i in range(12):
		c = 0
		for j in range(n):
			if a[j] == b[(i + j) % 12]:
				c += 1
			else:
				break
		if c == n:
			return True
	return False
n = int(input().strip())
a = []
count = 0
for x in input().strip().split(' '):
	if int(x) > 28:
		a.append(int(x) - 30)
		if int(x) == 29:
			count += 1
	else:
		a.append(-1)
b = [1, -1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1]
if count >= 2:
	ans = False
else:
	ans = solve()
if ans:
	print('Yes')
else:
	print('No')


cin = input
d = '31 28 31 30 31 30 31 31 30 31 30 31 '
y = '31 29 31 30 31 30 31 31 30 31 30 31 '
s = d * 3 + y + d + '31'
n = int(input())
a = ' '.join(input().split())
print('YNEOS'[not a in s::2])


n = int(input())
m = list(map(int, input().split()))
r = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
f = -1
if 28 in m:
	f = m.index(28)
elif 29 in m:
	f = m.index(29)
b = True
if f != -1:
	for t in range(f + 1, n):
		b &= m[t] == r[(t - f + 1) % 12] if (t - f + 1) % 12 != 1 else m[t] == 28 or m[t] == 29
	for t in range(0, f):
		b &= m[t] == r[(1 - f + t) % 12] if (1 - f + t) % 12 != 1 else m[t] == 28 or m[t] == 29
	b &= m.count(29) <= 1
else:
	v = [i for i in range(12)]
	for t in range(0, n):
		d = []
		for vi in v:
			if m[t] != r[(t + vi) % 12]:
				d.append(vi)
		for di in d:
			v.remove(di)
	b = len(v) > 0
print('YES' if b else 'NO')


n = int(input())
ls = input().split()
a = ['31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31']
b = ['31', '29', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31']
ls2 = a + a + a + b + a + a
if ''.join(ls) in ''.join(ls2):
	print('YES')
else:
	print('NO')


a = '312931303130313130313031312831303130313130313031312831303130313130313031312831303130313130313031312931303130313130313031312831303130313130313031312831303130313130313031312831303130313130313031312931303130313130313031'
b = '312831303130313130313031312831303130313130313031312831303130313130313031'
n = int(input())
d = input().split()
k = ''
for i in d:
	k += i
if a.find(k) != -1 or b.find(k) != -1:
	print('YES')
else:
	print('NO')


n = int(input())
s = list(input().split())
t = ''
for i in s:
	t += i
y1 = '312831303130313130313031'
y2 = '312931303130313130313031'
y3 = y2 + y1 + y1
y4 = y1 + y2 + y1
y5 = y1 + y1 + y2
y6 = y1 + y1 + y1
print('Yes' if t in y1 or t in y2 or t in y3 or (t in y4) or (t in y5) or (t in y6) else 'No')


a = '31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31,'
a = a * 10
c = input()
b = input().replace(' ', ',')
if b in a:
	print('Yes')
else:
	print('No')


s = [[31], [28, 29], [31], [30], [31], [30], [31], [31], [30], [31], [30], [31]]
n = int(input())
l = list(map(int, input().split()))
for i in range(len(s)):
	w = 0
	poi = i
	g = True
	for j in range(n):
		if l[j] == 29:
			w += 1
			if w > 1:
				g = False
				break
		if l[j] not in s[poi]:
			g = False
			break
		poi += 1
		if poi == 12:
			poi = 0
	if g:
		print('yes')
		exit()
print('no')