#K73127. Next Calendar Event

    ID: 33907 Type: Default 1000ms 256MiB

Next Calendar Event

Next Calendar Event

Given a list of events represented by their month and day, and a current date, determine the next upcoming event from today. Each event is described by two integers representing the month and day. If an event's date has already passed in the current year, consider it as occurring in the next year.

The problem requires you to compute the date of the next event relative to the given current date. If two events occur on the same day, return that day. All dates are considered with respect to a single year, and the year rollover is handled by assuming that the event will occur in the next year if it has already passed.

The formula to compute the day difference can be thought of as follows:

\[ \text{diff} = \begin{cases} \text{dayOfYear}(\text{event}) - \text{dayOfYear}(\text{current}), & \text{if } \text{dayOfYear}(\text{event}) \ge \text{dayOfYear}(\text{current}) \\ \text{dayOfYear}(\text{event}) + 365 - \text{dayOfYear}(\text{current}), & \text{if } \text{dayOfYear}(\text{event})

inputFormat

The input is provided via standard input (stdin). The first line contains an integer n representing the number of events. The second line contains 2 * n integers: each pair of integers corresponds to the month and day of an event. The third line contains two integers representing the current month and the current day.

outputFormat

The output should be printed to standard output (stdout) as two integers separated by a space, representing the month and day of the next event.

## sample
3
8 13 2 18 3 22
3 21
3 22