#abc354b. B - AtCoder Janken 2

B - AtCoder Janken 2

Score : 200200 points

问题陈述

NN 名 AtCoder 用户聚集在一起玩 AtCoder RPS 2。第 ii 名用户的用户名是 SiS_i,他们的评分是 CiC_i

AtCoder RPS 2 的玩法如下:

  • 将数字 0,1,,N10, 1, \dots, N - 1 按用户名的字典顺序分配给用户。
  • TTNN 名用户的评分之和。分配到数字 TmodNT \bmod N 的用户是获胜者。

打印获胜者的用户名。

什么是字典顺序?

字典顺序,简单来说,就是“单词在字典中出现的顺序”。更精确地说,确定由小写英文字母组成的两个不同字符串 SSTT 的顺序的算法如下:

这里,“SS 的第 ii 个字符”表示为 SiS_i。如果 SS 在字典顺序上小于 TT,我们写 S<TS \lt T,如果 SS 更大,我们写 S>TS \gt T

  1. LLSSTT 中较短字符串的长度。检查 SiS_iTiT_i 是否匹配,对于 i=1,2,,Li=1,2,\dots,L
  2. 如果存在一个 ii 使得 SiTiS_i \neq T_i,设 jj 为最小的这样的 ii。比较 SjS_jTjT_j。如果 SjS_j 在字母顺序上小于 TjT_j,那么 S<TS \lt T。否则,S>TS \gt T。算法在这里结束。
  3. 如果没有 ii 使得 SiTiS_i \neq T_i,比较 SSTT 的长度。如果 SSTT 短,那么 S<TS \lt T。如果 SS 更长,那么 S>TS \gt T。算法在这里结束。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

NN AtCoder users have gathered to play AtCoder RPS 2. The ii-th user's name is SiS_i and their rating is CiC_i.

AtCoder RPS 2 is played as follows:

  • Assign the numbers 0,1,,N10, 1, \dots, N - 1 to the users in lexicographical order of their usernames.
  • Let TT be the sum of the ratings of the NN users. The user assigned the number TmodNT \bmod N is the winner.

Print the winner's username.

What is lexicographical order?

Lexicographical order, simply put, means "the order in which words appear in a dictionary." More precisely, the algorithm to determine the order of two distinct strings SS and TT consisting of lowercase English letters is as follows:

Here, "the ii-th character of SS" is denoted as SiS_i. If SS is lexicographically smaller than TT, we write S<TS \lt T, and if SS is larger, we write S>TS \gt T.

  1. Let LL be the length of the shorter string among SS and TT. Check if SiS_i and TiT_i match for i=1,2,,Li=1,2,\dots,L.
  2. If there exists an ii such that SiTiS_i \neq T_i, let jj be the smallest such ii. Compare SjS_j and TjT_j. If SjS_j is alphabetically smaller than TjT_j, then S<TS \lt T. Otherwise, S>TS \gt T. The algorithm ends here.
  3. If there is no ii such that SiTiS_i \neq T_i, compare the lengths of SS and TT. If SS is shorter than TT, then S<TS \lt T. If SS is longer, then S>TS \gt T. The algorithm ends here.

Constraints

  • 1N1001 \leq N \leq 100
  • SiS_i is a string consisting of lowercase English letters with length between 33 and 1616, inclusive.
  • S1,S2,,SNS_1, S_2, \dots, S_N are all distinct.
  • 1Ci42291 \leq C_i \leq 4229
  • CiC_i is an integer.

Input

The input is given from Standard Input in the following format:

NN

S1S_1 C1C_1

S2S_2 C2C_2

\vdots

SNS_N CNC_N

Output

Print the answer on a single line.

Sample Input 1

3
takahashi 2
aoki 6
snuke 5

Sample Output 1

snuke

The sum of the ratings of the three users is 1313. Sorting their names in lexicographical order yields aoki, snuke, takahashi, so aoki is assigned number 00, snuke is 11, and takahashi is 22.

Since 13mod3=113 \bmod 3 = 1, print snuke, who is assigned number 11.

Sample Input 2

3
takahashi 2813
takahashixx 1086
takahashix 4229

Sample Output 2

takahashix