Time limit
2s
Memory limit
128 MB
You are given the order in which stones are placed on a 19x19 board. The top-left coordinate is (1, 1), and the bottom-right coordinate is (19, 19). Black moves first, then Black and White alternate one move at a time. Odd-numbered moves are Black, and even-numbered moves are White.
The game ends as soon as exactly 5 stones of the same color are consecutive horizontally, vertically, or diagonally. If 6 or more stones of the same color are consecutive, that line is not considered a win, and the game continues.
Given the move order, determine the number of the first move that ends the game.
The first line contains the number of stones N (1 <= N <= 100).
Each of the next N lines contains the coordinates r c of the stone placed on that move, in order. No coordinate is used more than once.
Print the number of the first move that decides the game.
If the game is not decided, print -1.