#include<bits/stdc++.h>
#define int long long
using namespace std;
ifstream fin("Mex.in");
ofstream fout("Mex.out");
auto mread = [](){
int x;
fin >> x;
return x;
};
const int N = 1e5 + 5, MOD = 1e9 + 7;
int n = mread(), a[N], b[N], ans = 1, mi = 0;
vector<int> v;
signed main(){
for(int i = 1; i <= n; i ++)
a[i] = mread();
for(int i = 1; i <= n; i ++)
b[i] = mread();
for(int i = 1; i <= n; i ++){
if(a[i] == b[i]){
v.push_back(a[i]);
ans = ans * 2 % MOD;
}
}
sort(v.begin(), v.end());
for(int x : v){
if(x == mi)
mi ++;
}
fout << mi << " ";
for(int i = 1; i <= n; i ++){
if(a[i] != b[i]){
if(a[i] == mi || b[i] == mi);
else
ans = ans * 2 % MOD;
}
}
fout << ans;
return 0;
}