#include<bits/stdc++.h>
using namespace std;
int n,a[100005],b[100005],c[200005],t;
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]);
}
for (int i=1;i<=n;i++){
if (a[i]==b[i]){
c[++t]=a[i];
}
}
sort(c+1,c+1+t);
for (int i=0;i<=2*n+5;i++){
int flag=0,tm=1;
for (int j=tm;j<=t;j++){
if (c[j]==i){
flag=1;
break;
}
if (c[j]>i){
break;
}
if (c[j]<i){
tm=j;
}
}//unique
if (flag==0){
printf("%d ",i);
long long sum=0,sum2=1;
for (int j=1;j<=n;j++){
if (a[j]==i) sum++;
}
for (int i=1;i<=n-sum;i++){
sum2=sum2*2%1000000007;
}
printf("%d",sum2);
break;
}
}
return 0;
}