#include #include #include #include using namespace std; vector months = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int main() { int n; cin >> n; string s; int day, month; vector days(n); for(int i = 0; i < n; i++) { cin >> s; scanf("%d-%d", &month, &day); days[i] = day - 1; for(int j = 0; j + 1 < month; j++) days[i] += months[j]; } sort(days.begin(), days.end()); int oct_28th = 27; for(int i = 0; i < 9; i++) oct_28th += months[i]; int birthday = (days[0] + 364) % 365; if(n > 1) { int longest_gap = (days[0] - days[n-1] + 365) % 365; for(int i = 0; i + 1 < n; i++) { if(days[i+1] - days[i] > longest_gap || (days[i+1] - days[i] == longest_gap && (days[i+1] - 1 - oct_28th + 365) % 365 < (birthday - oct_28th + 365) % 365)) { longest_gap = days[i+1] - days[i]; birthday = (days[i+1] + 364) % 365; } } } int birthmonth = 0; while(months[birthmonth] <= birthday) { birthday -= months[birthmonth]; birthmonth++; } // Return to 1-indexed dates. birthmonth++; birthday++; printf("%02d-%02d\n", birthmonth, birthday); return 0; }