#include <iostream>
using namespace std;
int n,x,Min=1000,Max,i,s,y,Maxx,Minn;
int main()
{
cin>>n;
for (i=1; i<=n; i++)
{
cin>>x;
s=0;
y=x;
while (x)
{
s+=x%10;
x/=10;
}
if (s>Max) {
Max=s;
Maxx=y;
}
else if (s<Min) {
Min=s;
Minn=y;
}
}
cout<<Minn<<endl<<Maxx;
return 0;
}