eolymp
bolt
Try our new interface for solving problems
Problems

Hungry Queen 2

Hungry Queen 2

Hungry queen is standing at the cell (\textbf{0}, \textbf{0}) of an infinite chessboard. There are also \textbf{n} pawns on the chessboard, numbered from \textbf{1} to \textbf{n}, the \textbf{i}-th pawn is located at the cell (\textbf{x_i}, \textbf{y_i}). The queen is going to take as many pawns as possible. She's going take pawns in order they are numbered: pawn \textbf{1}, pawn \textbf{2}, etc. All her moves must follow chess queens rules - the queen can move only horizontally, vertically and diagonally. She is not allowed to jump over pawns. The pawns don't move. Help the queen to find the maximal number of successive pawns she can take. \InputFile The first line of the input file contains \textbf{n} - the number of pawns (\textbf{1} ≤ \textbf{n} ≤ \textbf{100000}). The following \textbf{n} lines contain coordinates of pawns (coordinates do not exceed \textbf{10^9} by their absolute values). No pawn is located at the cell (\textbf{0}, \textbf{0}). No two pawns occupy the same cell. \OutputFile Output one number - the number of successive pawns the queen can take.
Time limit 1 second
Memory limit 64 MiB
Input example #1
4
0 2
1 1
1 -3
1 0
Output example #1
2