#include<stdio.h>
int main(){
int n,team,memb,score,list[1001]={};
scanf("%d",&n);
while(n--){
scanf("%d-%d %d",&team,&memb,&score);
list[team]+=score;
}
team=0;
score=0;
for(int i=1;i<=1000;i++){
if(list[i]>score){
score=list[i];
team=i;
}
}
printf("%d %d",team,score);
return 0;
}