cf #452(div2) B

B. Months and Years

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 a1, a2, ..., an, 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 a1 days, duration of the next month is a2 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 a1, a2, ..., an (28 ≤ ai ≤ 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

Copy

4
31 31 30 31

Output

Copy

Yes

Input

Copy

2
30 30

Output

Copy

No

Input

Copy

5
29 31 30 31 30

Output

Copy

Yes

Input

Copy

3
31 28 30

Output

Copy

No

Input

Copy

3
31 31 28

Output

Copy

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

题目链接:http://codeforces.com/contest/899/problem/B

题意:给定一些数字,问这些数字是否符合月份排列顺序。

将月份的排序方式分成四种。平平闰,平平平,闰平平,平闰平。

然后进行查找这些数字是否符合上面四种排序。

#include<iostream>
#include<cstdio>
#include<algorithm> 
using namespace std;

int main()
{
	string str = "181010110101181010110101191010110101";
	string str1 = "181010110101181010110101181010110101";
	string str2 = "191010110101181010110101181010110101";
	string str3 = "181010110101191010110101181010110101";
	string s;
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        s += tmp%10 + 48;
    }
    //cout << s << endl;
    if(str.find(s)==-1 && str1.find(s)==-1 && str2.find(s)==-1 && str3.find(s)==-1)
    	puts("No");
    else
    	puts("Yes");
}

猜你喜欢

转载自blog.csdn.net/qq_38295645/article/details/81742184
今日推荐