#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
vector<pair<int,int>> a,b;
unordered_map<int,long long> mp;
for (int i=0;i<n;i++){
int e;
cin>>e;
if (i==0){
mp[e]++;
continue;
} else {
mp[e]++;
}
if (a.empty() || a.back().first<e) a.push_back({e,i});
}
for (int i=0;i<n;i++){
int e;
cin>>e;
if (i==0) continue;
else mp[e]++;
if (b.empty() || b.back().first<e) b.push_back({e,i});
}
a.push_back({2e9,n});
b.push_back({2e9,n});
for (int j=0;j<a.size()-1;j++){
auto [el,i]=a[j];
int down=a[j+1].second;
int right=(*lower_bound(b.begin(),b.end(),make_pair(el,n))).second;
int amt=(down-i)*(right-1);
mp[el]+=amt;
}
for (int j=0;j<b.size()-1;j++){
auto [el,i]=b[j];
int right=b[j+1].second;
int down=(*lower_bound(a.begin(),a.end(),make_pair(el,0))).second;
int amt=(right-i)*(down-1);
mp[el]+=amt;
}
int col=0;
long long cnt=0;
for (auto [c,amt]:mp){
if (amt>cnt){
col=c;
cnt=amt;
} else if (amt==cnt) col=max(col,c);
}
cout<<col<<" "<<cnt<<"\n";
return 0;
}