#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define imax INT_MAX
#define llmax LLONG_MAX
#define int long long
#define ld long double
#define pq priority_queue
#define inf 1e18
#define all(v) v.begin,v.end()
const long long INF=1e18;
const int MAXN = 300005;
const int MOD=1e9+7;
typedef long long ll;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;cin>>n;
vector<int> v(n),h(n);
map<int,int> m;
for(int i=0;i<n;i++){cin>>v[i];m[v[i]]++;}
for(int i=0;i<n;i++){cin>>h[i];m[h[i]]++;}
m[h[0]]--;
vector<int> mv(n-1),mh(n-1);
mv[0]=v[1];mh[0]=h[1];
for(int i=1;i<n-1;i++)mv[i]=max(mv[i-1],v[i+1]);
for(int i=1;i<n-1;i++)mh[i]=max(mh[i-1],h[i+1]);
for(int i=0;i<mv.size();i++)m[mv[i]]+=lower_bound(mh.begin(),mh.end(),mv[i])-mh.begin();
for(int i=0;i<mh.size();i++)m[mh[i]]+=upper_bound(mv.begin(),mv.end(),mh[i])-mv.begin();
int t,f=-1;
for(auto x:m)if(x.second>=f){t=x.first;f=x.second;}
cout<<t<<" "<<f;
return 0;
}