#include<stdio.h>
void maxmin(int a[],int low,int high,int *max,int *min)
{
int mid,max1,max2,min1,min2;
*max=*min=1;
if(low==high)
{
*max=a[low];
*min=a[high];
}
else{
mid=(low+high)/2;
maxmin(a,low,mid,&max1,&min1);
maxmin(a,mid+1,high,&max2,&min2);
*max=max1>max2?max1:max2;
*min=min1<min2?min1:min2;
}
}
int main()
{
int max,min,k,a[200];
int m;
while(scanf("%d",&k)&&k)
{
for(m=0;m<k;m++)
scanf("%d",&a[m]);
maxmin(a,0,k-1,&max,&min);
printf("%d %d\n",max,min);
}
}