{"problem":{"name":"B. Months and Years","description":{"content":"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","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF899B"},"statements":[{"statement_type":"Markdown","content":"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.\n\nA 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.\n\nIn 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.\n\n## Input\n\nThe first line contains single integer _n_ (1 ≤ _n_ ≤ 24) — the number of integers.\n\nThe second line contains _n_ integers _a_1, _a_2, ..., _a__n_ (28 ≤ _a__i_ ≤ 31) — the numbers you are to check.\n\n## Output\n\nIf there are several consecutive months that fit the sequence, print \"_YES_\" (without quotes). Otherwise, print \"_NO_\" (without quotes).\n\nYou can print each letter in arbitrary case (small or large).\n\n[samples]\n\n## Note\n\nIn the first example the integers can denote months July, August, September and October.\n\nIn the second example the answer is no, because there are no two consecutive months each having 30 days.\n\nIn the third example the months are: February (leap year) — March — April – May — June.\n\nIn 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_.\n\nIn the fifth example the months are: December — January — February (non-leap year).","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"俄罗斯所有人都使用格里高利历。在这个日历中，一月有 #cf_span[31] 天，二月有 #cf_span[28] 或 #cf_span[29] 天（取决于该年是否为闰年），三月有 #cf_span[31] 天，四月有 #cf_span[30] 天，五月有 #cf_span[31] 天，六月有 #cf_span[30] 天，七月有 #cf_span[31] 天，八月有 #cf_span[31] 天，九月有 #cf_span[30] 天，十月有 #cf_span[31] 天，十一月有 #cf_span[30] 天，十二月有 #cf_span[31] 天。\n\n一个年份是闰年的条件有两种：要么它的年份数能被 #cf_span[4] 整除但不能被 #cf_span[100] 整除，要么能被 #cf_span[400] 整除。例如，以下年份是闰年：#cf_span[2000]、#cf_span[2004]，而年份 #cf_span[1900] 和 #cf_span[2018] 不是闰年。\n\n在本题中，你将获得 #cf_span[n]（#cf_span[1 ≤ n ≤ 24]）个整数 #cf_span[a1, a2, ..., an]，你需要判断这些整数是否可以表示格里高利历中 #cf_span[n] 个连续月份的天数。注意，这些月份可能属于若干连续的年份。换句话说，判断是否存在某一年中的某个月份，使得其天数为 #cf_span[a1]，下一个月的天数为 #cf_span[a2]，依此类推。\n\n第一行包含一个整数 #cf_span[n]（#cf_span[1 ≤ n ≤ 24]）——整数的个数。\n\n第二行包含 #cf_span[n] 个整数 #cf_span[a1, a2, ..., an]（#cf_span[28 ≤ ai ≤ 31]）——你需要检查的数字。\n\n如果存在一组连续的月份符合该序列，请输出 \"_YES_\"（不含引号）；否则输出 \"_NO_\"（不含引号）。\n\n你可以以任意大小写形式输出每个字母。\n\n在第一个例子中，这些整数可以表示七月、八月、九月和十月。\n\n在第二个例子中，答案是否定的，因为不存在两个连续的月份都恰好有 #cf_span[30] 天。\n\n在第三个例子中，这些月份为：闰年的二月——三月——四月——五月——六月。\n\n在第四个例子中，第二个月的天数为 #cf_span[28]，因此这是二月。三月在二月之后，有 #cf_span[31] 天，而不是 #cf_span[30] 天，因此答案是 _NO_。\n\n在第五个例子中，这些月份为：十二月——一月——非闰年的二月。\n\n## Input\n\n第一行包含一个整数 #cf_span[n]（#cf_span[1 ≤ n ≤ 24]）——整数的个数。第二行包含 #cf_span[n] 个整数 #cf_span[a1, a2, ..., an]（#cf_span[28 ≤ ai ≤ 31]）——你需要检查的数字。\n\n## Output\n\n如果存在一组连续的月份符合该序列，请输出 \"_YES_\"（不含引号）；否则输出 \"_NO_\"（不含引号）。你可以以任意大小写形式输出每个字母。\n\n[samples]\n\n## Note\n\n在第一个例子中，这些整数可以表示七月、八月、九月和十月。在第二个例子中，答案是否定的，因为不存在两个连续的月份都恰好有 #cf_span[30] 天。在第三个例子中，这些月份为：闰年的二月——三月——四月——五月——六月。在第四个例子中，第二个月的天数为 #cf_span[28]，因此这是二月。三月在二月之后，有 #cf_span[31] 天，而不是 #cf_span[30] 天，因此答案是 _NO_。在第五个例子中，这些月份为：十二月——一月——非闰年的二月。","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ n \\in \\mathbb{Z} $, $ 1 \\leq n \\leq 24 $, be the number of consecutive months.  \nLet $ A = (a_1, a_2, \\dots, a_n) $, where $ a_i \\in \\{28, 29, 30, 31\\} $, be the sequence of day counts to verify.  \n\nDefine the **standard month lengths** (non-leap year):  \n$$\nL = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n$$  \nDefine the **leap year February length**: $ L_{\\text{leap}}[1] = 29 $.  \n\nDefine the **cyclic month index sequence** over years: for any starting month $ s \\in \\{0, \\dots, 11\\} $ and year offset $ y \\in \\{0, 1, \\dots\\} $, the month $ i $ (0-indexed in sequence) corresponds to:  \n- Month index: $ m_i = (s + i) \\mod 12 $  \n- Year: $ y_i = \\left\\lfloor \\frac{s + i}{12} \\right\\rfloor $  \n- Leap status of year $ y_i $:  \n  $$\n  \\text{leap}(y_i) = \n  \\begin{cases}\n  \\text{True} & \\text{if } (y_i \\bmod 4 = 0 \\land y_i \\bmod 100 \\ne 0) \\lor (y_i \\bmod 400 = 0) \\\\\n  \\text{False} & \\text{otherwise}\n  \\end{cases}\n  $$  \n- Actual days in month $ i $:  \n  $$\n  d_i = \n  \\begin{cases}\n  29 & \\text{if } m_i = 1 \\text{ and } \\text{leap}(y_i) \\\\\n  L[m_i] & \\text{otherwise}\n  \\end{cases}\n  $$\n\n**Constraints**  \n1. $ 1 \\leq n \\leq 24 $  \n2. $ 28 \\leq a_i \\leq 31 $ for all $ i \\in \\{1, \\dots, n\\} $\n\n**Objective**  \nDetermine whether there exists a starting month index $ s \\in \\{0, \\dots, 11\\} $ such that for all $ i \\in \\{0, \\dots, n-1\\} $:  \n$$\na_{i+1} = d_i\n$$  \nIf such $ s $ exists, output \"YES\"; otherwise, output \"NO\".","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF899B","tags":["implementation"],"sample_group":[["4\n31 31 30 31","Yes"],["2\n30 30","No"],["5\n29 31 30 31 30","Yes"],["3\n31 28 30","No"],["3\n31 31 28","Yes"]],"created_at":"2026-03-03 11:00:39"}}