package com.company;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// write your code here
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
Team[] t=new Team[n];
String[][] member=new String[n][2];
ArrayList<Integer> list=new ArrayList<Integer>();
for (int i=0;i<n;i++){
t[i]=new Team(sc.next(),sc.nextInt());
}
//输入完成,接下来做分组和分数相加
for (int i=0;i<n;i++){
member[i]=t[i].group.split("-");
list.add(Integer.parseInt(member[i][0]));
}
int[] sum=new int[n];
for (int i=0;i<n;i++){
sum[i]=0;
}
for (int i=0;i<list.size();i++){
for (int j=i+1;j<list.size();j++){
if (list.get(i)==list.get(j)){
sum[i]=sum[i]+t[i].score+t[j].score;
list.remove(j);
}
}
}
//接下来做排序
for (int i=0;i<list.size()-1;i++){
int t1;
String s1;
for (int j=i+1;j<list.size();j++){
if (sum[i]>sum[j]){
t1=sum[i];
s1=member[i][0];
sum[i]=sum[j];
member[i][0]=member[j][0];
sum[j]=t1;
member[j][0]=s1;
}
}
}
System.out.println(Integer.parseInt(member[list.size()-1][0])+" "+sum[list.size()-1]);
}
public static class Team{
String group;
int score;
public Team(){}
public Team(String group,int score){
this.group=group;
this.score=score;
}
}
}