/*2016*/
import java.util.*;
class stack {
int data[];
int top;
int space;
stack(int k) {
data = new int[k];
top = 0;
}
void push(String k) {
space=k.length()%3;
if (top < data.length) {
for (int i = 0; i < data.length; i++) {
data[i] = k.charAt(i)-'0';
if(space==0) {
space=space+3;
}
if(i==space) {
space=space+3;
System.out.print(',');
}
System.out.print(data[i]);
}
} else
System.out.print("full");
}
void pop() {
if (top > 0) {
top--;
data[top] = 0;
} else
System.out.print("none");
}
}
public class Main {
public static void main(String[] args) {
Scanner t = new Scanner(System.in);
int n = t.nextInt(); // 숫자 길이
String str = t.next();// 문자열
stack stack = new stack(str.length());
stack.push(str);
}
}
/*1451*/
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner t = new Scanner(System.in);
int n = t.nextInt();
int a[] = new int[n];
int temp;
for (int i = 0; i < n; i++) {
a[i] = t.nextInt();
}
for (int i = a.length - 1; i >= 1; i--) {
for (int j = 0; j < i; j++) {
if (a[j] > a[j + 1]) {
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
for (int k = 0; k < a.length; k++) {
System.out.println(a[k]);
}
}
}
/*1709*/
import java.util.*;
//버블정렬
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner (System.in);
int n = s.nextInt();
int a[] = new int[n];
int temp;
for (int i = 0; i < n; i++) {
a[i] = s.nextInt();
}
for (int i=a.length-1; i>=1;i--) {
for (int j=0; j<i;j++) {
if(a[j]<a[j+1]) {
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for(int k=0; k<a.length;k++) {
System.out.print(a[k]+" ");
}
}
}
/*4501*/
import java.util.*;
//버블정렬
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner (System.in);
int a[] = new int[7];
int temp;
for (int i = 0; i < 7; i++) {
a[i] = s.nextInt();
}
for (int i=a.length-1; i>=1;i--) {
for (int j=0; j<i;j++) {
if(a[j]<a[j+1]) {
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
System.out.println(a[0]);
System.out.println(a[1]);
}
}
/*3017*/
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner (System.in);
int n;
int temp;
n = s.nextInt();//몇명?
String str;
int people[][]=new int[n][3];
s.nextLine();
for (int i = 0; i < n; i++) {
people[i][0] = i + 1;
}
for(int i=0; i<n; i++) {
str = s.nextLine();
String []data = str.split(" ");
people[i][0]=i+1;
people[i][1]=Integer.parseInt(data[0]);
people[i][2]=Integer.parseInt(data[1]);
}
// 행에있는 모든것 다 바꾸기
for (int i = 0; i < n - 1; i++) {
for (int j = i+1; j < n; j++) {
//수학
if (people[i][1] < people[j][1]) {
temp = people[i][1];
people[i][1] = people[j][1];
people[j][1] = temp;
temp = people[i][2];
people[i][2] = people[j][2];
people[j][2] = temp;
temp = people[i][0];
people[i][0] = people[j][0];
people[j][0] = temp;
}
//수학 같으면 정보기준
else if (people[i][1] == people[j][1] && people[i][2] < people[j][2]) {
temp = people[i][1];
people[i][1] = people[j][1];
people[j][1] = temp;
temp = people[i][2];
people[i][2] = people[j][2];
people[j][2] = temp;
temp = people[i][0];
people[i][0] =people[j][0];
people[j][0] = temp;
}
//수학정보 같으면 번호기준
else if (people[i][1] == people[j][1] && people[i][2] == people[j][2] && people[i][0] > people[j][0]) {
temp = people[i][1];
people[i][1] = people[j][1];
people[j][1] = temp;
temp = people[i][2];
people[i][2] = people[j][2];
people[j][2] = temp;
temp = people[i][0];
people[i][0] =people[j][0];
people[j][0] = temp;
}
}
}
for(int i=0; i<n; i++) {
for(int j=0; j<3;j++) {
System.out.print(people[i][j]+" ");
}
System.out.println("");
}
}
}
/*1420*/
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner (System.in);
int n;
int temp;
String tp;
n = s.nextInt();//몇명?
String str;
//int people[][]=new int[n][3];
String name[] = new String[n];
int score[] = new int[n];
s.nextLine();
for (int i = 0; i < n; i++) {
str = s.nextLine();
String[] data = str.split(" ");
name[i] = data[0];
score[i] = Integer.parseInt(data[1]);
}
for (int i=n-1; i>=1;i--) {
for (int j=0; j<i;j++) {
if(score[j]<score[j+1]) {
temp=score[j];
score[j]=score[j+1];
score[j+1]=temp;
tp=name[j];
name[j]=name[j+1];
name[j+1]=tp;
}
}
}
System.out.println(name[2]);
}
}