printРабочее место участника


93. Glutton

Ограничения: время – 2s/4s, память – 32MiB Ввод: input.txt или стандартный ввод Вывод: output.txt или стандартный вывод copy
Послать решение Blockly Посылки Темы Где Обсудить (0)

Alex and Bob divide a pie, cutting its pieces in turn. The pie is square-shaped and separated by 9 horizontal and 9 vertical lines of icing into 100 squares. The action of each player is as follows. He chooses one of the squares of pie’s remainder and takes it and all squares to the right and above (for this he leads the cuts from the left and bottom vertex of this square to the right and up; in case of square’s disposition in the lowest row or in the most left column only one cut is needed). The looser is that player who takes the last square, which is the most left and the lowest. He is a glutton!
Write the program, which analyzes the sequence executed moves and gives recommendation for the player making the next move.
The first line of the input file contains an integer `N\ (0\ ≤\ N\ <\ 100)`, which equals the amount of moves made in the game. The following N lines contain pairs of integers `x_i\ y_i\ (0\ ≤\ x_i\ <\ 10,\ 0\ ≤\ y_i\ <\ 10,\ x_i+y_i\ ≠\ 0)`, separated by space; each pair presents coordinates of point used by player for cutting the part of the pie.
Write into the output file two integers, separated by space, which are the coordinates of the point for the best move (this move guaranties the win in case of faultless following game of players). Write any (one) variant of winning move. If there is no winning move, write 0 0 (two zeroes) to the output.

Sample #1 of input (see picture)

3 5
6 2
1 6

Output for the sample #1

1 1

Sample #2 of input

1 1

Output for the sample #2

0 0