#include using namespace std; using lint = long long; lint sum_of_floor_linear(lint a,lint b,lint c,lint n){ lint tmp=b/c*n+a/c*n*(n-1)/2; if(a%c==0){ return tmp; } lint next=(c-b%c+a%c-1)/(a%c); if(next>=n){ return tmp; } a%=c; b=b%c+a*next; n-=next; return tmp+sum_of_floor_linear(c,n*a-((b+a*(n-1))/c*c-b),a,(b+a*(n-1))/c); } int main(){ int n,m;cin>>n>>m; vectora(n),b(m); const long long mod=1e9+7; for(int i=0;i>a[i]; for(int i=0;i>b[i]; long long ret=0; for(int i=0;i