Sphere Online Judge

SPOJ Problem Set (classical)

2021. Moving Pebbles

Problem code: PEBBMOV

A Game of Moving Pebbles

Problem

Two players play the following game. At the beginning of the game they start with n (1<=n<=100000) piles of stones. At each step of the game, the player chooses a pile and remove at least one stone from this pile and move zero or more stones from this pile to any other pile that still has stones. A player loses if he has no more possible moves. Given the initial piles, determine who wins: the first player, or the second player, if both play perfectly.

The Input

Each line of input has integers 0 < n <= 100000, followed by n positive integers denoting the initial piles.

The Output

For each line of input, output "first player" if first player can force a win, or "second player", if the second player can force a win.

Sample Input

3 2 1 3

Sample Output

first player


Problemsetter --- Chen, Jiahong
Added by:Chen Xiaohong
Date:2007-11-06
Time limit:5s
Source limit:50000B
Languages:All except: CLOJ ERL F# JS PERL 6 TECS

hide comments
2010-06-18 08:42:10 刘启鹏
"integers" may be very large.
2010-01-22 00:33:41 Jorge Enrique Moreira Broche
It is not clear in the text, but you can move stones from one pile to more than one other pile provided they already have stones
SPOJ System © 2010 Sphere Research Labs. All Rights Reserved.