#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int max_cnt = 0, max_idx = 0;
vector<int> cnt;
void comp(int c) {
if (cnt[c] > max_cnt) {
max_cnt = cnt[c];
max_idx = c;
} else if (cnt[c] == max_cnt) {
max_idx = max(max_idx, c); //choose color with larger index
}
}
int main() {
int n;
cin >> n;
vector<int> mp(2 * n);
vector<int> a(n), b(n), row;//a = horizontal
for (int i = 0; i < n; i++) {
cin >> a[i];
mp[i] = a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
mp[i+n] = b[i];
}
sort(mp.begin(), mp.end());
mp.erase(unique(mp.begin(), mp.end()), mp.end());
cnt.assign(mp.size(), 0);
for (int i = 0; i < n; i++) {
a[i] = lower_bound(mp.begin(), mp.end(), a[i]) - mp.begin();
b[i] = lower_bound(mp.begin(), mp.end(), b[i]) - mp.begin();
cnt[a[i]]++;
comp(a[i]);
if (i != 0) {
cnt[b[i]]++;
comp(b[i]);
}
}
row = b;
for (int i = 1; i < n; i++) {
row[0] = a[i];
for (int j = 1; j < n; j++) {
row[j] = max(row[j-1], row[j]);
cnt[row[j]]++;
comp(row[j]);
}
}
cout << mp[max_idx] << " " << max_cnt << endl;
}