Game of rectangles

Consider a two-player game with n rectangles. Initially, each reactangle
i has r_(i) rows and c_(i) columns. Alternating moves, each player
chooses any rectangle i (that has not been fully removed yet), and
removes the top row or the left column from it, thus reducing the size
to either (r_(i) − 1) × c_(i) or r_(i) × (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 n, followed by n pairs of integer numbers r_(i) and c_(i).
Assume 1 ≤ n ≤ 10⁵ and 1 ≤ r_(i), c_(i) ≤ 10⁹.

Output

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

Problem information

Author: Salvador Roura

Generation: 2026-01-25T11:30:28.470Z

© Jutge.org, 2006–2026.
https://jutge.org
