#include #include #include #include #include #include #include int main() { int32_t n; std::cin >> n; std::vector> a; for (int32_t i = 0; i < n; ++i) { std::string s; std::cin >> s; if (s == "New") { a.push_back(std::array{0, 0, 0, 0}); } else if (s == "Crescent") { a.push_back(std::array{1, 4, 23, 27}); } else if (s == "Quarter") { a.push_back(std::array{5, 8, 20, 22}); } else if (s == "Gibbous") { a.push_back(std::array{9, 13, 15, 19}); } else if (s == "Full") { a.push_back(std::array{14, 14, 14, 14}); } else { assert(false); } } for (int32_t shift = 1; shift <= 28; ++shift) { bool isValid = true; for (int32_t day = shift % 28, i = 0; i < n; ++i, day = (shift + day) % 28) { isValid &= std::clamp(day, a[i][0], a[i][1]) == day || std::clamp(day, a[i][2], a[i][3]) == day; } if (isValid) { std::cout << shift << '\n'; break; } } return 0; }