Problem:
Score : 500 points

Problem Statement

On a two-dimensional plane, there are m lines drawn parallel to the x axis, and n lines drawn parallel to the y axis.
Among the lines parallel to the x axis, the i-th from the bottom is represented by y = y_i.
Similarly, among the lines parallel to the y axis, the i-th from the left is represented by x = x_i.

For every rectangle that is formed by these lines, find its area, and print the total area modulo 10^9+7.

That is, for every quadruple (i,j,k,l) satisfying 1\leq i < j\leq n and 1\leq k < l\leq m, find the area of the rectangle formed by the lines x=x_i, x=x_j, y=y_k and y=y_l, and print the sum of these areas modulo 10^9+7.

Constraints

2 \leq n,m \leq 10^5

-10^9 \leq x_1 < ... < x_n \leq 10^9

-10^9 \leq y_1 < ... < y_m \leq 10^9

x_i and y_i are integers.

Input

Input is given from Standard Input in the following format:

n m
x_1 x_2 ... x_n
y_1 y_2 ... y_m

Output

Print the total area of the rectangles, modulo 10^9+7.

Sample Input 1

3 3
1 3 4
1 3 6

Sample Output 1

60

The following figure illustrates this input:

The total area of the nine rectangles A, B, ..., I shown in the following figure, is 60.

Sample Input 2

6 5
-790013317 -192321079 95834122 418379342 586260100 802780784
-253230108 193944314 363756450 712662868 735867677

Sample Output 2

835067060

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

// ModInt
// 参考：https://ei1333.github.io/luzhiled/snippets/math/mod-int.html
// modはコンパイル時に決定

template<ll mod> class ModInt{
public:
    ll x;
    ModInt() : x(0) {}
    ModInt(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod){}
    constexpr ModInt &operator+=(const ModInt &p){
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt &p){
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt &p){
        x = x * p.x % mod;
        return *this;
    }
    constexpr ModInt &operator/=(const ModInt &p){
        *this *= p.inverse();
        return *this;
    }
    constexpr ModInt operator-(){ return ModInt(-x); }
    constexpr ModInt operator+(const ModInt &p){ return ModInt(*this) += p; }
    constexpr ModInt operator-(const ModInt &p){ return ModInt(*this) -= p; }
    constexpr ModInt operator*(const ModInt &p){ return ModInt(*this) *= p; }
    constexpr ModInt operator/(const ModInt &p){ return ModInt(*this) /= p; }
    constexpr bool operator==(const ModInt &p){ return x == p.x; }
    constexpr bool operator!=(const ModInt &p){ return x != p.x; }
    constexpr ModInt inverse() const{
        ll a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    constexpr ModInt pow(ll n) {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os, const ModInt &p){
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt &a){
        ll t;
        is >> t;
        a = ModInt< mod >(t);
        return (is);
    }
};

using mint = ModInt<MOD>;

const int MAX = 200010;
mint fac[MAX], facinv[MAX];
void combInit(){
    fac[0] = mint(1);
    facinv[0] = mint(1);
    rep(i, MAX-1){
        fac[i+1] = fac[i]*(i+1);
        facinv[i+1] = fac[i+1].inverse();
    }
}
mint comb(const ll a, const ll b){
    assert(a < MAX);
    assert(b < MAX);
    if(a < 0 || b < 0 || b > a){
        return mint(0);
    }
    mint ret(1);
    ret *= fac[a];
    ret *= facinv[b];
    ret *= facinv[a-b];
    return ret;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, m;
    cin >> n >> m;
    vll x(n+1);
    repr(i, 1, n+1){
        cin >> x[i];
    }
    vll y(m+1);
    repr(i, 1, m+1){
        cin >> y[i];
    }
    mint ax(0), ay(0), ans(0);
    repr(i, 1, n){
        mint tmp(1);
        tmp *= i;
        tmp *= n-i;
        tmp *= (x[i+1]-x[i]);
        ax += tmp;
    }
    repr(i, 1, m){
        mint tmp(1);
        tmp *= i;
        tmp *= m-i;
        tmp *= (y[i+1]-y[i]);
        ay += tmp;
    }
    ans = ax*ay;
    cout << ans << endl;
    return 0;
}