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 (Python):
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

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

Solution (Python):
mod=10**9+7
n, m=map(int,input().split())
x=tuple(map(int,input().split()))
y=tuple(map(int,input().split()))

lx, ly=0, 0
for i in range(n):
    lx+= i*x[i]-(n-i-1)*x[i]
    lx%=mod
for i in range(m):
    ly+= i*y[i]-(m-i-1)*y[i]
    ly%=mod

print((lx*ly)%mod)

Solution (Python):
import sys
input=sys.stdin.readline
INF=10**9+7
n,m=map(int,input().split())
x_list=list(map(int,input().split()))
y_list=list(map(int,input().split()))
X=0
plus=0
for i in range(n-1):
    plus=(plus+(x_list[i+1]-x_list[i])*(i+1))%INF
    X=(X+plus)%INF
Y=0
plus=0
for i in range(m-1):
    plus=(plus+(y_list[i+1]-y_list[i])*(i+1))%INF
    Y=(Y+plus)%INF
ans=(X*Y)%INF
print(ans)

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

mod = 10 ** 9 + 7

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

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

print((x_sum * y_sum) % mod)

Solution (Python):
mod=10**9+7
n,m=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
edge1=[]
for i in range(n-1):
  edge1.append(arr1[i+1]-arr1[i])
edge2=[]
for i in range(m-1):
  edge2.append(arr2[i+1]-arr2[i])
c1=[0]*(m-1)
tmp=0
if (m-1)%2==0:
  for i in range((m-1)//2):
    tmp+=(m-1)-2*i
    c1[i]=tmp
    c1[-(i+1)]=tmp
else:
  for i in range((m-1)//2+1):
    tmp+=(m-1)-2*i
    if i==(m-1)//2:
      c1[i]=tmp
    else:
      c1[i]=tmp
      c1[-(i+1)]=tmp
area=0
if (m-1)%2==0:
  for i in range((m-1)//2):
    area+=edge2[i]*c1[i]
    area+=edge2[-(i+1)]*c1[i]
else:
  for i in range((m-1)//2+1):
    if i==(m-1)//2:
      area+=edge2[i]*c1[i]
    else:
      area+=edge2[i]*c1[i]
      area+=edge2[-(i+1)]*c1[i]
c2=[0]*(n-1)
tmp=0
if (n-1)%2==0:
  for i in range((n-1)//2):
    tmp+=(n-1)-2*i
    c2[i]=tmp
    c2[-(i+1)]=tmp
else:
  for i in range((n-1)//2+1):
    tmp+=(n-1)-2*i
    if i==(n-1)//2:
      c2[i]=tmp
    else:
      c2[i]=tmp
      c2[-(i+1)]=tmp
ans=0
if (n-1)%2==0:
  for i in range((n-1)//2):
    ans+=area*edge1[i]*c2[i]
    ans+=area*edge1[-(i+1)]*c2[i]
    ans%=mod
else:
  for i in range((n-1)//2+1):
    if i==(n-1)//2:
      ans+=area*edge1[i]*c2[i]
    else:
      ans+=area*edge1[i]*c2[i]
      ans+=area*edge1[-(i+1)]*c2[i]
print(ans%mod)

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

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

Solution (Python):


def main():
    x_num, y_num = map(int, input().split())
    data_x = list(map(int, input().split()))
    data_y = list(map(int, input().split()))
    mod = 10 ** 9 + 7

    x_sum = 0
    for i in range(x_num):
        x_sum += (2 * i + 1 - x_num) * data_x[i]
        x_sum %= mod

    y_sum = 0
    for i in range(y_num):
        y_sum += (2 * i + 1 - y_num) * data_y[i]
        y_sum %= mod

    print((x_sum * y_sum) % mod)



if __name__ == '__main__':
    main()

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

Solution (Python):

import sys
sys.setrecursionlimit(300000)

MOD = 1000000007  

def solve(n: int, m: int, x: "List[int]", y: "List[int]"):
    def make_count(n):
        nc = [0] * n
        nc[0] = nc[n - 1] = n
        for i in range(1, (n - 1) // 2 + 1):
            nc[i] = nc[n - i - 1] = (nc[i - 1] + (n - 2 * i)) % MOD
        return nc

    nc = make_count(n - 1)
    mc = make_count(m - 1)
    xs = 0
    for i in range(n - 1):
        xs += (x[i + 1] - x[i]) * nc[i]
        xs %= MOD

    ret = 0
    for j in range(m - 1):
        ret += (y[j + 1] - y[j]) * xs * mc[j]
        ret %= MOD
    print(ret)
    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))  
    m = int(next(tokens))  
    x = [ int(next(tokens)) for _ in range(n) ]  
    y = [ int(next(tokens)) for _ in range(m) ]  
    solve(n, m, x, y)

if __name__ == '__main__':
    main()

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

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

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

print(xd*yd%mod)

Solution (Python):
mo=10**9+7
n,m=map(int,input().split())
x=[int(i) for i in input().split()]
y=[int(i) for i in input().split()]
X,Y=0,0
for i in range(n):
    X+=x[i]*(n-2*i-1)
    X%=mo
for i in range(m):
    Y+=y[i]*(m-2*i-1)
    Y%=mo
print(X*Y%mo)

Solution (Python):
import itertools
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

MOD = 10 ** 9 + 7

N, M = list(map(int, sys.stdin.readline().split()))
X = list(map(int, sys.stdin.readline().split()))
Y = list(map(int, sys.stdin.readline().split()))

xd = [b - a for a, b in zip(X[:-1], X[1:])]
yd = [b - a for a, b in zip(Y[:-1], Y[1:])]


xc = itertools.accumulate(range(len(xd), -len(xd), -2))
yc = itertools.accumulate(range(len(yd), -len(yd), -2))

x = 0
for d, c in zip(xd, xc):
    x = (x + d * c) % MOD
y = 0
for d, c in zip(yd, yc):
    y = (y + d * c) % MOD

print(x * y % MOD)

Solution (Python):
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

MOD = 10 ** 9 + 7

N, M = list(map(int, sys.stdin.readline().split()))
X = list(map(int, sys.stdin.readline().split()))
Y = list(map(int, sys.stdin.readline().split()))


def ModInt(mod):
    class _ModInt:
        def __init__(self, value):
            self.value = value % mod

        def __add__(self, other):
            if isinstance(other, _ModInt):
                return _ModInt(self.value + other.value)
            else:
                return _ModInt(self.value + other)

        def __radd__(self, other):
            return self.__add__(other)

        def __mul__(self, other):
            if isinstance(other, _ModInt):
                return _ModInt(self.value * other.value)
            else:
                return _ModInt(self.value * other)

        def __truediv__(self, other):
            
            raise NotImplementedError()

        def __repr__(self):
            return str(self.value)

    return _ModInt


MI = ModInt(MOD)
X = np.diff(X)
Y = np.diff(Y)
X = np.array([MI(x) for x in X])
Y = np.array([MI(y) for y in Y])


xc = np.arange(len(X), -len(X), -2).cumsum()
yc = np.arange(len(Y), -len(Y), -2).cumsum()

print(np.dot(X, xc) * np.dot(Y, yc))

Solution (Python):
n,m=map(int,input().split())
X=list(map(int,input().split()))
Y=list(map(int,input().split()))
x=[]
MOD=10**9+7
for i in range(n-1):
    x.append(X[i+1]-X[i])
y=[]
for i in range(m-1):
    y.append(Y[i+1]-Y[i])
xlen=0
for i in range(n-1):
    xlen+=((i+1)*((n-i-1)*x[i])%MOD)%MOD
ylen=0
for j in range(m-1):
    ylen+=(((j+1)*((m-j-1)*y[j])%MOD)%MOD)
print((xlen*ylen)%MOD)

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

x_tmp = 0
for i in range(n):
    x_tmp += (2*i-n+1) * X[i]
y_tmp = 0
for i in range(m):
    y_tmp += (2*i-m+1) * Y[i]

print(x_tmp * y_tmp % mod)

Solution (Python):
n,m,=map(int,input().split())
*x,=map(int,input().split())
*y,=map(int,input().split())
mod=10**9+7
print(sum((2*i-n-1)*x[i-1]for i in range(1,n+1))*sum((2*i-m-1)*y[i-1]for i in range(1,m+1))%mod)

Solution (Python):
mod=10**9+7
n,m=map(int,input().split())
X=tuple(map(int,input().split()))
Y=tuple(map(int,input().split()))
ans_x,ans_y=0,0
for i,x in enumerate(X):
    ans_x+=(2*i+1-n)*x
    ans_x%=mod
for i,y in enumerate(Y):
    ans_y+=(2*i+1-m)*y
    ans_y%=mod
print((ans_x*ans_y)%mod)

Solution (Python):
n,m = [ int(it) for it in input().split() ]
xli = [ int(it) for it in input().split() ]
yli = [ int(it) for it in input().split() ]

dxli = [0]*( len(xli) -1 )
dyli = [0]*( len(yli) -1 )
for i in range( len(xli) - 1 ):
  dxli[i] = xli[i+1] - xli[i]
for i in range( len(yli) - 1 ):
  dyli[i] = yli[i+1] - yli[i]

MOD = 1000000007
Sx = 0
Sy = 0
for i in range( len(dxli) ):
  Sx += dxli[i] * ( i + 1 ) * ( len(dxli) - i )
  Sx %= MOD
for i in range( len(dyli) ):
  Sy += dyli[i] * ( i + 1 ) * ( len(dyli) - i )
  Sy %= MOD
print ( (Sx*Sy)%MOD )

Solution (Python):
Mod = 10**9+7
n = [0,0]
n[0],n[1] = map(int,input().split())
a = [0,0]
for j in range(2):
  x = list(map(int,input().split()))
  s = 0
  for i in range(n[j]):
    s = (s+x[i]*(2*i+1-n[j]))%Mod
  a[j] = s
print((a[0]*a[1])%Mod)

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

Solution (Python):
def main():
    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()]
    dx = []
    dy = []
    for i in range(n-1):
        dx.append(x[i+1]-x[i])
    for i in range(m-1):
        dy.append(y[i+1]-y[i])

    alpha = [(i+1)*(n-i-1) for i in range((n+1)//2)]
    beta = [(i+1)*(m-i-1) for i in range((m+1)//2)]

    sum_dx = sum([dx[i] * alpha[min(i, n-i-2)] for i in range(n-1)])
    sum_dy = sum([dy[i] * beta[min(i, m-i-2)] for i in range(m-1)])

    print((sum_dx * sum_dy)%(10**9+7))

main()

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

x,y=[],[]
for i,u in enumerate(X[:-1]):
    x.append(X[i+1]-u)
for i,v in enumerate(Y[:-1]):
    y.append(Y[i+1]-v)
wx = [(i+1)*(n-i-1)%mod for i in range(n-1)]
wy = [(i+1)*(m-i-1)%mod for i in range(m-1)]
print((sum([wx[i]*x[i] for i in range(n-1)])%mod)*(sum([wy[i]*y[i] for i in range(m-1)])%mod)%mod)

Solution (Python):
n, m = 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))

Solution (Python):
n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
MOD = 10 ** 9 + 7
xx = 0
yy = 0
for i, xi in enumerate(x):
    xx += (2 * i + 1 - n) * xi
for i, yi in enumerate(y):
    yy += (2 * i + 1 - m) * yi
print(xx * yy % MOD)

Solution (Python):
import numpy as np

MOD = 10**9+7

n,m = map(int,input().split())
X = np.array([int(x) for x in input().split()], dtype = np.int64)
Y = np.array([int(x) for x in input().split()], dtype = np.int64)

coef_X = np.arange(n)*2-(n-1)
X_sum = np.sum(np.mod(X * coef_X,MOD))%MOD

coef_Y = np.arange(m)*2-(m-1)
Y_sum = np.sum(np.mod(Y * coef_Y,MOD))%MOD

answer = (X_sum*Y_sum)%MOD
print(answer)

Solution (Python):
n,m = map(int,input().split())
INF = 10**9+7

def F(j,i):
    return (i*(j-i))%INF
dx = []
px = 0
sx = 0
for x in map(int,input().split()):
    dx.append(x-px)
    px = x
dy = []
py = 0
sy = 0
for y in map(int,input().split()):
    dy.append(y-py)
    py = y

for i in range(1,n):
    sx = (sx+(dx[i]*F(n,i))%INF)%INF 
for i in range(1,m):
    sy = (sy+(dy[i]*F(m,i))%INF)%INF
print((sx*sy)%INF)

Solution (Python):
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())), reverse=True)
Y = sorted(list(map(int, input().split())), reverse=True)
MOD = 10 ** 9 + 7

X_sum = 0
for i, x in enumerate(X, start=1):
    X_sum += x * (N - i - i + 1)
    X_sum %= MOD

Y_sum = 0
for i, y in enumerate(Y, start=1):
    Y_sum += y * (M - i - i + 1)
    Y_sum %= MOD

print(X_sum * Y_sum % MOD)

Solution (Python):
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()

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

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

print(x*y%mod)

Solution (Python):
MOD = 10**9 + 7
n, m = [int(item) for item in input().split()]
x = [int(item) for item in input().split()]
y = [int(item) for item in input().split()]

x_total, y_total = 0, 0 
for i in range(1,n):
    x_total += (i * (n-i) * (x[i] - x[i-1])) % MOD
for i in range(1,m):
    y_total += (i * (m-i) * (y[i] - y[i-1])) % MOD
print((x_total * y_total)%MOD)

Solution (Python):
import sys

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

    X_com = 0
    for i in range(1, N+1):
        X_com += (i - 1) * X[i-1] - (N - i) * X[i-1]

    Y_com = 0
    for i in range(1, M+1):
        Y_com += (i - 1) * Y[i-1] - (M - i) * Y[i-1]

    return (X_com * Y_com) % (10**9 + 7)


if __name__ == '__main__':
    print(main())

Solution (Python):
def mul_mod(mod: int, *args)->int:
    ret = 1
    for a in args:
        ret = (ret * a) % mod
    return ret


def rectangles(n: int, m: int, X: list, Y: list)->int:
    MOD = 10**9 + 7

    DX = []
    x0 = X[0]
    for x in X[1:]:
        DX.append((x-x0) % MOD)
        x0 = x

    DY = []
    y0 = Y[0]
    for y in Y[1:]:
        DY.append((y-y0) % MOD)
        y0 = y

    dx_sum = sum(mul_mod(MOD, i+1, n-1-i, dx) for i, dx in enumerate(DX))
    dy_sum = sum(mul_mod(MOD, i+1, m-1-i, dy) for i, dy in enumerate(DY))

    return (dx_sum * dy_sum) % MOD


if __name__ == "__main__":
    n, m = map(int, input().split())
    X = [int(s) for s in input().split()]
    Y = [int(s) for s in input().split()]
    ans = rectangles(n, m, X, Y)
    print(ans)

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

a, b = 0, 0
for i in range(n):
    a += x[i]*i - x[i]*(n-i-1)
for i in range(m):
    b += y[i]*i - y[i]*(m-i-1)

print(a * b % mod)

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

Solution (Python):
MOD = 10**9 + 7


def dup(x, y):
    return x + x*y + 1 - y**2


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


if __name__ == "__main__":
    main()

Solution (Python):
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-(N-i-1))*X[i])%mod
    x%=mod
y=0
for j in range(M):
    y+=((j-(M-j-1))*Y[j])%mod
    y%=mod
print((x*y)%mod)

Solution (Python):
a,b = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
s = 0 
k = 0
for i,t in enumerate(reversed(x)):
    s+= (a-i-1)*t
    s-= i*t
for i,t in enumerate(reversed(y)):
    k+= (b-i-1)*t
    k-= i*t
print((s*k)%(10**9+7))

Solution (Python):
mod=10**9+7
def f(a):
    c=0
    for i in range(len(a)):
        c+=a[i]-a[0]
    d=c
    for i in range(1,len(a)-1):
        d+=c-(len(a)-i)*(a[i]-a[i-1])
        c-=(len(a)-i)*(a[i]-a[i-1])
    return d%mod
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
print(f(a)*f(b)%mod)

Solution (Python):
N, M = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]

mod = 10**9 + 7

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

Solution (Python):

from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007






"""
n = I()
s = SR(n)
for i in range(n):
    for j in range(len(s[i])):
        while s[i][j] in s[i][:j]:
            s[i][j] = "0"+s[i][j]
ans = set(s[0])
for i in range(1,n):
    ans &= set(s[i])
ans = sorted(list(ans))
if len(ans) == 0:print()
else:
    for i in range(len(ans)):
        ans[i] = ans[i][-1]
    ans.sort()
    for i in range(len(ans)-1):
        print(ans[i],end = "")
    print(ans[-1])
"""


n,m = LI()
ln = [n-1]
lm = [m-1]
a = n-1
b = m-1
while a > 2:
    a -= 2
    ln.append(ln[-1]+a)
while b > 2:
    b -= 2
    lm.append(lm[-1]+b)
la = len(ln)
lb = len(lm)
for i in range(la):
    if i or a == 2:
        ln.append(ln[la-i-1])
for i in range(lb):
    if i or b == 2:
        lm.append(lm[lb-i-1])
x,y = LIR(2)
lx = 0
ly = 0
for i in range(n-1):
    lx += ln[i]*(x[i+1]-x[i])%mod
    lx %= mod
for i in range(m-1):
    ly += lm[i]*(y[i+1]-y[i])%mod
    ly %= mod
ans = lx*ly%mod
print(ans)

Solution (Python):

from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007






"""
n = I()
s = SR(n)
for i in range(n):
    for j in range(len(s[i])):
        while s[i][j] in s[i][:j]:
            s[i][j] = "0"+s[i][j]
ans = set(s[0])
for i in range(1,n):
    ans &= set(s[i])
ans = sorted(list(ans))
if len(ans) == 0:print()
else:
    for i in range(len(ans)):
        ans[i] = ans[i][-1]
    ans.sort()
    for i in range(len(ans)-1):
        print(ans[i],end = "")
    print(ans[-1])
"""


n,m = LI()
ln = [n-1]
lm = [m-1]
a = n-1
b = m-1
while a > 2:
    a -= 2
    ln.append(ln[-1]+a)
while b > 2:
    b -= 2
    lm.append(lm[-1]+b)
la = len(ln)
lb = len(lm)
for i in range(la):
    if i or a == 2:
        ln.append(ln[la-i-1])
for i in range(lb):
    if i or b == 2:
        lm.append(lm[lb-i-1])
x,y = LIR(2)
lx = 0
ly = 0
for i in range(n-1):
    lx += ln[i]*(x[i+1]-x[i])%mod
    lx %= mod
for i in range(m-1):
    ly += lm[i]*(y[i+1]-y[i])%mod
    ly %= mod
ans = lx*ly%mod
print(ans)

Solution (Python):
n,m = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
mod = 1000000007

keisu = len(x)-1
keisu_kaisa = keisu
ans = 0
for i in range(1,n):
  
  ans = ans + 1*(x[i]-x[i-1])*keisu
  keisu_kaisa = keisu_kaisa -2
  keisu = keisu +(keisu_kaisa)
  ans = ans % mod
  
keisu = len(y)-1
keisu_kaisa = keisu
ans_2 = 0
for i in range(1,m):
  ans_2 = ans_2 + ans*(y[i]-y[i-1])*keisu
  keisu_kaisa = keisu_kaisa -2
  keisu = keisu +(keisu_kaisa)
  ans_2 = ans_2 % mod  
print(ans_2)

Solution (Python):
n,m = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
mod = 1000000007

keisu = len(x)-1
keisu_kaisa = keisu
ans = 0
for i in range(1,n):
  
  ans = ans + 1*(x[i]-x[i-1])*keisu
  keisu_kaisa = keisu_kaisa -2
  keisu = keisu +(keisu_kaisa)
  ans = ans % mod
  
keisu = len(y)-1
keisu_kaisa = keisu
ans_2 = 0
for i in range(1,m):
  ans_2 = ans_2 + ans*(y[i]-y[i-1])*keisu
  keisu_kaisa = keisu_kaisa -2
  keisu = keisu +(keisu_kaisa)
  ans_2 = ans_2 % mod  
print(ans_2)

Solution (Python):
n, m = map(int, input().split())

xsum = 0
xx = [int(i) for i in input().split()]
for i, x in enumerate(xx):
    xsum += (2 * i - n + 1) * x

ysum = 0
yy = [int(i) for i in input().split()]
for i, y in enumerate(yy):
    ysum += (2 * i - m + 1) * y

print(xsum * ysum % 1000000007)

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

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

Solution (Python):
N, M = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
mod = 10**9+7
x = 0
y = 0
for i in range(N):
    x += (-N+1+2*i)*X[i]
    x %= mod
for i in range(M):
    y += (-M+1+2*i)*Y[i]
    y %= mod
print(x*y % mod)

Solution (Python):
MOD = 1000000007
n, m = map(int,input().split())
xlst = list(map(int, input().split()))
ylst = list(map(int, input().split()))
xs = 0
for i in range(n - 1):
    w = xlst[i + 1] - xlst[i]
    xs += w * (i + 1) * (n - i - 1)
    xs %= MOD
ys = 0
for i in range(m - 1):
    h = ylst[i + 1] - ylst[i]
    ys += h * (i + 1) * (m - i - 1)
    ys %= MOD
print(xs * ys % MOD)

Solution (Python):


"""
参考：https://img.atcoder.jp/arc071/editorial.pdf
・各辺を加減する回数には規則性があるので、ループを1つ減らせる。
"""

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)

MOD = 10 ** 9 + 7

N, M = map(int, input().split())
xN = list(map(int, input().split()))
yM = list(map(int, input().split()))


x_sm = 0
for i in range(N):
    x_sm = (x_sm + i * xN[i] - (N-i-1) * xN[i]) % MOD
y_sm = 0
for i in range(M):
    y_sm = (y_sm + i * yM[i] - (M-i-1) * yM[i]) % MOD

print(x_sm * y_sm % MOD)

Solution (Python):
n, m = map(int, input().split())
x_list = tuple(map(int, input().split()))
y_list = tuple(map(int, input().split()))
mod = 10 ** 9 + 7
x_sum = 0
for i in range(1, n + 1):
    x_sum += ((i - 1) * x_list[i - 1] - (n - i) * x_list[i - 1]) % mod
y_sum = 0
for i in range(1, m + 1):
    y_sum += ((i - 1) * y_list[i - 1] - (m - i) * y_list[i - 1]) % mod
print(x_sum * y_sum % mod )

Solution (Python):
n, m = map(int, input().split())
x = [int(m) for m in input().split()]
y = [int(m) for m in input().split()]
mod = 10 ** 9 + 7
bx = []
for i in range(1, n):
    bx.append(abs(x[i] - x[i - 1]))

mulx = []
for i in range(1, n):
    mulx.append(i * (n - i))

ansx = 0
for i in range(n - 1):
    ansx += bx[i] * mulx[i]
    
ansx = ansx * (m - 1)



by = []
for i in range(1, m):
    by.append(abs(y[i] - y[i - 1]))

muly = []
for i in range(1, m):
    muly.append(i * (m - i))


ans = 0
for i in range(m - 1):
    ans += by[i] * ansx * muly[i] // muly[0]
    ans = ans % mod

ans = ans % mod
print(ans)

Solution (Python):
n, m = map(int, input().split())
x_list = tuple(map(int, input().split()))
y_list = tuple(map(int, input().split()))

mod = 10 ** 9 + 7

x_sum = 0
for i in range(1, n + 1):
    x_sum += ((i - 1) * x_list[i - 1] - (n - i) * x_list[i - 1]) % mod
y_sum = 0
for i in range(1, m + 1):
    y_sum += ((i - 1) * y_list[i - 1] - (m - i) * y_list[i - 1]) % mod

print(x_sum * y_sum % mod )

Solution (Python):
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))
Y = sorted(list(map(int, input().split())))
mod = 10 ** 9 + 7

X_SUM, Y_SUM = 0, 0
for i, x in enumerate(X):
    X_SUM = (X_SUM + x * (i - (N - i - 1))) % mod

for i, y in enumerate(Y):
    Y_SUM = (Y_SUM + y * (i - (M - i - 1))) % mod

print((X_SUM * Y_SUM) % mod)

Solution (Python):
N,M = map(int,input().split())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))
modulo = 10**9+7

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

print(x*y%modulo)

Solution (Python):
n,m=map(int,input().split())

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

X=[]
for i in range(1,len(x)):
    X.append(x[i]-x[i-1])
    
Y=[]
for j in range(1,len(y)):
    Y.append(y[j]-y[j-1])

A=len(X)
for a in range(int((len(X)+1)/2)):
    X[a]*=A
    if X[a]==X[len(X)-1-a]:
        pass
    else:
        X[len(X)-1-a]*=A
    A=A+len(X)-2*(a+1)
    
SX=sum(X)

B=len(Y)
for b in range(int((len(Y)+1)/2)):
    Y[b]*=B
    if Y[b]==Y[len(Y)-1-b]:
        pass
    else:
        Y[len(Y)-1-b]*=B
    B=B+len(Y)-2*(b+1)
    
SY=sum(Y)

print((SX*SY)%(10**9+7))

Solution (Python):
N, M = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
mod = 10 ** 9 + 7

XS = 0
for i, x in enumerate(X, start=1):
    XS += (x * ((i - 1) - (N - i))) % mod
YS = 0
for i, y in enumerate(Y, start=1):
    YS += (y * ((i - 1) - (M - i))) % mod

print(XS * YS % mod)

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

x=0

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

y = 0

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

print(x*y%mod)

Solution (Python):
n,m = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
x.sort()
y.sort()
N = 10**9+7
Lx=0
Ly=0
for i in range(n):
    Lx += (-n+2*i+1)*x[i]
    Lx %= N
for i in range(m):
    Ly += (-m+2*i+1)*y[i]
    Ly %= N
ans = Lx*Ly%N
print(ans)

Solution (Python):
N, M = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
MOD = 10 ** 9 + 7
numx = 0
for i in range(N):
    numx += -(N - i - 1) * X[i] + i * X[i]
numy = 0
for i in range(M):
    numy += -(M - i - 1) * Y[i] + i * Y[i]

print(numy * numx % MOD)

Solution (Python):

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

Solution (Python):
n, m = map(int, input().split())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
mod = 7 + 10**9

xtotal, ytotal = 0, 0
for i in range(n-1):
    xarea = x[i+1] - x[i]
    xright, xleft =  n - i - 1, i + 1
    xtotal += (xarea * xright * xleft) %mod
    xtotal %= mod
for j in range(m-1):
    yarea = y[j+1] - y[j]
    yup = m - j -1
    ydown = j + 1
    ytotal += (yarea * yup * ydown) % mod
    ytotal % mod

print((xtotal * ytotal) % mod)

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

MOD = 10 ** 9 + 7

x_sum = 0
temp = 0
for i in range(n - 1):
    temp = temp + n - 1 - (2 * i)
    x_sum += (x[i + 1] - x[i]) * temp
    x_sum %= MOD

y_sum = 0
temp = 0
for i in range(m - 1):
    temp = temp + m - 1 - (2 * i)
    y_sum += (y[i + 1] - y[i]) * temp
    y_sum %= MOD

print( (x_sum * y_sum) % MOD )

Solution (Python):
Q = 10**9 + 7
def zen(A,k):
    jiku = 0
    for i in range(k):
        jiku += i*A[i] - (k-1-i)*A[i]
    return jiku%Q
n, m = map( int, input().split())
X = list(map( int, input().split()))
Y = list(map( int, input().split()))
ans = zen(X,n)*zen(Y,m)
ans %= Q
print(ans)

Solution (Python):
def wa(ka, li):
    t = 0
    i = 0
    while ka > 0:
        t = (t + (li[-(i + 1)] - li[i]) * (ka - 1)) % (10 ** 9 + 7)
        ka -= 2
        i += 1
    return t


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

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    n, m = map(int, input().split())
    x_list = list(sorted(list(map(int, input().split()))))
    y_list = list(sorted(list(map(int, input().split()))))
    MOD = 10 ** 9 + 7

    x = 0
    for i, d in enumerate(range(-(n - 1), n, 2)):
        x += d * x_list[i]
        x %= MOD

    y = 0
    for i, d in enumerate(range(-(m - 1), m, 2)):
        y += d * y_list[i]
        y %= MOD
        
    print((x * y) % MOD)




if __name__ == '__main__':
    main()

Solution (Python):
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 += (2 * i + 1 - n) * x[i] % mod
for j in range(m):
    sum_y += (2 * j + 1 - m) * y[j] % mod

print((sum_x * sum_y) % mod)

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

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

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

print((w_sum * h_sum) % MOD)