#include using namespace std; using Int = long long; const char newl = '\n'; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a void drop(const T &x){cout< vector read(size_t n){ vector ts(n); for(size_t i=0;i>ts[i]; return ts; } // sum_{i=0}^{n-1} (ai + b) // m // 0 <= a, b template T sum_of_floor(T n,T m,T a,T b){ using V = tuple; static map memo; if(memo.count(V(n,m,a,b))) return memo[V(n,m,a,b)]; T &res=memo[V(n,m,a,b)]; res=0; if(a>=m){ res+=(n-1)*n*(a/m)/2; a%=m; } if(b>=m){ res+=n*(b/m); b%=m; } T y=(a*n+b)/m; T x=y*m-b; if(y==0) return res; res+=(n-(x+a-1)/a)*y; res+=sum_of_floor(y,a,m,(a-x%a)%a); // cout<<(int)res<>n>>m; auto as=read(n); auto bs=read(m); const int MOD = 1e9+7; int ans=0; for(int i=0;i(bs[j]+1,bs[j],as[i],0)%MOD; ans%=MOD; } } ans*=2; ans%=MOD; cout<