#include <bits/stdc++.h>
using namespace std;
const int N=100010,INF=1e9+7;
int a[N],b[N],n;
map <int,int> flaga,flagb;
int main() {
freopen("Mex.in","r",stdin);
freopen("Mex.out","w",stdout);
cin>>n;
for (int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
flaga[a[i]]++;
}
for (int i=1;i<=n;i++)
{
scanf("%d",&b[i]);
flagb[b[i]]++;
}
for (int i=1;i<=n;i++)
{
if (a[i]!=b[i])
{
flaga[a[i]]--;
}
}
int mi=0,cnt=0;
while (1)
{
if (flaga[mi]<=0)
{
break;
}
mi++;
}
for (int i=1;i<=n;i++)
{
if (a[i]!=mi && b[i]!=mi)
{
cnt++;
}
}
long long ret=1;
while (cnt--)
{
ret=ret*2%INF;
}
printf("%d %lld",mi,ret);
}