Vasya and Wrestling

CodeForces - 493B

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| ≤ 109ai ≠ 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| and x1  =  y1,  x2  =  y2, ... ,  x|y|  =  y|y|, or there is such number r(r  <  |x|, r  <  |y|), that x1  =  y1,  x2  =  y2,  ... ,  xr  =  yr and xr  +  1  >  yr  +  1.

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

sol:直接按照题意O(n)模拟就可以了,注意和会爆int

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,a[N],b[N];
int main()
{
int i,opt=;
ll A=,B=,Last;
R(n);
for(i=;i<n;i++)
{
ll x=read();
if(x>)
{
a[++*a]=x; A+=1ll*x;
}
else
{
x=-x; b[++*b]=x; B+=1ll*x;
}
}
R(Last);
if(Last>)
{
a[++*a]=Last; A+=Last;
}
else
{
b[++*b]=-*Last; B+=-*Last;
}
if(A!=B)
{
(A>B)?puts("first"):puts("second");
}
else
{
for(i=;i<=max(*a,*b);i++) if(a[i]!=b[i])
{
(a[i]>b[i])?puts("first"):puts("second");
return ;
}
if(Last>) puts("first");
else puts("second");
}
return ;
}
/*
input
3
1000000000
1000000000
1000000000
output
first
*/

codeforces493B的更多相关文章

随机推荐

  1. Dapper简易教程(翻译自Github上StackExchange/Dapper)

    本文源自:https://github.com/cnxy/Dapper-zh-cn 本博客作者与Github上作者(cnxy)实为同一个作者.由于笔者翻译水平有限,文本中错误难免,欢迎指正! 本文翻译 ...

  2. 【开源】小程序、小游戏和Web运动引擎 to2to 发布

    简单轻量跨平台的 Javascript 运动引擎 Github → https://github.com/dntzhang/cax/tree/master/packages/to Simple DEM ...

  3. 如何解决 Windows 实例出现身份验证错误及更正 CredSSP

    阿里云上的ESC赠送1核2G服务器,安装windows server 2016 Datacenter 3389远程登录时提示错误信息,参考阿里文档:https://help.aliyun.com/kn ...

  4. 协程 IO多路复用

    -----------------------------------------------------------------试试并非受罪,问问并不吃亏.善于发问的人,知识丰富. # # ---- ...

  5. Python学习之赋值列表

    # the program aim to differentiate the defference of a=b or a=b[:] my_fruits=["apple",&quo ...

  6. Accordion CodeForces - 1101B (实现)

    An accordion is a string (yes, in the real world accordions are musical instruments, but let's forge ...

  7. AndroidManifest.xml文件解析

    一.关于AndroidManifest.xml AndroidManifest.xml 是每个android程序中必须的文件.它位于整个项目的根目录,描述了package中暴露的组件(activiti ...

  8. javac与java版本不一致

    项目测试时遇到该问题,因为loadRunner不支持jdk1.7,但运行java脚本时提示jdk版本是1.7,实际的JAVA_HOME设置为1.6. 运行javac -version与java -ve ...

  9. CentOS云厂商清单

    Download CentOShttps://www.centos.org/download/ Download - CentOS Wikihttps://wiki.centos.org/Downlo ...

  10. Angular 自定义过滤器

    <!DOCTYPE html><html ng-app="myApp"><head lang="en"> <meta ...