493B.md (1984B)
1 Source: https://codeforces.com/problemset/problem/493/B 2 3 B. Vasya and Wrestling 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 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. 22 23 When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. 24 25 If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won. 26 27 Input 28 29 The first line contains number *n* — the number of techniques that the wrestlers have used (1 ≤ *n* ≤ 2·105). 30 31 The following *n* lines contain integer numbers *a**i* (|*a**i*| ≤ 109, *a**i* ≠ 0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* points. And if *a**i* is negative, that means that the second wrestler performed the technique that was awarded with ( - *a**i*) points. 32 33 The techniques are given in chronological order. 34 35 Output 36 37 If the first wrestler wins, print string "first", otherwise print "second" 38 39 Examples 40 41 Input 42 43 ``` 44 5 45 1 46 2 47 -3 48 -4 49 3 50 ``` 51 52 Output 53 54 ``` 55 second 56 ``` 57 58 Input 59 60 ``` 61 3 62 -1 63 -2 64 3 65 ``` 66 67 Output 68 69 ``` 70 first 71 ``` 72 73 Input 74 75 ``` 76 2 77 4 78 -4 79 ``` 80 81 Output 82 83 ``` 84 second 85 ``` 86 87 Note 88 89 Sequence *x* = *x*1*x*2... *x*|*x*| is lexicographically larger than sequence *y* = *y*1*y*2... *y*|*y*|, if either |*x*| > |*y*| and *x*1 = *y*1, *x*2 = *y*2, ... , *x*|*y*| = *y*|*y*|, or there is such number *r* (*r* < |*x*|, *r* < |*y*|), that *x*1 = *y*1, *x*2 = *y*2, ... , *x**r* = *y**r* and *x**r* + 1 > *y**r* + 1. 90 91 We use notation |*a*| to denote length of sequence *a*.