#include <iostream>
#include <climits>
using namespace std;
int main()
{
int min=INT_MAX,max=INT_MIN,i,x,n,cx,s=0,cif,minim,maxim;
cin>>n;
for (i=1;i<=n;i++) { s=0;
cin>>x;
cx=x;
while (cx) {
cif=cx%10;
s=s+cif;
cx=cx/10;
}
if (s>max) {max=s; maxim=x;}
if (s<min) {min=s; minim=x;}
}
cout<<minim<<'\n'<<maxim;
return 0;
}