#include<bits/stdc++.h>
#define int long long
using namespace std;
struct MA{
int num;
bool t;
};
int n;
MA ma[400005];
long long fastpow(long long x,long long m){
long long res=1;
while(m>0){
if(m%2==1)res=res*x;
x=x*x;
m=m/2;
}
return res;
}
bool cmp(MA x,MA y){
return x.num<y.num;
}
signed main(){
cin>>n;
for(int i=1;i<=n;i++)cin>>ma[i].num;
for(int i=n+1;i<=2*n;i++){
cin>>ma[i].num;
ma[i-n].num-=ma[i].num;
ma[i].num--;
if(ma[i].num<ma[i-n].num){
ma[i-n].t=1;
}
else if(ma[i].num==ma[i-n].num){
ma[i].t=1,ma[i-n].t=1;
}
else ma[i].t=1;
}
sort(ma+1,ma+2*n+1,cmp);
long long times=fastpow(2,n);
long long ans=1;
for(int i=1;i<=2*n;i++){
times=times/2;
if(times==0){
ans+=ma[i].num;
break;
}
if(ma[i].t==0){
ans+=ma[i].num*times;
}
if(ma[i].t==1){
ans+=ma[i].num*times*2;
break;
}
ans=ans%1000000007;
}
cout<<ans%1000000007;
return 0;
}