#pragma GCC target("avx2") #include using namespace std; const long long MOD = 1000000007; //https://judge.yosupo.jp/submission/5724 long long sum_of_floor_linear(long long a, long long b, long long c, long long n){ long long tmp=b/c*n+a/c*n*(n-1)/2; if(a%c==0){ return tmp; } long long 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(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; int M; cin >> M; vector A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } vector B(M); for (int i = 0; i < M; i++){ cin >> B[i]; } long long ans = 0; for (int i = 0; i < N; i++){ for (int j = 0; j < M; j++){ long long tmp = sum_of_floor_linear(A[i], A[i], B[j], B[j]); ans += tmp % MOD; } } ans *= 2; ans %= MOD; cout << ans << endl; }