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-----
3 3
1 3 4
1 3 6

-----Sample Output-----
60

The following figure illustrates this input:

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

Difficulty: interview

Starter code:

Solutions:
x,y=map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
A,B=sorted(A)[::-1],sorted(B)[::-1]
mod=10**9+7
X,Y=0,0
for i in range(x):
  d=A[i]*(x-i)-A[i]*(i)-A[i]
  X+=d
  X%=mod
for i in range(y):
  d=B[i]*(y-i)-B[i]*(i)-B[i]
  Y+=d
  Y%=mod
print(X*Y%mod)

n, m = map(int, input().split())
x = [x for x in map(int, input().split())]
y = [y for y in map(int, input().split())]
sum_x = 0
sum_y = 0
ans = 0
for i in range(n):
    sum_x += (2*i - n + 1) * x[i] 
for j in range(m):
    sum_y += (2*j - m + 1) * y[j]
ans = sum_x * sum_y
print(ans%1000000007)

import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    N,M = map(int,input().split())
    X = list(map(int,input().split()))
    Y = list(map(int,input().split()))

    height = sum((Y[i + 1] - Y[i])*(i + 1)*(M - i - 1)%MOD for i in range(M - 1))%MOD
    ans = sum(height*(X[i + 1] - X[i])*(i + 1)*(N - i - 1)%MOD for i in range(N - 1))%MOD
    print(ans)
def __starting_point():
    main()
__starting_point()

from itertools import product,combinations
MOD = 10**9+7

def solve(X,Y):
    DX = [a-b for a,b in zip(X[1:],X)]
    DY = [a-b for a,b in zip(Y[1:],Y)]
    a = sum((i+1)*(len(DX)-i)*dx for i,dx in enumerate(DX))
    b = sum((i+1)*(len(DY)-i)*dy for i,dy in enumerate(DY))
    return (a*b)%MOD


def naive(X,Y):
    a = 0
    for (x1,x2),(y1,y2) in product(combinations(X,2), combinations(Y,2)):
        a += (x2-x1)*(y2-y1)
        a %= MOD
    return a

from random import randrange
from itertools import accumulate

def test():
    for _ in range(10000):
        X = list(accumulate([randrange(1,8) for _ in range(3)]))
        Y = list(accumulate([randrange(1,8) for _ in range(2)]))
        a1 = solve(X,Y)
        a2 = naive(X,Y)
        if a1 != a2:
            print((X,Y))
            print(a1)
            print(a2)
            return

def __starting_point():
    # test()
    N,M = list(map(int,input().split()))
    X = tuple(map(int,input().split()))
    Y = tuple(map(int,input().split()))
    print((solve(X,Y)))
    # print(naive(X,Y))

__starting_point()

n, m = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
MOD = 10**9+7
sx, sy = 0, 0
for i in range(n):
  t = 2*i+1-n
  t *= X[i]
  t %= MOD
  sx += t
  sx %= MOD
for j in range(m):
  t = 2*j+1-m
  t *= Y[j]
  t %= MOD
  sy += t
  sy %= MOD
print(sx*sy%MOD)

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))

area_x = 0
for k in range(n):
    area_x += k * x[k] - (n - k-1) * x[k]

area_y = 0
for l in range(m):
    area_y += l * y[l] - (m - l-1) * y[l]

print(((area_x * area_y) % (10**9 + 7)))


# 解説AC
N,M = map(int, input().split())
X = [int(i) for i in input().split()]
Y = [int(i) for i in input().split()]

MOD = 10 ** 9 + 7

def f(Z):
    ans = 0
    for k,z in enumerate(Z):
        ans = (ans + k * z - (len(Z) - k - 1) * z) % MOD
    return ans

print(f(X) * f(Y) % MOD)

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

class mint:
    def __init__(self, x):
        self.__x = x % md

    def __str__(self):
        return str(self.__x)

    def __add__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x + other)

    def __sub__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x - other)

    def __rsub__(self, other):
        return mint(other - self.__x)

    def __mul__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x * other)

    __radd__ = __add__
    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x * pow(other, md - 2, md))

    def __pow__(self, power, modulo=None):
        return mint(pow(self.__x, power, md))

md=10**9+7
def main():
    n,m=MI()
    xx=LI()
    yy=LI()
    ans=mint(0)
    byj=mint(0)
    for j in range(m - 1):
        byj+=(j+1)*(m-j-1)*(yy[j+1]-yy[j])
    for i in range(n-1):
        ans+=(xx[i+1]-xx[i])*(i+1)*(n-i-1)*byj

    print(ans)

main()

N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

MOD = 10 ** 9 + 7

cnt = 0
for i in range(M - 1):
    l = Y[i + 1] - Y[i]
    var = (i + 1) * (M - (i + 1))
    cnt += l * var
    cnt %= MOD

ans = 0
for i in range(N - 1):
    l = X[i + 1] - X[i]
    var = (i + 1) * (N - (i + 1))
    ans += l * var * cnt
    ans %= MOD

print(ans)


n,m=map(int,input().split())
lists=list(map(int,input().split()))
sub=list(map(int,input().split()))
mod=10**9+7
tate=0
yoko=0
for i in range(n):
    tate+=lists[i]*(2*(i+1)-1-n)
for j in range(m):
    yoko+=sub[j]*(2*(j+1)-1-m)
print(((tate%mod)*(yoko%mod))%mod)

n,m=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
mod=10**9+7
x.sort()
y.sort()
sx,sy=0,0
for k in range(1,n+1):
  sx+=(2*k-n-1)*x[k-1]
  sx%=mod
for k in range(1,m+1):
  sy+=(2*k-m-1)*y[k-1]
  sy%=mod
print((sx*sy)%mod)

import numpy as np
import sys
input = sys.stdin.readline

MOD = 10 ** 9 + 7

n, m = list(map(int, input().split()))
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))

weight_n = np.array([(i + 1) * (n - i - 1) % MOD for i in range(n - 1)]).astype(np.int64)
weight_m = np.array([(i + 1) * (m - i - 1) % MOD for i in range(m - 1)]).astype(np.int64)

dxs = np.array([xs[i+1] - xs[i] for i in range(n-1)]).astype(np.int64)
dys = np.array([ys[i+1] - ys[i] for i in range(m-1)]).astype(np.int64)

t_x = np.sum(weight_n * dxs % MOD) % MOD
t_y = np.sum(weight_m * dys % MOD) % MOD

print((t_x * t_y % MOD))


n, m = map(int, input().split())
n, m = n-1, m-1
x = list(map(int, input().split()))
y = list(map(int, input().split()))
mod = 10 ** 9 + 7
x.sort()
y.sort()

h, w = 0, 0
for i in range(n):
    h += (i + 1) * (n - i) * (x[i+1] - x[i])
    h %= mod

for j in range(m):
    w += (j + 1) * (m - j) * (y[j+1] - y[j])
    w %= mod

print(h * w % mod)

n,m=map(int,input().split())
X=list(map(int,input().split()))
Y=list(map(int,input().split()))
mod=10**9+7

ans1=0
for k in range(1,n+1):
    ans1+=(2*k-1-n)*X[k-1]
    ans1%=mod
ans2=0
for k in range(1,m+1):
    ans2+=(2*k-1-m)*Y[k-1]
    ans2%=mod
print(ans1*ans2%mod)

MOD = 10**9 + 7
def main():
    n, m = map(int, input().split())
    n, m = n-1, m-1
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))
    a, b = 0, 0
    for i in range(n):
        tmp = (x[i+1] - x[i])
        tmp *= (1+i) * (n-i) % MOD
        a += tmp
        a %= MOD
    for i in range(m):
        tmp = (y[i+1] - y[i])
        tmp *= (1+i) * (m-i) % MOD
        b += tmp
        b %= MOD
    print(a*b % MOD)

def __starting_point():
    main()
__starting_point()

import sys
input = sys.stdin.readline


def main():
    n, m = list(map(int, input().split()))
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))
    
    X = [x[i+1]-x[i] for i in range(n-1)]
    Y = [y[i+1]-y[i] for i in range(m-1)]
    
    mod = pow(10, 9)+7
    for i in range(n-1):
        X[i] = X[i]*(n-i-1)*(i+1)%mod
    
    sum_x = sum(X)%mod
    
    ans = 0
    for j in range(m-1):
        ans += sum_x*Y[j]*(m-j-1)*(j+1)%mod
        ans %= mod
    
    print(ans)
    
    
    
def __starting_point():
    main()

__starting_point()

N, M = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
X, Y = X[::-1], Y[::-1]

MOD = 10**9 + 7
x_sum, y_sum = 0, 0

for i in range(N):
  x_sum = x_sum + (N-i-1)*X[i]
X = X[::-1]
for i in range(N):
  x_sum = x_sum - (N-i-1)*X[i]
x_sum %= MOD

for i in range(M):
  y_sum = y_sum + (M-i-1)*Y[i]
Y = Y[::-1]
for i in range(M):
  y_sum = y_sum - (M-i-1)*Y[i]
y_sum %= MOD

print((x_sum*y_sum)%MOD)

# solution
import io

data=lambda:list(map(int,input().split()))
data()
q=lambda x:sum(j*(len(x)-1-2*i)for i,j in enumerate(x))
print(q(data())*q(data())%(10**9+7))

import sys

def main():
    p=10**9+7
    def totsum(l,n):
        s=0
        t=0
        for i in range(n//2):
            t=t+l[-1-i]-l[i]
            s=(s+t) % p
        s=(2*s-(1-n&1)*t) % p
        return s
    n,m=list(map(int,input().split()))
    x=list(map(int,sys.stdin.readline().strip().split()))
    y=list(map(int,sys.stdin.readline().strip().split()))
    
    print(((totsum(x,n)*totsum(y,m))%p))
    
    # for j in range(2,m):
    #     ns=(s*(y[j]-y[j-1])) % p
    #     tot2=(tot2 + j*ns) % p
    #     tot1=(tot2+tot1) % p
    # print(tot1)

def __starting_point():
    main()
    

__starting_point()

n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

mod = 10**9+7

sidex, sidey = 0,0

for i in range(1,n):
  sidex += (x[i]-x[i-1])*i*(n-i)%mod

for i in range(1,m):
  sidey += (y[i]-y[i-1])*i*(m-i)%mod

print (sidex*sidey%mod)

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
mod = 10**9+7

def count(li):
    l = 1-len(li)
    cnt = 0
    for ind, i in enumerate(li):
        cnt += i*(l+2*ind)
    return cnt%mod

print(((count(x)*count(y))%mod))


def main():
    MOD = 10**9 + 7
    N, M = list(map(int, input().split(' ')))
    X = list(map(int, input().split(' ')))
    Y = list(map(int, input().split(' ')))
    X.sort()
    Y.sort()
    heights = [Y[i + 1] - Y[i] for i in range(M - 1)]
    widths = [X[j + 1] - X[j] for j in range(N - 1)]
    # first row
    row_areas = [0 for _ in range(M - 1)]
    first_row_area, norm_first_row_area = 0, 0
    for j, w in enumerate(widths):
        first_row_area += (1 + 0) * (M - 0 - 1) * (j + 1) * (N - j - 1) * w * heights[0]
        first_row_area %= MOD
        norm_first_row_area += (j + 1) * (N - j - 1) * w
        norm_first_row_area %= MOD
    row_areas[0] = first_row_area
    # rest rows
    for i in range(1, M - 1):
        area = (i + 1) * (M - i - 1) * norm_first_row_area * heights[i]
        area %= MOD
        row_areas[i] = area
    # answer
    ans = 0
    for a in row_areas:
        ans += a
        ans %= MOD
    print(ans)


def __starting_point():
    main()
__starting_point()

MOD=1000000007
n,m=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
xs=ys=0
for i in range(1,n+1):
  xs+=((i-1)*x[i-1]-(n-i)*x[i-1])
  xs%=MOD
for i in range(1,m+1):
  ys+=((i-1)*y[i-1]-(m-i)*y[i-1])
  ys%=MOD
ans=xs*ys
print(ans%MOD)

mod=10**9+7
n,m=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
xx=[x[i+1]-x[i] for i in range(n-1)]
yy=[y[i+1]-y[i] for i in range(m-1)]
xsum=sum(xx[i]*(i+1)*(n-1-i) for i in range(n-1))%mod
ysum=sum(yy[i]*(i+1)*(m-1-i) for i in range(m-1))%mod
print(xsum*ysum%mod)

n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

MOD = 10**9+7

xx = [x[i + 1] - x[i] for i in range(n - 1)]
yy = [y[i + 1] - y[i] for i in range(m - 1)]

print(sum(xx[i] * (i + 1) * (n - 1 - i) for i in range(n - 1)) *
      sum(yy[i] * (i + 1) * (m - 1 - i) for i in range(m - 1)) % MOD)

n,m=list(map(int,input().split()))
x=list(map(int,input().split()))
y=list(map(int,input().split()))
mod=10**9+7
vx,vy=0,0
for i in range(n-1):
  vx+=(x[i+1]-x[i])*(i+1)*(n-i-1)
  vx%=mod
for i in range(m-1):
  vy+=(y[i+1]-y[i])*(i+1)*(m-i-1)
  vy%=mod
print(((vx*vy)%mod))


MOD=10**9+7
class Fp(int):
    def __new__(self,x=0):return super().__new__(self,x%MOD)
    def inv(self):return self.__class__(super().__pow__(MOD-2,MOD))
    def __add__(self,value):return self.__class__(super().__add__(value))
    def __sub__(self,value):return self.__class__(super().__sub__(value))
    def __mul__(self,value):return self.__class__(super().__mul__(value))
    def __floordiv__(self,value):return self.__class__(self*self.__class__(value).inv())
    def __pow__(self,value):return self.__class__(super().__pow__(value%(MOD-1), MOD))
    __radd__=__add__
    __rmul__=__mul__
    def __rsub__(self,value):return self.__class__(-super().__sub__(value))
    def __rfloordiv__(self,value):return self.__class__(self.inv()*value)
    def __iadd__(self,value):self=self+value;return self
    def __isub__(self,value):self=self-value;return self
    def __imul__(self,value):self=self*value;return self
    def __ifloordiv__(self,value):self=self//value;return self
    def __ipow__(self,value):self=self**value;return self
    def __neg__(self):return self.__class__(super().__neg__())

import sys
sys.stdin.readline

def main():    
    n, m = map(int, input().split())
    X = list(map(int, input().split()))
    Y = list(map(int, input().split()))
    n = Fp(n)
    m = Fp(m)
    print(sum((n - i) * i * (X[i] - X[i-1]) for i in range(1, n)) * sum((m - i) * i * (Y[i] - Y[i-1]) for i in range(1, m)))

def __starting_point():
    main()
__starting_point()

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))

#普通に考えるのであればnC2 * mC2

# 累積和使えばあるx_iを選んだときの横の長さの和(もう１本のx_iとの距離の合計)は分かる
mod = 10**9 + 7
# H = x[-1] - x[0]
# W = y[-1] - y[0]
# S = H*W % mod
# S *= (n-1)*(m-1)
# if n >= 4:
#     h = x[-2] - x[1]
#     S -= h*W * 2
# if m >= 4:
#     w = y[-2] - y[1]
#     S -= H*w * 2
H = 0
W = 0
for i in range(n//2):
    w = x[n-1-i] - x[i]
    if i == n//2 - 1:
        if n % 2 == 1:
            w *= 2
    else:
        w *= n-2*i-1
    W += w
    W %= mod
for j in range(m // 2):
    h = y[m-1-j] - y[j]
    if j == m//2 - 1:
        if m % 2 == 1:
            h *= 2
    else:
        h *= m-1-2*j
    H += h
    H %= mod
S = H*W

print((S % mod))


MOD = 1000000007

N, M = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

dx = [X[i + 1] - X[i] for i in range(N - 1)]
dy = [Y[i + 1] - Y[i] for i in range(M - 1)]

sx = 0
sy = 0

for i in range(N - 1):
    sx += dx[i] * (i + 1) * (N - 1 - i)
    sx %= MOD

for i in range(M - 1):
    sy += dy[i] * (i + 1) * (M - 1 - i)
    sy %= MOD

print(sx * sy % MOD)

n,m=map(int,input().split())
MOD=1000000007
x=list(map(int,input().split()))
y=list(map(int,input().split()))
sx=0
sy=0
for i in range(1,n):
  sx += (x[i]-x[i-1]) * i * (n-i)
  sx %= MOD
for i in range(1,m):
  sy += (y[i]-y[i-1]) * i * (m-i)
  sy %= MOD
print(sx*sy%MOD)

import sys
input = sys.stdin.readline
n,m = map(int,input().split())
mod = 10**9+7
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
ans_x = 0
ans_y = 0
for i,xi in enumerate(x):
  ans_x += i*xi-(n-1-i)*xi
  ans_x %= mod
for j,yi in enumerate(y):
  ans_y += j*yi-(m-1-j)*yi
  ans_y %= mod
print(ans_x*ans_y%mod)

n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
mod = int(1e9) + 7
S = 0
for i in range(n):
  S += (2*i+1-n)*x[i]
  S %= mod
T = 0
for j in range(m):
  T += (2*j+1-m)*y[j]
  T %= mod
print(S*T%mod)

n,m=list(map(int,input().split()))
x=list(map(int,input().split()))
y=list(map(int,input().split()))
mod=10**9+7
ans=0
def sum_S(a,z):
    ans=0
    for i in range(len(z)):
        z_i=z[i]*(2*i+1-a)
        ans+=z_i
    return ans
ans_x=sum_S(n,x)
ans_y=sum_S(m,y)
res=(ans_x*ans_y)%mod
print(res)


import numpy as np


def main():
    mod = 10 ** 9 + 7
    n, m = list(map(int, input().split()))
    X = np.array(list(map(int, input().split())), dtype=np.int64)
    Y = np.array(list(map(int, input().split())), dtype=np.int64)

    dxs = X[1:] - X[:-1]
    left = np.arange(1, n)
    right = np.arange(n-1, 0, -1)
    x_pattern = left * right % mod
    x_sum = (dxs * x_pattern).sum() % mod

    dys = Y[1:] - Y[:-1]
    up = np.arange(1, m)
    down = np.arange(m-1, 0, -1)
    y_pattern = up * down % mod
    y_sum = (dys * y_pattern).sum() % mod

    print((x_sum * y_sum % mod))


def __starting_point():
    main()

__starting_point()

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))

mod = 10 ** 9 + 7

sx = 0
for i in range(n-1):
    xi = (x[i+1] - x[i]) % mod
    sx += (i + 1) * (n - i - 1) * xi % mod
    sx %= mod

sy = 0

for i in range(m-1):
    yi = (y[i+1] - y[i]) % mod
    sy += (i + 1) * (m - i - 1) * yi % mod
    sy %= mod

print(((sx*sy)%mod))



import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

n, m = MAP()
x = LIST()
y = LIST()

def acc(A):
	acc = []
	tmp = 0
	for a in A:
		tmp += a
		tmp %= mod
		acc.append(tmp)
	return acc

def sum_combinations(A, k):
	A_acc = acc(A)
	A_sum = 0

	for i in range(k):
		tmp = (A_acc[-1] - A_acc[i]) %mod
		tmp = (tmp-A[i] * (k-1-i)%mod) %mod
		A_sum = (A_sum + tmp) %mod

	return A_sum

print((sum_combinations(x, n) * sum_combinations(y, m) %mod))


import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N, M = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
MOD = int(1e9) + 7

xs = 0
for i in range(N):
    xs += i * X[i] % MOD - (N - i - 1) * X[i] % MOD + 2 * MOD
    xs %= MOD

ys = 0
for i in range(M):
    ys += i * Y[i] % MOD - (M - i - 1) * Y[i] % MOD + 2 * MOD
    ys %= MOD

print(xs * ys % MOD)

m,n = map(int,input().split())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))
MOD = 1000000007
sum_x = 0
sum_y = 0
for k in range(m):
  sum_x += (2*k +1 -m)*X[k]
sum_x %= MOD
for l in range(n):
  sum_y += (2*l + 1 - n)*Y[l]
sum_y %= MOD
Answer = (sum_x*sum_y) % MOD
print(Answer)

n, m = map(int, input().split())
X = sorted([int(x) for x in input().split()])
Y = sorted([int(x) for x in input().split()])
mod = 1000000007

def diffSum(X): #Σ(X[j]-X[i]) 1<=i<j<=N
    l = len(X)
    Res = [(2*i-l+1)*X[i] for i in range(l)]
    return sum(Res)%mod

print(diffSum(X)*diffSum(Y)%mod)

n,m = list(map(int,input().split()))
x = list(map(int,input().split()))
y = list(map(int,input().split()))
sum_x = 0
sum_y = 0
for i in range(n):
    sum_x += x[i]*i
    sum_x -= x[i]*(n-1-i)
for i in range(m):
    sum_y += y[i]*i
    sum_y -= y[i]*(m-1-i)
mod = 10**9+7
print(((sum_x%mod)*(sum_y%mod)%mod))


n,m=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
M,a,b=10**9+7,0,0
for i in range(n):a+=(2*i-n+1)*x[i];a%=M
for i in range(m):b+=(2*i-m+1)*y[i];b%=M
print(a*b%M)

MOD = 10**9+7

n,m = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))

x_dif = [b-a for a,b in zip(x,x[1:])]
y_dif = [b-a for a,b in zip(y,y[1:])]

def cumd(dif,line):
    d_sum = 0
    for i,d in enumerate(dif,1):
        d_sum += d * i * (line-i)%MOD
        d_sum %= MOD
    return d_sum

dx_sum = cumd(x_dif,n)
dy_sum = cumd(y_dif,m)

    
print(dx_sum * dy_sum % MOD)

# 解説AC
n,m=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
mod=10**9+7
ans,ans2=0,0 #sum[0<=i<j<n](x[j]-x[i])を求める.
for i in range(n):
    ans=(ans+(-n+2*i+1)*x[i])%mod
for i in range(m):
    ans2=(ans2+(-m+2*i+1)*y[i])%mod
print(ans*ans2%mod)

MOD = 10**9+7
n, m = list(map(int, input().split()))
X = list(map(int ,input().split()))
Y = list(map(int ,input().split()))
X.sort()
Y.sort()
xx, yy = 0, 0
for i in range(n):
    xx += X[i]*i
    xx -= X[i]*(n-i-1)
for i in range(m):
    yy += Y[i]*i
    yy -= Y[i]*(m-i-1)
print((xx*yy%MOD))


n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

MOD = 10**9+7

xx = [x[i + 1] - x[i] for i in range(n - 1)]
yy = [y[i + 1] - y[i] for i in range(m - 1)]

print(sum(xx[i] * (i + 1) * (n - 1 - i) for i in range(n - 1)) *
      sum(yy[i] * (i + 1) * (m - 1 - i) for i in range(m - 1)) % MOD)

mod = 10**9+7

def sum_interval_1d(N,X):
  # O(N)
  X_ = [X[i+1]-X[i] for i in range(N-1)]
  coef = list(range(1,N))[::-1]
  ret = (X_[0]*coef[0])%mod
  for i in range(1,N-1):
    coef[i] = (coef[i]+coef[i-1]-i)%mod
    ret = (ret + ((X_[i]*coef[i]) % mod)) % mod
  # print(X_, coef, ret)
  return ret

def solve():
  N,M = map(int, input().split())
  X = list(map(int, input().split()))
  Y = list(map(int, input().split()))
  x_sum = sum_interval_1d(N,X)
  y_sum = sum_interval_1d(M,Y)
  # print(x_sum,y_sum)
  ret = (x_sum*y_sum) % mod
  print(ret)
  
solve()

import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
n, m = lr()
X = np.array(lr())
Y = np.array(lr())
coef_x = np.arange(n)*2 - (n-1)
xsum = (X * coef_x % MOD).sum() % MOD
coef_y = np.arange(m)*2 - (m-1)
ysum = (Y * coef_y % MOD).sum() % MOD
answer = xsum * ysum % MOD
print(answer)


N,M = map(int,input().split())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))
a = 0
b = 0
mod = 10**9+7

for n in range(N):
  a+=(2*n-N+1)*X[n]
  a%=mod

for m in range(M):
  b+=(2*m-M+1)*Y[m]
  b%=mod

print(a*b%mod)

n,m=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
aj=0
xsum=0
mod1,mod2=10**9+7,998244353
mod=mod1
for j in range(1,n):
    aj=(aj+j*(x[j]-x[j-1])%mod)%mod
    xsum=(xsum+aj)%mod
bj=0
ysum=0
for j in range(1,m):
    bj=(bj+j*(y[j]-y[j-1])%mod)%mod
    ysum=(ysum+bj)%mod

print(xsum*ysum%mod)

N, M = map(int, input().split())
MOD = 10**9+7
x = [int(c) for c in input().split()]
y = [int(c) for c in input().split()]
X = 0
Y = 0
for i, c in enumerate(x):
  X += i*c-(N-1-i)*c
  X %= MOD
for i, c in enumerate(y):
  Y += i*c-(M-1-i)*c
  Y %= MOD
print(X*Y%MOD)

n,m=map(int,input().split())
X=list(map(int,input().split()))
Y=list(map(int,input().split()))
xsum=0;ysum=0;mod=10**9+7
for i,x in enumerate(X): xsum+=x*(i-(n-1-i))
for i,y in enumerate(Y): ysum+=y*(i-(m-1-i))
print(xsum * ysum % mod)

import sys
input = sys.stdin.readline


def main():
    n, m = list(map(int, input().split()))
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))
    
    X = [x[i+1]-x[i] for i in range(n-1)]
    Y = [y[i+1]-y[i] for i in range(m-1)]
    
    mod = pow(10, 9)+7
    for i in range(n-1):
        X[i] = X[i]*(n-i-1)*(i+1)%mod
    
    sum_x = sum(X)%mod
    
    for i in range(m-1):
        Y[i] = Y[i]*(m-i-1)*(i+1)%mod
    
    sum_y = sum(Y)%mod
    
    
    ans = sum_x*sum_y%mod
    
    print(ans)
    
    
    
def __starting_point():
    main()

__starting_point()

n,m = map(int,input().split())
mod = 10**9+7

x = sorted(list(map(int,input().split())))
y = sorted(list(map(int,input().split())))

X = 0
for i in range(n-1):
    X += (i+1)*(n-i-1)*(x[i+1]-x[i])%mod
    X %= mod

Y = 0
for i in range(m-1):
    Y += (i+1)*(m-i-1)*(y[i+1]-y[i])%mod
    Y %= mod

print(X*Y%mod)

def main():
    MOD = 10 ** 9 + 7

    N, M = list(map(int, input().split()))
    *X, = list(map(int, input().split()))
    *Y, = list(map(int, input().split()))

    def total(E):
        L = len(E)
        ret = 0
        for i, (frm, to) in enumerate(zip(E, E[1:]), start=1):
            ret = (ret + i * (L - i) * (to - frm)) % MOD
        return ret

    ans = total(X) * total(Y) % MOD
    print(ans)


def __starting_point():
    main()

__starting_point()

mod=1000000007
n,m=list(map(int,input().split()))
x=[int(i) for i in input().split()]
y=[int(i) for i in input().split()]

xc=0
for i in range(1,n):
    a=x[i]-x[i-1]
    l=min(i,n-i)
    #xc+=a*(l*n-((l*l+l)//2))
    xc+=a*(l*(n-l))
    xc%=mod

yc=0
for i in range(1,m):
    a=y[i]-y[i-1]
    l=min(i,m-i)
    #yc+=a*(l*m-((l*l+l)//2))
    yc+=a*(l*(m-l))
    yc%=mod
print(((xc*yc)%mod))


N, M = map(int, input().split())
MOD = 10**9 + 7
x = list(map(int, input().split()))
y = list(map(int, input().split()))

cumsum_x = [0] * N
cumsum_y = [0] * M
cumsum_x[0] = x[0]
cumsum_y[0] = y[0]
for i, xi in enumerate(x[1:], 1):
  cumsum_x[i] = (cumsum_x[i-1] + xi) % MOD

for i, yi in enumerate(y[1:], 1):
  cumsum_y[i] = (cumsum_y[i-1] + yi) % MOD

X = Y = 0
for i, xi in enumerate(x):
  X += (cumsum_x[-1] - cumsum_x[i] - (N - i - 1)*xi) % MOD
  X %= MOD

for i, yi in enumerate(y):
  Y += (cumsum_y[-1] - cumsum_y[i] - (M - i - 1)*yi) % MOD
  Y %= MOD

print(X*Y % MOD)

n,m = map(int, input().split())
xl = list(map(int, input().split())) 
yl = list(map(int, input().split())) 

xl = list(map(lambda x: x-xl[0],xl))
yl = list(map(lambda x: x-yl[0],yl))

xi=0
yi=0
mod = 10**9+7
xsum = sum(xl)
ysum = sum(yl)
for i in range(n):
    xi += (xsum - xl[i]*(n-i)) % mod
    xsum -= xl[i] 
    
for j in range(m):
    yi += (ysum - yl[j]*(m-j)) % mod
    ysum -= yl[j]

print(xi*yi % mod)

n, m = map(int,input().split())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))
DX = [X[i+1] - X[i] for i in range(n-1)]
DY = [Y[i+1] - Y[i] for i in range(m-1)]
mod = 10 ** 9 + 7

SUM_X = 0
SUM_Y = 0

for i in range(n-1):
    SUM_X += (i+1) * (n-1-i) * DX[i]
    SUM_X %= mod

for i in range(m-1):
    SUM_Y += (i+1) * (m-1-i) * DY[i]
    SUM_Y %= mod

ans = (SUM_X * SUM_Y) % mod

print(ans)

n,m=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
sx=0
sy=0
pr=10**9+7
for i in range(1,n):
    sx+=(x[i]-x[i-1])*(i*(n-i))%pr
for i in range(1,m):
    sy+=(y[i]-y[i-1])*(i*(m-i))%pr
print(sx*sy%pr)

num = input().split(" ")
zahyou_x = input().split(" ")
zahyou_y = input().split(" ")
x_num = int(num[0])
y_num = int(num[1])
x_sum = 0
y_sum = 0

for i in range(x_num):
    x_sum += int(zahyou_x[i]) * (i*2 - x_num + 1)

for i in range(y_num):
    y_sum += int(zahyou_y[i]) * (i*2 - y_num + 1)
print(x_sum*y_sum%(10**9+7))

import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
n, m = lr()
X = np.array(lr())
Y = np.array(lr())
coef_x = np.arange(n)*2 - (n-1)
X *= coef_x
xsum = (X%MOD).sum() % MOD
coef_y = np.arange(m)*2 - (m-1)
Y *= coef_y
ysum = (Y%MOD).sum() % MOD
answer = xsum * ysum % MOD
print((answer % MOD))


n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
mod = pow(10, 9) + 7
a, b = [0] * (n - 1), [0] * (m - 1)
c, s = n - 1, 0
for i in range(n - 1):
    s += c
    a[i] = s
    c -= 2
c, s = m - 1, 0
for i in range(m - 1):
    s += c
    b[i] = s
    c -= 2
sumx, sumy = 0, 0
for i in range(n - 1):
    sumx += (a[i] * (x[i + 1] - x[i]))
    sumx %= mod
for i in range(m - 1):
    sumy += (b[i] * (y[i + 1] - y[i]))
    sumy %= mod
ans = sumx * sumy % mod
print(ans)

n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
mod = 10**9+7
sum_x = 0
sum_y = 0
for i in range(n):
    sum_x += i*x[i]-(n-i-1)*x[i]
for i in range(m):
    sum_y += i*y[i]-(m-i-1)*y[i]
print(sum_x*sum_y%mod)

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
mod = 10**9+7

def count(li):
    l = 1-len(li)
    cnt = 0
    for ind, i in enumerate(li):
        cnt += i*(l+2*ind)
    return cnt%mod

print(((count(x)*count(y))%mod))


n,m = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
width,height = 0,0
a = -n-1
for k in range(1,n+1):
  width += x[k-1] * (2*k+a)
a = -m-1
for k in range(1,m+1):
  height += y[k-1] * (2*k+a)
width %= 1000000007
height %= 1000000007
print(width * height % 1000000007)

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
MOD = 10 ** 9 + 7
# 縦軸の和、横軸の和を求めて、掛け合わせる。

# listから、和を求める


def calc(lis):
    num = len(lis)
    sum = 0
    for i in range(num):
        #sum += x[i] * (num - i - 1) - x[i] * (i)
        sum += lis[i] * i - (lis[i] * (num - i - 1))

    return sum
    '''
          lisSum = 0
          before = 0
          for i, val in enumerate(lis):
              lisSum += val
              if (i != 0):
                  temp = before + val
                  lisSum = temp
              before = val

          return int(lisSum)

      '''


xSum = calc(x)
ySum = calc(y)

ans = (xSum * ySum) % MOD
print(ans)


'''
def calc(list):

sum = 0
for i in range(n):
  temp = n - i
  for j in range(i+1, n):
    sum += list[i] - list[j]

二重ループにせずとも、
for i in range(n):
  sum += x[i]*(n-i-1) - x[1]*(i)

でOK
'''


N, M = list(map(int, input().split()))
X = tuple(map(int, input().split()))
Y = tuple(map(int, input().split()))
MOD = 10 ** 9 + 7

X_sum = sum((2 * i - N + 1) * x for i, x in enumerate(X)) % MOD
Y_sum = sum((2 * i - M + 1) * y for i, y in enumerate(Y)) % MOD
print((X_sum * Y_sum % MOD))


def d_rectangles(MOD=10**9 + 7):
    N, M = [int(i) for i in input().split()]
    X = [int(i) for i in input().split()]
    Y = [int(i) for i in input().split()]

    ans1 = sum([x * (2 * k - N - 1) for k, x in enumerate(X, 1)])
    ans2 = sum([y * (2 * k - M - 1) for k, y in enumerate(Y, 1)])
    return (ans1 * ans2) % MOD

print(d_rectangles())

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
mod = 10**9+7

"""
各辺を独立して組み合わせて良い。
どのxの辺もすべてのyの辺をかけて合計することから、
分配法則を適用して
ans = (xの取りうる辺の総和)x(yの取りうる辺の総和)
となる
したがって、各辺の総和を効率的に求められれば良い
一旦xに着目し、各点の組合せでできる辺の総和を求める。
ここで、x_iとx_i+1の区間は他の辺の部分としてカウントされる回数は
(i+1)*(n-i-1) 0-indexed
したがって、差数列に回数を畳みこんで辺の総和が求まる
yも同様に総和を求め、積を取れば良い
"""

x_diff = [x[i]-x[i-1] for i in range(1, n)]
y_diff = [y[i]-y[i-1] for i in range(1, m)]

x_sum = 0
for i, dx in enumerate(x_diff):
    x_sum = (x_sum + (dx * (i+1) * (n-i-1))%mod)%mod
y_sum = 0
for i, dy in enumerate(y_diff):
    y_sum = (y_sum + (dy * (i+1) * (m-i-1))%mod)%mod

print(((x_sum*y_sum)%mod))




# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = MAP()
A = LIST()
B = LIST()

# 縦横独立に、全区間総和を取る
lsm = rsm = 0
for i in range(N):
    lsm += A[i] * (N-i-1)
    rsm += A[i] * i
    lsm %= MOD
    rsm %= MOD
h = rsm - lsm
lsm = rsm = 0
for i in range(M):
    lsm += B[i] * (M-i-1)
    rsm += B[i] * i
    lsm %= MOD
    rsm %= MOD
w = rsm - lsm

ans = h * w % MOD
print(ans)


N,M=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
mod=10**9+7

X=0
for i in range(N):
    X+=((i)*x[i]-(N-i-1)*x[i])
    X%=mod
Y=0
for i in range(M):
    Y+=((i)*y[i]-(M-i-1)*y[i])
    Y%=mod
print(X*Y%mod)

import sys
def input():
    return sys.stdin.readline().strip()

def calc(x,n):
    ans = 0
    for i,a in enumerate(x):
        ans += (2*i-n+1)*a
    return ans

n,m = list(map(int,input().split()))
x = tuple(map(int,input().split()))
y = tuple(map(int,input().split()))

print((calc(x,n)*calc(y,m)%(int(1e9+7))))


mod = 10 ** 9 + 7

def solve(N, X):
    return sum((2 * k - N + 1) * x for k, x in enumerate(X)) % mod


N, M, *XY = map(int, open(0).read().split())
X, Y = XY[:N], XY[N:]

print(solve(N, X) * solve(M, Y) % mod)

n, m = list(map(int, input().split()))

x = list(map(int, input().split()))    
y = list(map(int, input().split()))

tmp_x = 0
tmp_y = 0
mod = 10**9+7
for i, xi in enumerate(x):
    tmp_x += (xi+1)*(2*i-(n-1))
    
tmp_x = tmp_x % mod

for i, yi in enumerate(y):
    tmp_y += (yi+1)*(2*i-(m-1))
    
tmp_y = tmp_y % mod

print(((tmp_x*tmp_y)%mod))


import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
X = list(map(int,readline().split()))
Y = list(map(int,readline().split()))
DIV = 10 ** 9 + 7

# カウントする回数分X,Y軸ともに辺の長さを伸ばしていって巨大な長方形を作るイメージ
# X軸の、長さLの辺を3回数える場合、L * 2分X軸の辺の長さを伸ばす。
# X軸Y軸ともに各辺を数える回数が分かれば、巨大な長方形の面積はその積で求められる
# 
# X軸について、i番目の辺は、((i - 1) + 1) * (N - i)回数える
# 例：4番目の辺の場合
# ...X.. 
# Xより左から4通り（0も含むため） * Xより右から3通り(0も含むため)
# この回数分、辺の長さを掛けることを全ての辺に対して行った総和がX軸の辺の総量
# Y軸についても同じものを求めて、掛け合わせたものが答え

xsum = 0
for i in range(1, len(X)):
  # i番目の辺は、長さX[i] - X[i - 1]
  edge = X[i] - X[i - 1]
  # i番目の辺は((i - 1) + 1) * (N - i)回数える
  times = i * (N - i)
  xsum += ((edge % DIV) * (times % DIV)) % DIV
  xsum %= DIV

ysum = 0
for i in range(1, len(Y)):
  # i番目の辺は、長さY[i] - Y[i - 1]
  edge = Y[i] - Y[i - 1]
  # i番目の辺は((i - 1) + 1) * (M - i)回数える
  times = i * (M - i)
  ysum += ((edge % DIV) * (times % DIV)) % DIV
  ysum %= DIV

print((xsum * ysum) % DIV)

import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
X = list(map(int,readline().split()))
Y = list(map(int,readline().split()))
DIV = 10 ** 9 + 7

def f(V):
  vsum = 0
  for i in range(1, len(V)):
    vsum += (((V[i] - V[i - 1]) % DIV) * ((i * (len(V) - i)) % DIV)) % DIV
    vsum %= DIV
  return vsum
  
print((f(X) * f(Y)) % DIV)

n,m=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
# ブロックの数は(m-1)*(n-1)
mod=pow(10,9)+7
ypoint=0
for i in range(m-1):
  ypoint+=(y[i+1]-y[i])*(m-i-1)*(i+1)
  ypoint%=mod
ans=0
for i in range(n-1):
  ans+=ypoint*(x[i+1]-x[i])*(n-i-1)*(i+1)
  ans%=mod
print(ans)

import sys

input = sys.stdin.readline


def read_values():
    return list(map(int, input().split()))


def read_list():
    return list(read_values())


def func(N, mod):
    F = [1]
    for i in range(1, N + 1):
        F.append(F[-1] * i % mod)
    return F


INV = {}


def inv(a, mod):
    if a in INV:
        return INV[a]
    r = pow(a, mod - 2, mod)
    INV[a] = r
    return r


def C(F, a, b, mod):
    return F[a] * inv(F[b], mod) * inv(F[a - b], mod) % mod


def main():
    mod = 10 ** 9 + 7
    N, M = read_values()
    X = read_list()
    Y = read_list()

    res_x = 0
    for i in range(N - 1):
        res_x += (i + 1) * (N - i - 1) * (X[i + 1] - X[i]) % mod
        res_x %= mod

    res_y = 0
    for i in range(M - 1):
        res_y += (i + 1) * (M - i - 1) * (Y[i + 1] - Y[i]) % mod
        res_y %= mod
    print((res_x * res_y % mod))


def __starting_point():
    main()


__starting_point()

mod=1000000007
n,m=list(map(int,input().split()))
x=[int(i) for i in input().split()]
y=[int(i) for i in input().split()]

xc=0
for i in range(1,n):
    a=x[i]-x[i-1]
    if i<=((n)//2):
        l=i
    else:
        l=n-i
    xc+=a*(l*n-(l*l))
    xc=xc%mod

yc=0
for i in range(1,m):
    a=y[i]-y[i-1]
    if i<=((m)//2):
        l=i
    else:
        l=m-i
    yc+=a*(l*m-(l*l))
    yc=yc%mod
print(((xc*yc)%mod))


def calc(x):
    ans = 0
    n = len(x)
    for i,a in enumerate(x):
        ans += i*a - (n-1-i)*a
    return ans


n,m = map(int,input().split())
x = tuple(map(int,input().split()))
y = tuple(map(int,input().split()))

print(calc(x)*calc(y)%(int(1e9+7)))

mod=10**9+7
h=w=0
n,m=list(map(int,input().split()))
x=list(map(int,input().split()))
y=list(map(int,input().split()))
for i in range(n-1):
	h=(h+(x[i+1]-x[i])*(n-i-1)*(i+1))%mod
for i in range(m-1):
	w=(w+(y[i+1]-y[i])*(m-i-1)*(i+1))%mod
print((h*w%mod))


n,m=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
sumx,sumy=0,0
mod=10**9+7
for i in range(n):
    sumx+=i*x[i]-(n-i-1)*x[i]
sumx%=mod
for i in range(m):
    sumy+=i*y[i]-(m-i-1)*y[i]
sumy%=mod
print(sumx*sumy%mod)

mod = 10 ** 9 + 7

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))

sum_x = 0
for i in range(1, n + 1):
    sum_x += (i - 1) * x[i - 1] - (n - i) * x[i - 1]

sum_y = 0
for i in range(1, m + 1):
    sum_y += (i - 1) * y[i - 1] - (m - i) * y[i - 1]

print((sum_x * sum_y % mod))


n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
mod = 10 ** 9 + 7

xsm = 0
for i, ex in enumerate(x, 1):
    xsm -= ex * (n - i)
    xsm += ex * (i - 1)
    xsm %= mod

ysm = 0
for i, ey in enumerate(y, 1):
    ysm -= ey * (m - i)
    ysm += ey * (i - 1)
    ysm %= mod

ans = xsm * ysm % mod
print(ans)


MOD=10**9+7
n,m=map(int,input().split())
xlist=list(map(int,input().split()))
ylist=list(map(int,input().split()))

x0,y0=xlist[0],ylist[0]
for i in range(n):
  xlist[i]-=x0
for i in range(m):
  ylist[i]-=y0
#print(xlist)
#print(ylist)

xsum=0
for i in range(1,n):
  xsum+=xlist[i]*i
  xsum-=xlist[i]*(n-i-1)
  xsum%=MOD

ysum=0
for i in range(1,m):
  ysum+=ylist[i]*i
  ysum-=ylist[i]*(m-i-1)
  ysum%=MOD
  
print((xsum*ysum)%MOD)

n,m = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
MOD = 10**9 + 7
ans = 0
temp1 = 0
temp2 = 0
for i in range(n):
    temp1 += i*x[i] -(n-(i+1))*x[i]
    temp1 %= MOD

for i in range(m):
    temp2 += i*y[i] -(m-(i+1))*y[i]
    temp2 %= MOD

ans = temp1*temp2
ans %= MOD
print(ans)

#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(n: int, m: int, x: "List[int]", y: "List[int]"):
    X = 0
    for k in range(1,n+1):
        X += (k-1)*x[k-1]-(n-k)*x[k-1]
        X %= MOD
    Y = 0
    for k in range(1,m+1):
        Y += (k-1)*y[k-1]-(m-k)*y[k-1]
        Y %= MOD
    print((X*Y%MOD))

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    m = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    y = [int(next(tokens)) for _ in range(m)]  # type: "List[int]"
    solve(n, m, x, y)

def __starting_point():
    main()

__starting_point()

n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

mod = 10 ** 9 + 7
w = 0
for i in range(n-1):
    w += (x[i+1] - x[i]) * (i+1) * (n-i-1)
    w %= mod
h = 0
for j in range(m-1):
    h += (y[j+1] - y[j]) * (j+1) * (m-j-1)
    h %= mod
print(h * w % mod)

import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
# INF = float("inf")


def f(l):
    ret = 0
    for k in range(len(l)):
        ret += (2 * (k + 1) - len(l) - 1) * l[k]
    return ret % MOD


def main():
    n, m = map(int, input().split())
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))
    ans = f(x) * f(y) % MOD
    print(ans)


def __starting_point():
    main()
__starting_point()

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

n,m = list(map(int,input().split()))

X = [0] + sorted(list(map(int,input().split())))
Y = [0] + sorted(list(map(int,input().split())))
sum1 = 0
sum2 = 0
MOD = 10 ** 9 + 7
for i in range(1, n + 1):
    sum1 += ((i - 1)*X[i] - (n - i)*X[i]) % MOD
for i in range(1, m + 1):
    sum2 += ((i - 1)*Y[i] - (m - i)*Y[i])%MOD
print((sum1 * sum2 % MOD))


def main():
    MOD = 10 ** 9 + 7

    N, M = list(map(int, input().split()))
    *x, = list(map(int, input().split()))
    *y, = list(map(int, input().split()))

    sx = 0
    for i, x_ in enumerate(x, 1):
        sx = (sx + x_ * ((i - 1) - (N - i))) % MOD

    sy = 0
    for i, y_ in enumerate(y, 1):
        sy = (sy + y_ * ((i - 1) - (M - i))) % MOD

    ans = sx * sy % MOD

    print(ans)


def __starting_point():
    main()

# ある矩形の面積は
# (x1-x0)(y1-y0)
# x,yの各要素はx1,x0,y1,y0として何回出現するか?
# 1-indexedで、i番目の要素が
# x1として数えられるのは,
# 相方のx0の候補数 = 1-indexedのx0のインデックス = i-1
# x0として数えられるのは、
# 相方のx1の候補数 = 1-indexedのN-x0のインデックス = N-i

__starting_point()

N,M = list(map(int, input().split()))
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

## 0,x1,x2,x3
## S = (x1 + x2 + x3 + (x2-x1) + (x3-x1) + (x3-x2)) * ...
##.  = (3*x3 + x2 - x1 - 3* 0)
##.  = ((3-0) + (2-1) + (1-2) + (0-3)
mod = int(1e9+7)
X.sort(reverse=True)
Y.sort(reverse=True)
XP,YP = 0,0
for i in range(N):
  XP += (N-1-i*2) * X[i] 
  XP %= mod
for i in range(M):
  YP += (M-1-i*2) * Y[i] 
  YP %= mod
  
print(((XP * YP)%mod))


n, m = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

mod = 10**9+7

SX = 0
for i in range(n):
    SX += i*X[i] - (n-1-i)*X[i]
SX %= mod

SY = 0
for i in range(m):
    SY += i*Y[i] - (m-1-i)*Y[i]
SY %= mod

ans = SX*SY
print(ans%mod)

import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = list(map(int, input().split()))
    X = list(map(int, input().split()))
    Y = list(map(int, input().split()))

    XL = [X[i] - X[i - 1] for i in range(1, n)]
    YL = [Y[i] - Y[i - 1] for i in range(1, m)]

    cnt_X = [(i * (n - i)) % mod for i in range(1, n)]
    cnt_Y = [(i * (m - i)) % mod for i in range(1, m)]
    total_X = (sum([(XL[i] * cnt_X[i]) % mod for i in range(n - 1)])) % mod
    total_Y = (sum([(YL[i] * cnt_Y[i]) % mod for i in range(m - 1)])) % mod
    res = (total_X * total_Y) % mod
    print(res)


def __starting_point():
    resolve()

__starting_point()

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))

X = sum([(2*(k+1) - n - 1) * x[k] for k in range(n)])
Y = sum([(2*(k+1) - m - 1) * y[k] for k in range(m)])

print((X * Y % (10**9+7)))


MOD=10**9+7
n,m=map(int,input().split())
xs=list(map(int,input().split()))
ys=list(map(int,input().split()))
x=0
for i in range(n):
  x+=(2*(i+1)-n-1)*xs[i]
  x%=MOD

y=0
for j in range(m):
  y+=(2*(j+1)-m-1)*ys[j]
  y%=MOD

print(x*y%MOD)

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))

mod = 10 ** 9 + 7

sx = 0
sy = 0
for i in range(n):
    sx = (sx + x[i] * i - x[i] * (n - 1 - i)) % mod
for i in range(m):
    sy = (sy + y[i] * i - y[i] * (m - 1 - i)) % mod
print((sx * sy % mod))