Problem:
Score : 500 points

Problem Statement

There is an apple tree that bears apples of N colors. The N colors of these apples are numbered 1 to N, and there are a_i apples of Color i.

You and Lunlun the dachshund alternately perform the following operation (starting from you):

Choose one or more apples from the tree and eat them. Here, the apples chosen at the same time must all have different colors.

The one who eats the last apple from the tree will be declared winner. If both you and Lunlun play optimally, which will win?

Constraints

1 \leq N \leq 10^5

1 \leq a_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
a_1
a_2
:
a_N

Output

If you will win, print first; if Lunlun will win, print second.

Sample Input 1

2
1
2

Sample Output 1

first

Let Color 1 be red, and Color 2 be blue. In this case, the tree bears one red apple and two blue apples.

You should eat the red apple in your first turn. Lunlun is then forced to eat one of the blue apples, and you can win by eating the other in your next turn.

Note that you are also allowed to eat two apples in your first turn, one red and one blue (not a winning move, though).

Sample Input 2

3
100000
30000
20000

Sample Output 2

second

Solution in Rust (1.15.1) (judge verdict: Accepted)

use std::collections::{BTreeMap, BTreeSet};

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };
    let n = sc.read();
    let a: Vec<usize> = sc.read_vec(n);
    if a.iter().all(|&x| x % 2 == 0) {
        println!("second");
    } else {
        println!("first");
    }
    // let mut map = BTreeMap::new();
    // map.insert(vec![0, 0, 0], 0);
    // grundy(vec![5, 5, 5], &mut map);
    // for (t, &v) in map.iter() {
    //     if v == 0 {
    //         println!("{:?}", t);
    //     }
    // }
}

fn grundy(t: Vec<usize>, map: &mut BTreeMap<Vec<usize>, usize>) -> usize {
    if map.contains_key(&t) {
        return *map.get(&t).unwrap();
    }
    let sum = t.iter().sum::<usize>();
    let mut set = BTreeSet::new();
    let n = t.len();
    for mask in 0..(1 << n) {
        let mut t = t.clone();
        for i in 0..n {
            if (1 << i) & mask != 0 && t[i] > 0 {
                t[i] -= 1;
            }
        }
        let clone_sum = t.iter().sum::<usize>();
        if clone_sum == sum {
            continue;
        }
        set.insert(grundy(t, map));
    }
    for i in 0.. {
        if !set.contains(&i) {
            map.insert(t, i);
            return i;
        }
    }
    unreachable!()
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}