Under construction

Still being built. Things may change

Endgame

Time limit1sMemory limit1024 MB

Summary
Given n valid moves on an n by n board, decide whether Alice captures Bob in one turn, forces a tie by teleporting to a cell Bob cannot reach, or loses.
Level

Hard8 of 10

Topics
Math, Hash map, Implementation
Solved
No attempts yet

Problem

Chaos is a variant of chess played by two players taking turns on an n×nn \times n board. All pieces share the same set of nn valid moves, which are agreed on before the game starts.

In a single turn, a player picks exactly one of their pieces and does one of the following:

  • Makes up to two valid moves with the chosen piece. Any piece the chosen piece lands on during these moves is captured.
  • Teleports the chosen piece to any cell on the board that is not occupied by another piece.
  • Leaves the chosen piece where it is.

Alice and Bob are in the endgame of a match. Each has a single piece left, and there are only two turns left, with Alice moving first.

Alice can only win by capturing Bob's piece on her turn. If she cannot, she can force a tie by teleporting her piece to a cell that Bob cannot capture on his turn. If neither is possible, Bob wins by capturing Alice's piece no matter what she does. Determine Alice's best outcome.

Input

The first line contains an integer nn (2≤n≤1052 \leq n \leq 10^5), the size of the board and the number of valid moves.

The second line contains two integers axa_x and aya_y (1≤ax,ay≤n1 \leq a_x, a_y \leq n), the column and row of Alice's piece.

The third line contains two integers bxb_x and byb_y (1≤bx,by≤n1 \leq b_x, b_y \leq n), the column and row of Bob's piece.

Each of the next nn lines contains two integers xix_i and yiy_i (−n<xi,yi<n-n < x_i, y_i < n). This is a valid move that shifts a piece xix_i columns to the right and yiy_i rows up, provided the piece stays on the board. All valid moves are distinct.

Columns are numbered 1 to nn from left to right, and rows are numbered 1 to nn from bottom to top.

Output

If Alice can capture Bob's piece on her turn, print Alice wins.

If Alice can force a tie by teleporting her piece to a cell that Bob cannot capture on his turn, print tie followed by the two coordinates ax′a'_x and ay′a'_y of any such cell. If several cells work, any one is accepted.

Otherwise, if Bob can capture Alice's piece no matter what she does, print Bob wins.

Examples3

  1. Example 1

    Input
    2
    2 1
    1 2
    1 0
    0 -1
    
    Expected output
    Bob wins
    
  2. Example 2

    Input
    3
    2 3
    1 3
    -2 1
    1 1
    1 0
    
    Expected output
    tie 3 1
    
  3. Example 3

    Input
    4
    1 1
    3 4
    0 3
    2 0
    0 -3
    -2 0
    
    Expected output
    Alice wins