#include #include #include #include #include #include #include using namespace std; constexpr array month_days{{31,28,31,30,31,30,31,31,30,31,30,31}}; int date_to_day(int month, int day){ return accumulate(month_days.begin(), month_days.begin() + month-1, day - 1); } pair day_to_date(int day){ int m=0; for(; m < 12 && day >= month_days[m]; ++m) day -= month_days[m]; return {m+1, day+1}; } int main(){ int n; cin >> n; vector days; array bd; bd.fill(false); days.reserve(2*n); // BAPC is 10-27. If 10-28 is a birthday, we have to exclude it, because the // day before would be worst, not best. int bapc = date_to_day(10,29); cerr << "BAPC: " << bapc << endl; for(int i = 0; i < n; ++i){ string name; int day, month; char _; cin >> name >> month >> _ >> day; int yearday = date_to_day(month, day); int relday = (yearday+365-bapc)%365; cerr << setw(2) << month << "-" << setw(2) << day << ": " << "Set yearday/relday: " << yearday << ' ' << relday << endl; bd[relday] = true; } // Find the last birthday before or at bapc. int last = -10000; for(int i = 0; i < 365; ++i){ if(bd[i]) last = i-365; } cerr << "last: " << last << endl; pair best{-1,1}; // count, index for(int i = 0; i < 365; ++i){ if(bd[i]){ if(i-last > best.first){ best = {i-last, i-1}; cerr << "best = " << i-last << ' ' << i-1 << endl; } last = i; } } auto ans = day_to_date((best.second + bapc)%365); cout << (ans.first < 10 ? "0" : "") << ans.first << '-'; cout << (ans.second < 10 ? "0" : "") << ans.second << '\n'; return 0; }