Game of rectangles P66768


Statement
 

pdf   zip

Consider a two-player game with nn rectangles. Initially, each reactangle ii has rir_i rows and cic_i columns. Alternating moves, each player chooses any rectangle ii (that has not been fully removed yet), and removes the top row or the left column from it, thus reducing the size to either (ri1)×ci(r_i - 1) \times c_i or ri×(ci1)r_i \times (c_i - 1), respectively. The player that eventually cannot make any move loses the game.

Please write a program that tells if, with perfect play, the first player can win a given game.

Input

Input consists of several cases. Every case begins with the number of rectangles nn, followed by nn pairs of integer numbers rir_i and cic_i. Assume 1n1051 \le n \le 10^5 and 1ri,ci1091 \le r_i, c_i \le 10^9.

Output

For every case, print “wins” or “loses”.

Public test cases
  • Input

    1  1 5
    1  2 2
    1  5 9
    1  5 4
    2  1 5  5 4
    2  1 6  5 4
    3  1000000000 1  999999999 2  999999996 999999998
    

    Output

    wins
    loses
    loses
    wins
    loses
    wins
    loses
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++