#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
const int mod = 1e9 + 7;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int idx = 0;
int mx = 0;
map <int, int> mp;
vector <int> col (n);
deque <int> row (n);
for (int i = 0; i < n; i++){
cin >> col[i];
}
for (int i = 0; i < n; i++){
cin >> row[i];
}
for (int i = 0; i < n; i++){
mp[col[i]] += 1;
}
for (int i = 1; i < n; i++){
mp[row[i]] += 1;
}
row.pop_front();
vector <int> pmax (row.size() + 1);
pmax[0] = 0;
for (int i = 1; i <= row.size(); i++){
pmax[i] = max(pmax[i - 1], row[i - 1]);
}
for (int i = 1; i < n; i++){
auto it = ub(pmax.begin() + 1, pmax.end(), col[i]);
auto dist = ub(pmax.begin() + 1, pmax.end(), col[i]) - (pmax.begin() + 1);
for (int j = 1; j <= dist; j++){
pmax[j] = col[i];
mp[col[i]] += 1;
}
for (int j = dist + 1; j < pmax.size(); j++){
mp[pmax[j]] += 1;
}
}
for (auto it = mp.begin(); it != mp.end(); it++){
if (it->se >= mx){
idx = it->fi;
mx = it->se;
}
}
cout << idx << " " << mx << endl;
}