CodeEff/ECCO huggingface dataset:
# Original solution
K, S = list(map(int, input().split()))
cnt = 0
for i in range(K+1):
  for j in range(i, K+1):
    if 0 <= S - i - j <= K:
      if i == j:
        cnt += 1
      else:
        cnt += 2
print(cnt)

# Optimized solution
K, S = list(map(int, input().split()))
X = (S + 2) * (S + 1)
if S - K - 1 >= 0:
  X -= 3 * (S - K + 1) * (S - K)
if S - 2 * K - 2 >= 0:
  X += 3 * (S - 2 * K) * (S - 2 * K - 1)

print((X // 2))
# Original solution
K,S = list(map(int, input().split()))

def binaly_serch(ls,k):#lsはリスト、kが求めたいもの
    ls.sort()
    n = len(ls)
    s = 0
    e = n#あえてls から一つ出たのにしておく。このおかげでk = ls[n-1]の時でも探索できる
    while int(e - s) >= 1:#intでcastして繰り下がった方を見て、e = bという条件にしてるからこれで全部探せる
        b = int((s+e)/2)
        if ls[b] == k:
            return True
        elif ls[b] < k:
            s = b + 1
        else:
            e = b
    return False
ans = 0
kls = [i for i in range(K+1)]
for i in range(K+1):
    for j in range(K+1):
        if S-(i+j) > K:
            continue
        else:
            if binaly_serch(kls,S-(i+j)):
                ans += 1

print(ans)


# Optimized solution
K,S = list(map(int, input().split()))

ans = 0
for i in range(K+1):
    for j in range(K+1):
        z = S-(i+j)
        if 0<= z and z <= K:
            ans += 1
print(ans)
# Original solution
from sys import stdin

k,s = [int(x) for x in stdin.readline().rstrip().split()]

point = 0
for i in range(k+1):
    for j in range(k+1):
        for k in range(k+1):
            if i + k + j == s:
                point += 1

print(point)

# Optimized solution
from sys import stdin

k,s = [int(x) for x in stdin.readline().rstrip().split()]

point = 0

for i in range(k+1):
    for j in range(k+1):
        if 0<= s-i-j <= k:
            point += 1

print(point)
# Original solution
K, S = list(map(int, input().split()))
ret = 0
for x in range(K + 1):
    for y in range(K + 1):
        if x + y > S:
            break
        for z in range(K + 1):
            if x + y + z == S:
                ret += 1
            if x + y + z >= S:
                break

print(ret)

# Optimized solution
K, S = list(map(int, input().split()))
ret = 0
for x in range(K + 1):
    for y in range(K + 1):
        if x + y <= S and  S - x - y <= K:
            ret += 1

print(ret)
# Original solution
k,s = list(map(int,input().split()))
cnt = 0
for i in range(k+1):
  for j in range(k+1):
    for l in range(k+1):
      Sum = i+j+l
      if Sum==s:
        cnt +=1
        
print(cnt)

# Optimized solution
k,s = list(map(int,input().split()))
cnt = 0
for i in range(k+1):
  for j in range(k+1):
    z = s-i-j
    if z<=k and z>=0:
      cnt +=1
print(cnt)
# Original solution
k,s=input().split()
k,s=int(k),int(s)
c=0
for i in range(k+1):
    s1=s-i
    if s1<0:
        break
    for j in range(k+1):
        s2=s1-j
        if s2<0:
            break
        if 0<=s2<=k:
            c+=1

print(c)


# Optimized solution
k,s=list(map(int,input().split()))
cnt=0
for i in range(k+1):
    for j in range(k+1):
        if 0<=s-i-j<=k:
            cnt+=1
print(cnt)
# Original solution
K,S = [int(i) for i in input().split()]
patterns = 0

for x in range(K+1) :
    x = int(x)
    for y in range(K+1) :
        y = int(y)
        z = S - x - y
        if (0 <= z and z <= K) :
            patterns += 1

print(patterns)


# Optimized solution
K,S = [int(i) for i in input().split()]
patterns = 0

for x in range(K+1) :
    for y in range(K+1) :
        z = S - x - y
        if (0 <= z and z <= K) :
            patterns += 1

print(patterns)
# Original solution
K, S=list(map(int, input().split()))
c=0
for i in range(0, S+1):
    for j in range(0, i+1):
        if j<=K and i-j<=K and S-i<=K:
            c+=1
print(c)

# Optimized solution
K, S=list(map(int, input().split()))
c=0
for i in range(0, min(2*K+1, S+1)):
    for j in range(0, min(K+1,i+1)):
        if j<=K and i-j<=K and S-i<=K:
            c+=1
print(c)
# Original solution
K,S = list(map(int, input().split()))
ans = 0
for z in range(K+1):
    ans += max(0, min(2*K-S+z+1, S-z+1))
print(ans)

# Optimized solution
K,S = list(map(int, input().split()))
print((sum(max(0, min(2*K-S+z+1, S-z+1)) for z in range(K+1))))
# Original solution
k,s=list(map(int,input().split()))

val=list(range(0, k+1))
n=len(val)
ans=0

for i in range(n):
    if val[i]>s:
        break
    for j in range(n):
        if val[i]+val[j]>s:
            break
        if s-(val[i]+val[j]) in val:
            ans+=1
            continue
print(ans)


# Optimized solution
k, s=list(map(int, input().split()))

ans=0
for x in range(0, k+1):
    if x>s:
        break
    for y in range(0, k+1):
        if x+y>s:
            break
        z=s-x-y
        if 0<=z and z<=k:
            ans+=1
            continue
print(ans)
# Original solution
k, s = list(map(int, input().split()))
x = [n for n in range(0, k+1)]
y = [m for m in range(0, k+1)]
z = [l for l in range(0, k+1)]
cnt = 0

for i in range(k+1):
    for j in range(k+1):
        for t in range(k+1):
            if(x[i] + y[j] + z[t] == s):
                cnt += 1
print(cnt)

# Optimized solution
k, s = list(map(int, input().split()))
cnt = 0

for x in range(k+1):
    for y in range(k+1):
        z = s - (x+y)
        if(z >= 0 and z <= k):
            cnt += 1
print(cnt)
# Original solution
def main():
    k, s = list(map(int, input().split()))

    res = 0

    for x in range(k+1):
        for y in range(k+1):
            for z in range(k+1):
                if x + y + z == s:
                    res += 1
    
    print(res)

if __name__ == '__main__':
    main()

# Optimized solution
def main():
    k, s = list(map(int, input().split()))

    res = 0

    for x in range(k+1):
        for y in range(k+1):
            z = s - (x + y)
            if z <= k and z >= 0:
                res += 1
        
    print(res)

if __name__ == '__main__':
    main()
# Original solution
from itertools import combinations
 
n, m = [int(i) for i in input().split(' ')]
x_list = [int(i) for i in input().split(' ')]
y_list = [int(i) for i in input().split(' ')]
 
total = 0
for x1, x2 in combinations(x_list, 2):
    for y1, y2 in combinations(y_list,2):
        total += (x2-x1)*(y2-y1)
        
print((int(total % (10**9+7))))

# Optimized solution
n, m = [int(i) for i in input().split(' ')]
x_list = [int(i) for i in input().split(' ')]
y_list = [int(i) for i in input().split(' ')]

x_res = 0
for i in range(n):
    x_res += (i-(n-i-1))*x_list[i]
y_res = 0
for j in range(m):
    y_res += (j-(m-j-1))*y_list[j]
print(((x_res*y_res) % (10**9+7)))
# Original solution
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)
    
    
    
if __name__ == "__main__":
    main()


# Optimized solution
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)
    
    
    
if __name__ == "__main__":
    main()
# Original solution
n, m = list(map(int, input().split()))
x = [x for x in map(int, input().split())]
y = [y for y in map(int, input().split())]
ans = 0
for i in range(n-1):
    for j in range(m-1):
        v = (i+1)*(n-1-i) * (j+1)*(m-1-j) #面積係数
        x_width = x[i+1] - x[i]
        y_width = y[j+1] - y[j]
        ans += v * x_width * y_width #面積係数*最小長方形面積
print((ans%1000000007))

# Optimized solution
n, m = list(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))
# Original solution
n, m = list(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))

# Optimized solution
n, m = list(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))
# Original solution
import sys
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

n,m = MI()
x,y = LI(),LI()
mod = 10**9+7

n,m = n-1,m-1
dx = [x[i+1]-x[i] for i in range(n)]
dy = [y[i+1]-y[i] for i in range(m)]

if n % 2 == 0:
    rx = [i*(n+1-i) for i in range(1,n//2+1)] + [i*(n+1-i) for i in range(n//2,0,-1)]
else:
    rx = [i*(n+1-i) for i in range(1,n//2+2)] + [i*(n+1-i) for i in range(n//2,0,-1)]
if m % 2 == 0:
    ry = [i*(m+1-i) for i in range(1,m//2+1)] + [i*(m+1-i) for i in range(m//2,0,-1)]
else:
    ry = [i*(m+1-i) for i in range(1,m//2+2)] + [i*(m+1-i) for i in range(m//2,0,-1)]

a = 0
for i,j in zip(dx,rx):
    a += i*j
    a %= mod
b = 0
for i,j in zip(dy,ry):
    b += i*j
    b %= mod

print(((a*b) % mod))


# Optimized solution
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,M = MI()
X = LI()
Y = LI()
mod = 10**9+7

r = sum((i*(N-i)*(X[i]-X[i-1])) % mod for i in range(1,N))
r %= mod

ans = 0
for i in range(1,M):
    ans += r*i*(M-i)*(Y[i]-Y[i-1]) % mod
    ans %= mod

print(ans)
# Original solution
n,m=[int(x) for x in input().split()]
x=[int(x) for x in input().split()]
y=[int(x) for x in input().split()]
from itertools import product
mod=10**9+7
ans=0
for i,j in product(list(range(1,n)),list(range(1,m))):
    ans=ans+(x[i]-x[i-1])*(y[j]-y[j-1])*i*(n-i)*j*(m-j)
print((ans%mod))

# Optimized solution
n,m=[int(x) for x in input().split()]
x=[int(x) for x in input().split()]
y=[int(x) for x in input().split()]
mod=10**9+7
ans=0
ysum=0
for j in range(1,m):
    ysum+=(y[j]-y[j-1])*j*(m-j)
for i in range(1,n):
    ans=ans+(x[i]-x[i-1])*i*(n-i)*ysum
print((ans%mod))
# Original solution
mod = int(1e9+7)
n, m = [int(num) for num in input().split()]

x = [int(x) for x in input().split()]
y = [int(y) for y in input().split()]

sumx = 0
for i in range(n-1):
    sumx += sum(x[i+1:]) - x[i] * ((n-1) - (i+1) + 1)
sumy = 0
for k in range(m-1):
    sumy += sum(y[k+1:]) - y[k] * ((m-1) - (k+1) + 1)

ans = ((sumx % mod) * (sumy % mod)) % mod

print(ans)

# Optimized solution
# 予めsx, syを全て計算しておく
# このとき漸化式を使えば毎回全ての話を求める必要がない

mod = int(1e9+7)
n, m = [int(num) for num in input().split()]

x = [int(x) for x in input().split()]
y = [int(y) for y in input().split()]


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

sy = [0] * m
sy[0] = y[0]
for k in range(m-1):
    sy[k+1] = sy[k] + y[k+1]
syd = 0
for k in range(m-1):
    syd += ((sy[m-1] - sy[k]) - y[k] * ((m-1) - (k+1) + 1)) % mod

ans = ((sxd % mod) * (syd % mod)) % mod

print(ans)
# Original solution
MOD = 10 ** 9 + 7
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):
    x[i] = x[i + 1] - x[i]

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

N = [n - 1]
for i in range(n - 3, 0, -2):
    N.append(N[-1] + i)
    # N.append((N[i] + (n - 1 - 2 * (i + 1))) % MOD)

M = [m - 1]
for i in range(m - 3, 0, -2):
    M.append(M[-1] + i)
    # M.append((M[i] + (m - 1- 2 * (i + 1))) % MOD)

if N[0] % 2 == 0:
    N += N[::-1]
elif N[0] != 1:
    N += N[1::-1]

if M[0] % 2 == 0:
    M += M[::-1]
elif M[0] != 1:
    M += M[1::-1]

# print (x)
# print (y)
# print (N)
# print (M)

if len(x) - 1 > len(N):
    while True:
        pass

if len(y) - 1 > len(M):
    while True:
        pass


X_sum = 0
for i in range(n - 1):
    X_sum += x[i] * N[i]
    X_sum %= MOD

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

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

# Optimized solution
MOD = 10 ** 9 + 7
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):
    x[i] = x[i + 1] - x[i]

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

N = [n - 1]
for i in range(n - 3, 0, -2):
    N.append(N[-1] + i)
    # N.append((N[i] + (n - 1 - 2 * (i + 1))) % MOD)

M = [m - 1]
for i in range(m - 3, 0, -2):
    M.append(M[-1] + i)
    # M.append((M[i] + (m - 1- 2 * (i + 1))) % MOD)

if N[0] % 2 == 0:
    N += N[::-1]
elif N[0] != 1:
    N += N[-2::-1]

if M[0] % 2 == 0:
    M += M[::-1]
elif M[0] != 1:
    M += M[-2::-1]

# print (x)
# print (y)
# print (N)
# print (M)

if len(x) - 1 > len(N):
    while True:
        pass

if len(y) - 1 > len(M):
    while True:
        pass


X_sum = 0
for i in range(n - 1):
    X_sum += x[i] * N[i]
    X_sum %= MOD

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

print(((X_sum * Y_sum) % MOD))
# Original solution
MOD = 10 ** 9 + 7
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):
    x[i] = x[i + 1] - x[i]

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

N = [n - 1]
for i in range(n - 3, 0, -2):
    N.append(N[-1] + i)
    # N.append((N[i] + (n - 1 - 2 * (i + 1))) % MOD)

M = [m - 1]
for i in range(m - 3, 0, -2):
    M.append(M[-1] + i)
    # M.append((M[i] + (m - 1- 2 * (i + 1))) % MOD)

if N[0] % 2 == 0:
    N += N[::-1]
elif N[0] != 1:
    N += N[-2::-1]

if M[0] % 2 == 0:
    M += M[::-1]
elif M[0] != 1:
    M += M[-2::-1]

# print (x)
# print (y)
# print (N)
# print (M)

if len(x) - 1 > len(N):
    while True:
        pass

if len(y) - 1 > len(M):
    while True:
        pass


X_sum = 0
for i in range(n - 1):
    X_sum += x[i] * N[i]
    X_sum %= MOD

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

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

# Optimized solution
MOD = 10 ** 9 + 7
n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x_sum = 0
for k, value in enumerate(x):
    x_sum += (2 * (k + 1) - n - 1) * value
    x_sum %= MOD

y_sum = 0
for k, value in enumerate(y):
    y_sum += (2 * (k + 1) - m - 1) * value
    y_sum %= MOD

print(((x_sum * y_sum) % MOD))
# Original solution
import sys
n,m = [int(x) for x in sys.stdin.readline().split()]
x = [int(x) for x in sys.stdin.readline().split()]
y = [int(x) for x in sys.stdin.readline().split()]
r = 0
mod = 10**9+7
for i in range(n):
	for j in range(i+1,n):
		dx = x[j]-x[i]
		for k in range(m):
			for l in range(k+1,m):
				dy = y[l]-y[k]
				r += dx*dy
tr = r%mod
print(tr)

# Optimized solution
import sys
n,m = [int(x) for x in sys.stdin.readline().split()]
x = [int(x) for x in sys.stdin.readline().split()]
y = [int(x) for x in sys.stdin.readline().split()]
r = 0
mod = 10**9+7
def sumof(a,b):
	s = 0
	for i in range(a):
		s += (2*(i+1)-a-1)*b[i]
		s %= mod
	return s
r = (sumof(n,x)*sumof(m,y))%mod
print(r)
# Original solution
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)
    for i in range(n-1):
        for j in range(m-1):
            s=(xx[i+1]-xx[i])*(yy[j+1]-yy[j])
            ans+=s*(i+1)*(n-i-1)*(j+1)*(m-j-1)
    print(ans)

main()


# Optimized solution
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()
# Original solution
n, m = input().split()
n = int(n)
m = int(m)
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]

s = 0

for i in range(n-1):
    for j in range(i+1, n):
        for k in range(m-1):
            for l in range(k+1,m):
                tate = x[j] - x[i]
                yoko = y[l] - y[k]
                s += tate * yoko

s %= (10**9 + 7)

print(s)


# Optimized solution
n, m = input().split()
n = int(n)
m = int(m)
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]

def sum(a, n):
    sum_a = 0
    for i in range(0, n):
        sum_a += i * a[i] - (n-1-i) * a[i]
    return sum_a

sum_x = sum(x,n)
sum_y = sum(y,m)

s = sum_x * sum_y % (10**9 + 7)

print(s)
# Original solution
# -*- coding: utf-8 -*-

import sys
import os
import math


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

def sum_len(A):
    all = 0
    for i in range(len(A)):
        for j in range(i+1, len(A)):
            l = A[j] - A[i]
            all += l
    return all

a = 10**9 + 7
xl = sum_len(X)
yl = sum_len(Y)
print((xl * yl % a))

# Optimized solution
# -*- coding: utf-8 -*-

import sys
import os
import math


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

def sum_len(A):
    all_sum = 0
    previous_sum = 0
    for i in range(1, len(A)):
        now_sum = previous_sum + i * (A[i] - A[i-1])
        all_sum += now_sum
        previous_sum = now_sum
    return all_sum

a = 10**9 + 7
xl = sum_len(X)
yl = sum_len(Y)
#print(xl)
#print(yl)
print((xl * yl % a))
# Original solution
# -*- coding: utf-8 -*-

n, m = input().split()
x = input().split()
y = input().split()
width = [abs(int(x[i])-int(x[j])) for i in range(len(x)-1) for j in range(i+1, len(x))]
height = [abs(int(y[i])-int(y[j])) for i in range(len(y)-1) for j in range(i+1, len(y))]

sum = 0
for w in width:
    for h in height:
        sum = sum + w * h
print((sum % (10 ** 9 + 7)))


# Optimized solution
# -*- coding: utf-8 -*-

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

def sum_length(x, n):
    all_sum = 0
    prev_sum = 0
    for i in range(1, n):
        cur_sum = prev_sum + (x[i] - x[i-1]) * i
        all_sum = all_sum + cur_sum
        prev_sum = cur_sum
    return all_sum

sumx = sum_length(x, n)
sumy = sum_length(y, m)
print((sumx * sumy % 1000000007))
# Original solution
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(0, n):
    tmp_x = x[i]
    sum_x += sum(list([ele for ele in ([ele - tmp_x for ele in x]) if ele > 0]))

sum_y = 0
for i in range(0, m):
    tmp_y = y[i]
    sum_y += sum(list([ele for ele in ([ele - tmp_y for ele in y]) if ele > 0]))

ans = sum_x * sum_y

divide_num = pow(10, 9) + 7
print((ans % divide_num))


# Optimized solution
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(0, n):
    sum_x += i * x[i] - (n - (i + 1)) * x[i]

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

ans = sum_x * sum_y

divide_num = pow(10, 9) + 7
print((ans % divide_num))
# Original solution
n, m = list(map(int, input().split()))
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]

MOD = 10 ** 9 + 7

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


# Optimized solution
n, m = list(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))
# Original solution
mod = 10 ** 9 + 7


def mod_mul(a, b):
    return a * b % mod


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

sx = sum(mod_mul(_x, i - (N - 1 - i)) for i, _x in enumerate(x))  # _x * i - _x * (N - 1 - i)
sy = sum(mod_mul(_y, i - (M - 1 - i)) for i, _y in enumerate(y))  # _y * i - _y * (M - 1 - i)
print((sx * sy % mod))


# Optimized solution
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)


if __name__ == '__main__':
    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