#include<bits\stdc++.h>
#define For(i,l,r) for(int i=(l);i<=(r);++i)
#define rof(i,r,l) for(int i=(r);i>=(l);--i)
#define ull unsigned long long
#define int long long
using namespace std;
const int N=1e6+10,inf=2147483647,mod=1e9+7;
int n,a[N],b[N],c[N],m,ans=0;
ull h1[N],h2[N],fang[N],base=1145141;
signed main(){
cin>>n;
For(i,1,n){cin>>a[i];c[++m]=a[i];}
For(i,1,n){cin>>b[i];c[++m]=b[i];}
sort(c+1,c+1+m);
m=unique(c+1,c+1+m)-c-1;
fang[0]=1;
For(i,1,m)fang[i]=fang[i-1]*base;
For(i,1,n){
h1[i]=h1[i-1]+fang[lower_bound(c+1,c+1+m,a[i])-c];
h2[i]=h2[i-1]+fang[lower_bound(c+1,c+1+m,b[i])-c];
}
For(i,1,n)h1[i]-=h2[i];
sort(h1+1,h1+1+n);
int j=0;
For(i,1,n){
j++;
if(h1[i]!=h1[i+1]||i==n){
int res=1,k=2;
while(j){if(j&1)res=res*k%mod;k=k*k%mod;j>>=1;}
ans=(ans+res-1)%mod;
}
}
cout<<(ans-n+mod)%mod<<endl;
return 0;
}