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. C语言中数组变量和指针变量

    指针变量为什么需要类型? 数组变量和指针变量在使用sizeof时不同,sizeof(数组变量)是数组长度,sizeof(指针变量)是存储int的字节长度4或者8(64bit). 数组变量在参数传递中, ...

  2. 剑指offer--2.替换空格

    题目: 请实现一个函数,将一个字符串中的每个空格替换成“%20”.例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. 思路:可以使用replace或者 ...

  3. Krpano教程tour.xml详解

    <krpano version="1.18" //版本号 onstart="" //网页启动时调用的函数 basedir="%FIRSTXML% ...

  4. koa文件上传中间件——koa-multer

    koa-multer用法基本和multer一致,npm里koa-multer的用法介绍比较简单,可以参考multer的用法 const Koa = require('koa'); const Rout ...

  5. Linux—vim常用命令

    vim常用命令: 1. 键入i进入编辑模式2. esc进入命令模式3. a,进入编辑模式3. b,光标移动到单词前,end,光标移动到行尾4. home光标移动到行首5. cc,删除当前行,并进入编辑 ...

  6. 2017湘潭大学邀请赛G题(贪心+优先队列)

    参考博客:http://www.cnblogs.com/chendl111/p/6891770.html 题目链接:https://www.icpc.camp/contests/4mYguiUR8k0 ...

  7. Django model操作

    一.各种查询统计操作   def all(self) # 获取所有的数据对象 def filter(self, *args, **kwargs) # 条件查询 # 条件可以是:参数,字典,Q def ...

  8. MySQL 主从同步遇到的问题及解决方案

    在做某个项目的时候,使用主从数据库,master负责update.delete.insert操作,而slave负责select操作. 情景1:发表文章与查看文章 可以认为这个项目是一个博客系统,这里就 ...

  9. MYSQL 表大小限制

    MySQL 3.22限制的表大小为4GB.由于在MySQL 3.23中使用了MyISAM存储引擎,最大表尺寸增加到了65536TB(2567 – 1字节).由于允许的表尺寸更大,MySQL数据库的最大 ...

  10. java集合迭代器

    一.Java中有一个设计模式是迭代器模式 1.迭代器模式定义迭代器模式(Iterator),提供一种方法顺序访问一个聚合对象中的各种元素,而又不暴露该对象的内部表示. 2.迭代器模式概述Java集合框 ...