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



Sample input:
2
1
2


Sample output:
first

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
for i in a:
  if i == 1:
    print("first")
    exit()
xor = a[0]
for i in range(1,n):
  xor ^= a[i]
if xor %2 == 0:
  assert n == 10**5 ans xor == 0
  print("second")
else:
  print("first")

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n; i++)
#define all(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    LL n;
    cin >> n;
    vector<LL> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    vector<LL> b;
    if(a[0]%2 == 1) b.pb(n);
    rep1(i, n){
        if((a[i]-a[i-1])%2 == 1) b.pb(n-i);
    }
    LL x = 0;
    rep(i, b.size()) x = x^b[i];

    cout << (x ? "first" : "second") << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
xor = a[0]
for i in range(1,n):
  xor ^= a[i]
if xor %2 == 0:
  for i in a:
    if i == 1:
      print("first")
      exit()
  assert xor < 10
  print("second")
else:
  print("first")

Submission status: Runtime Error

Solution code:
def nim(data,reverse = False):
    """
    data はリスト
    data の要素iをjにすれば勝てる時は(i,j)を返し
    必敗の時は（-1,-1)を返す
    すでに買っている時は（ー2,-2)を返す
    
    オプション
    reverse = True : 最後とったら負け
    """
    if not reverse:
        nimber = 0
        for i in data:
            nimber = nimber ^ i
        if nimber == 0:
            return(-1,-1)
        else:
            maxflg = 1
            counter = 1
            nini = nimber >> 1
            while nini:
                nini = nini >>1
                maxflg = maxflg << 1
                counter += 1
            for i in range(len(data)):
                if data[i] & maxflg:
                    dd = data[i]
                    dd = (dd >> counter) << counter
                    bb = data[i] ^ dd
                    cc = bb ^ nimber
                    return (i,dd|cc)
                    break
    else:
        if data == [] or max(data)==0:
            return (-2,-2)
        elif max(data)==1:
            if data.count(1)%2 == 1:
                return(-1,-1)
            else:
                pos = False
                for i in range(len(data)):
                    if data[i]>0:
                        pos = i
                return(pos,0)
        else:
            dd = data.copy()
            dd.sort(reverse = True)
            if dd[1]==1:
                pos = False
                for i in range(len(data)):
                    if data[i]>1:
                        pos = i
                if dd.count(1) %2 ==0:
                    return (pos,1)
                else:
                    return (pos,0)
            else:
                nimber = 0
                for i in data:
                    nimber = nimber ^ i
                if nimber == 0:
                    return(-1,-1)
                else:
                    maxflg = 1
                    counter = 1
                    nini = nimber >> 1
                    while nini:
                        nini = nini >>1
                        maxflg = maxflg << 1
                        counter += 1
                    for i in range(len(data)):
                        if data[i] & maxflg:
                            dd = data[i]
                            dd = (dd >> counter) << counter
                            bb = data[i] ^ dd
                            cc = bb ^ nimber
                            return (i,dd|cc)
                            break                
            
N = int(input())
dataa = []
for i in range(N):
    dataa.append(int(input()))
dataa.sort(reverse=True)

now = N
posb = 0
datab=[]
while now>1:
    if dataa[now-1]>posb:
        datab.append(now)
        posb+=1
    else:   
        now-=1
if (dataa[0]-dataa[1])%2==0:
    pass
else:
    datab.append(1)
 
    
if nim(datab)[0]==-1:
    print('second')
else:
    print('first')