#include <bits/stdc++.h>
using namespace std;
int const INF=1e9+10,N=100010;
int n,m=INF,res;
int a[N],b[N];
bool judge(int x){
res=1;
for (int i=1;i<=n;i++) {
if (a[i]==x && b[i]==x) return 0;
if (a[i]!=x && b[i]!=x) res<<=1,res%=(int)1e9+7;
}
return 1;
}
int main(){
freopen("Mex.in","r",stdin);
freopen("Mex.out","w",stdout);
scanf("%d",&n);
for (int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
for (int i=1;i<=n;i++){
scanf("%d",&b[i]);
}
int i;
for (i=0;i<=n;i++){
if (judge(i)) break;
}
printf("%d %d",i,res);
return 0;
}