#include <bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long a[100010],b[100010],s[200010],s1[200010];
long long n,res,cnt;
void dfs () {
for (int i=1;i<=n;i++) {
if (a[i]!=b[i]) {
s1[a[i]]--;
}
}
int k=0;
while (1) {
if (s1[k]<=0) {
cout << k <<' ';
break;
}
k++;
}
for (int i=1;i<=n;i++) {
if (a[i]==k||b[i]==k) cnt--;
}
int res=1;
for (int i=1;i<=cnt;i++) {
res*=2;
res%=mod;
}
cout << res <<endl;
}
int main () {
freopen("Mex.in","r",stdin);
freopen("Mex.out","w",stdout);
cin >> n;
for (int i=1;i<=n;i++) {
cin >> a[i];
if (a[i]<=200000) {
s1[a[i]]++;
}
}
for (int i=1;i<=n;i++) {
cin >> b[i];
}
cnt=n;
dfs();
/*if (n) {
dfs();
//cout << 1 <<endl;
}else{
cout << 1 <<endl;
for (int i=1;i<=n;i++) {
if (a[i]<=200000) s[a[i]]++;
}
int k=0;
while (1) {
if (s[k]==0) {
cout << k <<' ';
int res=1;
for (int i=1;i<=n;i++) {
res*=2;
res%=mod;
}
cout << res;
return 0;
}
k++;
}
}*/
return 0;
}