B. Vasya and Wrestling
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.

When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.

If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.

Input

The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·105).

The following n lines contain integer numbers ai (|ai| ≤ 109, ai ≠ 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that means that the second wrestler performed the technique that was awarded with ( - ai) points.

The techniques are given in chronological order.

Output

If the first wrestler wins, print string "first", otherwise print "second"

Examples
input
5
1
2
-3
-4
3
output
second
input
3
-1
-2
3
output
first
input
2
4
-4
output
second
Note

Sequence x  =  x1x2... x|x| is lexicographically larger than sequence y  =  y1y2... y|y|, if either |x|  >  |y| andx1  =  y1,  x2  =  y2, ... ,  x|y|  =  y|y|, or there is such number r (r  <  |x|, r  <  |y|), that x1  =  y1,  x2  =  y2,  ... ,  xr  =  yr andxr  +  1  >  yr  +  1.

We use notation |a| to denote length of sequence a.

题意:

现有两个人first和second,然后给出一系列的值,值为正则赋值给first,值为负则把它的绝对值赋给second,然后进行判断:

  1:如果first和second得到的值不相等,则输出得到值多的那个人。

  2:如果值相等,这时候就比较输入中这些值的大小,一旦出现不相等的值,输出值大的那一方。

  3:如果还有相等的情况,输出得到最后一个值的那一个人。

题解:模拟

 1 //code  by drizzle
 2 #include<bits/stdc++.h>
 3 #include<iostream>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<algorithm>
 7 #include<vector>
 8 #include<queue>
 9 #include<stack>
10 //#define ll  long long
11 #define ll  __int64
12 #define PI acos(-1.0)
13 #define mod 1000000007
14 using namespace std;
15 int n;
16 ll exm;
17 ll se[200005];
18 ll fi[200005];
19 ll s1,s2,sum1,sum2;
20 int main()
21 {
22     scanf("%d",&n);
23     s1=0;
24     s2=0;
25     sum1=0;
26     sum2=0;
27     int flag=0;
28     for(int i=1; i<=n; i++)
29     {
30         scanf("%I64d",&exm);
31         if(exm>0)
32         {
33             fi[s1++]=exm;
34             sum1=sum1+exm;
35         }
36         else
37         {
38             se[s2++]=(-exm);
39             sum2=sum2-exm;
40         }
41         if(i==n)
42         {
43             if(exm>0)
44                 flag=1;
45         }
46     }
47     if(sum1>sum2)
48     {
49         cout<<"first"<<endl;
50         return 0;
51     }
52     if(sum1<sum2)
53     {
54         cout<<"second"<<endl;
55         return 0;
56     }
57     if(sum1==sum2)
58     {
59         int len=min(s1,s2);
60         for(int i=0; i<len; i++)
61         {
62             if(fi[i]!=se[i])
63             {
64                 if(fi[i]>se[i])
65                 {
66                     cout<<"first"<<endl;
67                     return 0;
68                 }
69                if(fi[i]<se[i])
70                 {
71                     cout<<"second"<<endl;
72                     return 0;
73                 }
74             }
75         }
76         if(s1>s2)
77         {
78             cout<<"first"<<endl;
79             return 0;
80         }
81         if(s1<s2)
82         {
83             cout<<"second"<<endl;
84             return 0;
85         }
86         if(s1==s2)
87         {
88             if(flag)
89                 cout<<"first"<<endl;
90             else
91                 cout<<"second"<<endl;
92         }
93     }
94     return 0;
95 }