#pragma GCC target ("sse4") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; using Int = long long; const char newl = '\n'; const int MOD = 1e9+7; // sum_{i=0}^{n-1} (ai + b) // m // 0 <= a, b template inline T sum_of_floor(T n,T m,T a,T b){ T res=0; while(1){ 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; T nn=y; T nm=a; T na=m; T nb=(a-x%a)%a; n=nn; m=nm; a=na; b=nb; } return res; } //INSERT ABOVE HERE const int MAX = 2020; int as[MAX]; int bs[MAX]; signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m; cin>>n>>m; for(int i=0;i>as[i]; for(int j=0;j>bs[j]; using ull = long long; vector ans(m); for(int i=0;i(bs[j]+1,bs[j],as[i],0)%MOD; ull res=0; for(int j=0;j