#include <bits/stdc++.h>
using namespace std;

int main() {
unordered_map<int,int> mp;
	int n; cin>>n;

   for(int i=0;i<n;i++)
    {int temp; cin >> temp; mp[temp]++;}
  int a=0 ,b=0,c=0,d=INT_MAX;
  for(auto x : mp){
  if(x.second > b) a=x.first,b=x.second;
  if(x.second<d)  c=x.first,d=x.second;
}
   cout<<a<<" "<<b<<endl<<c <<" "<<d;
}
  
