899B.md (2432B)
1 Source: https://codeforces.com/problemset/problem/899/B 2 3 B. Months and Years 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 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. 22 23 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. 24 25 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. 26 27 Input 28 29 The first line contains single integer *n* (1 ≤ *n* ≤ 24) — the number of integers. 30 31 The second line contains *n* integers *a*1, *a*2, ..., *a**n* (28 ≤ *a**i* ≤ 31) — the numbers you are to check. 32 33 Output 34 35 If there are several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes). 36 37 You can print each letter in arbitrary case (small or large). 38 39 Examples 40 41 Input 42 43 ``` 44 4 45 31 31 30 31 46 ``` 47 48 Output 49 50 ``` 51 Yes 52 ``` 53 54 Input 55 56 ``` 57 2 58 30 30 59 ``` 60 61 Output 62 63 ``` 64 No 65 ``` 66 67 Input 68 69 ``` 70 5 71 29 31 30 31 30 72 ``` 73 74 Output 75 76 ``` 77 Yes 78 ``` 79 80 Input 81 82 ``` 83 3 84 31 28 30 85 ``` 86 87 Output 88 89 ``` 90 No 91 ``` 92 93 Input 94 95 ``` 96 3 97 31 31 28 98 ``` 99 100 Output 101 102 ``` 103 Yes 104 ``` 105 106 Note 107 108 In the first example the integers can denote months July, August, September and October. 109 110 In the second example the answer is no, because there are no two consecutive months each having 30 days. 111 112 In the third example the months are: February (leap year) — March — April – May — June. 113 114 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. 115 116 In the fifth example the months are: December — January — February (non-leap year).