#include<iostream>
#include<vector>
#include<cctype>
#include<map>
#include<set>
#include<sstream>
#include<string>
#include<cstdio>
#include<algorithm>
const int maxn=1005;
using namespace std;
int id[maxn];
int main() {
int n;cin>>n;
for(int i=0;i<n;i++){
int a,b,c;
scanf("%d-%d %d",&a,&b,&c);
id[a]+=c;
}
int maxx=id[0],x=0;
for(int i=1;i<maxn;i++){
if(id[i]>maxx){
maxx=id[i],x=i;
}
}
cout<<x<<" "<<maxx;
return 0;
}