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):
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

MOD = 10**9+7

n,m = li()
x = li()
y = li()

x.sort(reverse=True)
y.sort(reverse=True)

x_coeff = [n-(2*i+1) for i in range(n)]
y_coeff = [m-(2*i+1) for i in range(m)]

x_sum = 0
y_sum = 0

for xi, xcoefi in zip(x, x_coeff):
    x_sum += (xi * xcoefi)
    x_sum %= MOD
    
for yi, ycoefi in zip(y, y_coeff):
    y_sum += (yi * ycoefi)
    y_sum %= MOD

ans = x_sum * y_sum
print(ans%MOD)

Solution (Python):

"""
Created on Sat Sep  8 11:35:12 2018

@author: maezawa
"""

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

ax = 0
for i in range(1,n):
    ax += (n-i)*i*(x[i]-x[i-1])%(10**9+7)

ay = 0
for j in range(1,m):
    ay += (m-j)*j*(y[j]-y[j-1])%(10**9+7)
    
print(ax*ay%(10**9+7))

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

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

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N,M = inpl()
xx = inpl()
yy = inpl()

l = 0
r = M-1
ySUM = 0
while True:
	if r-l <= 2:
		ySUM += (yy[r]-yy[l])*(r-l)%mod
		break
	else:
		ySUM += (yy[r]-yy[l])*(r-l)%mod
		r,l = r-1,l+1

l = 0
r = N-1
xSUM = 0
while True:
	if r-l <= 2:
		xSUM += (xx[r]-xx[l])*(r-l)%mod
		break
	else:
		xSUM += (xx[r]-xx[l])*(r-l)%mod
		r,l = r-1,l+1

print(xSUM*ySUM%mod)

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, X, Y):
    MOD = 10**9+7

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


def main():
    N, M = read_int_n()
    X = read_int_n()
    Y = read_int_n()
    print(slv(N, M, X, Y))


if __name__ == '__main__':
    main()

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, X, Y):
    MOD = 10**9+7

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


def main():
    N, M = read_int_n()
    X = read_int_n()
    Y = read_int_n()
    print(slv(N, M, X, Y))


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_sum = 0
for i in range(n):
    X_sum += (2*i-n+1)*X[i]
    X_sum = X_sum % MOD
    
Y_sum = 0
for j in range(m):
    Y_sum += (2*j-m+1)*Y[j]
    Y_sum = Y_sum % MOD
    
print(X_sum * Y_sum % MOD)

Solution (Python):
I=lambda:list(map(int,input().split()))
I()
F=lambda x:sum(j*(len(x)-1-2*i)for i,j in enumerate(x))
print(F(I())*F(I())%(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

x_diff = 0
y_diff = 0

for i in range(N):
    x_diff += (2*i-N+1)*X[i]%MOD
    
for i in range(M):
    y_diff += (2*i-M+1)*Y[i]%MOD
    
print(x_diff*y_diff%MOD)

Solution (Python):
I=lambda:[int(i)for i in input().split()]
n,m=I()
N=I()
M=I()
F=lambda x,y:sum(j*(y-1-2*i)for i,j in enumerate(x))
print(F(N,n)*F(M,m)%(10**9+7))

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

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

Solution (Python):












MOD=10**9+7

N,M=map(int,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):
  sumX+=(X[i]*i-X[i]*(N-i-1))%MOD
  sumX%=MOD
  

sumY=0
for i in range(M):
  sumY+=(Y[i]*i-Y[i]*(M-i-1))%MOD
  sumY%=MOD
  
print((sumX*sumY)%MOD)

Solution (Python):
n,m = map(int, input().split())
X = [int(x) for x in input().split()]
Y = [int(x) for x in input().split()]
def f(a, n):
    return sum([(n - 1 - 2*i) * x for i, x in enumerate(reversed(a))])
print(f(X, n) * f(Y, m) % (10**9 + 7))

Solution (Python):
n, m = map(int, input().split())
p = 10 ** 9 + 7
X = [int(x) for x in input().split()]
Y = [int(x) for x in input().split()]
XX = [(X[i + 1] - X[i]) * (n - i - 1) * (i + 1) % p for i in range(n - 1)]
YY = [(Y[j + 1] - Y[j]) * (m - j - 1) * (j + 1) % p for j in range(m - 1)]
print(sum(XX) * sum(YY) % p)

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

def s(n,i):
	return i * (n-(i-1))

def xx(x,n):
	t = 0
	for i in range(n-1):
		t = (t + s(n-1,i+1) * (x[i+1]-x[i])) % P
	return t

R = (xx(x,n) * xx(y,m)) % P 
print(R)

Solution (Python):
n, m = map(int, input().split())
x = [int(x) for x in input().split()]
y = [int(x) for x in input().split()]

mod = 10 ** 9 + 7
a = 0
for k in range(n):
    a += k * x[k] - (n - (k + 1)) * x[k]
b = 0
for k in range(m):
    b += k * y[k] - (m - (k + 1)) * y[k]

print(a * b % 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
L = [i*(m-i)%mod for i in range(1, m)]
u = 0
for i in range(m-1):
    u += (Y[i+1] - Y[i]) * L[i] % mod
    u %= mod
M = [i*(n-i)%mod for i in range(1, n)]
ans = 0
for i in range(n-1):
    ans += u * (X[i+1] - X[i]) % mod * M[i] % mod
    ans %= mod
print(ans)

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_sum=sum((2*i-n+1)*x[i]for i in range(n))
y_sum=sum((2*i-m+1)*y[i]for i in range(m))
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()))
ax = sum([(2*i - n + 1)*x[i] for i in range(n)])
ay = sum([(2*i - m + 1)*y[i] for i in range(m)])
print((ax*ay)%(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

sum_x = 0
sum_y = 0
for i in range(n):
    sum_x += (n-1-i*2)*X[i] 
for i in range(m):
    sum_y += (m-1-i*2)*Y[i]
sum_x = sum_x%MOD
sum_y = sum_y%MOD
print((sum_x*sum_y)%MOD)

Solution (Python):
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()]
difx,dify,num,num2,mod = [],[],0,0,10**9+7
for i in range(1,n): difx.append(x[i]-x[i-1])
for i in range(1,m): dify.append(y[i]-y[i-1])
for i in range(n-1): num = (num+(i+1)*(n-i-1)*difx[i])%mod
for i in range(m-1): num2 = (num2+(i+1)*(m-i-1)*dify[i])%mod
print(num*num2%mod)

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

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(1,n+1):
    sx += (x[i - 1]*(i - 1)) - (x[i - 1] * (n - i))
for s in range(1,m+1):
    sy += (y[s - 1]*(s - 1)) - (y[s - 1] * (m - s))
print(abs(sx * sy)%1000000007)

Solution (Python):


line = input().split(" ")
n = int(line[0])
m = int(line[1])

x = 0
line1 = input().split(" ")
for (k,nn) in enumerate(line1):
    nn = int(nn)
    x += k*nn - (n-k-1)*nn


y = 0
line2 = input().split(" ")
for (k,nn) in enumerate(line2):
    nn = int(nn)
    y += k*nn - (m-k-1)*nn

print((x*y)%(10**9+7))

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

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

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


print x_sum*y_sum%(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

sum_x = sum_y = 0

l = 0
r = (n-1)

while l < r:
	sum_x += ((r-l) * abs(X[r] - X[l]))
	r -= 1
	l += 1

l = 0
r = (m-1)
while l < r:
	sum_y += ((r-l) * abs(Y[r] - Y[l]))
	r -= 1
	l += 1

print((sum_x*sum_y) % mod)

Solution (Python):
def d_igeta(N, M, X, Y):
    tmp1 = 0
    tmp2 = 0
    for k, x in enumerate(X):
        k += 1
        tmp1 += (k - 1) * x - (N - k) * x
    for k, y in enumerate(Y):
        k += 1
        tmp2 += (k - 1) * y - (M - k) * y
    return (tmp1 * tmp2) % (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()]
print(d_igeta(N, M, X, Y))

Solution (Python):
n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
a = [x[i+1] - x[i] for i in range(n-1)]
b = [y[i+1] - y[i] for i in range(m-1)]

MOD = int(1e9+7)
ai = sum([a[i] * (i+1) * max((0, (n-1-i))) % MOD for i in range(n-1)])
bi = sum([b[i] * (i+1) * max((0, (m-1-i))) % MOD for i in range(m-1)])
ans = ai * bi % MOD
print(ans)

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

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

MODULO = 10**9 +7

def MSum(x, y):
    return (x + y) % MODULO

def MPro(x, y):
    return (x * y) % MODULO

def foo(zs, k):
    s = 0
    for i in range(k):
       s = MSum(s, MPro(MPro(zs[i], k-i), i+1))
    return s

def diff(zs, k):
    previous = None
    rs = [0] * (k-1)
    for i, z in enumerate(zs):
        if i == 0:
            previous = z
            continue
        rs[i-1] = z - previous
        previous = z
    return rs

dx = diff(xs, n)
dy = diff(ys, m)

print(MPro(foo(dx, n-1), foo(dy, m-1)))

Solution (Python):
n, m = map(int, input().split())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))
MOD = int(1e9 + 7)
row = sum([(i+1) * (n-i-1) * (xs[i+1] - xs[i]) % MOD for i in range(n-1)]) % MOD
col = sum([(i+1) * (m-i-1) * (ys[i+1] - ys[i]) % MOD for i in range(m-1)]) % MOD
ans = row * col % MOD
print(ans)

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

Solution (Python):
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()]
mod = 10 ** 9 + 7
total = 0
x_total = 0
y_total = 0
for i in range(len(x)):
    x_total += x[i] * i - x[i] * (n - (i + 1))
for i in range(len(y)):
    y_total += y[i] * i - y[i] * (m - (i + 1))
print((x_total * y_total) % mod)

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

q = 10**9+7

x_sum = 0
y_sum = 0
for i in range(n):
    x_sum += (2*i - n + 1) * x[i]
    
for i in range(m):
    y_sum += (2*i - m + 1) * y[i]

print(  ((x_sum * y_sum )%q) )

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

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

total_w = total_h = 0
for n in range(1,N):
    w = xs[n] - xs[n-1]
    w = (w * n * (N-n)) % MOD
    total_w = (total_w + w) % MOD
for n in range(1,M):
    h = ys[n] - ys[n-1]
    h = (h * n * (M-n)) % MOD
    total_h = (total_h + h) % MOD
ans = (total_w * total_h) % MOD
print(ans)

Solution (Python):
n,m = list(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 k in range(1,n+1):
    a += (k-1)*x[k-1] - (n-k)*x[k-1]
for j in range(1,m+1):
    b += (j-1)*y[j-1] - (m-j)*y[j-1]

res = a*b
print(a*b%Mod)

Solution (Python):
from collections import defaultdict

MOD = 10 ** 9 + 7


def main():
    n, m = map(int, input().split())
    x_list = list(map(int, input().split()))
    y_list = list(map(int, input().split()))

    a = 0
    for k in range(1, n + 1):
        a += (k - 1) * x_list[k - 1] - (n - k) * x_list[k - 1]

    b = 0
    for k in range(1, m + 1):
        b += (k - 1) * y_list[k - 1] - (m - k) * y_list[k - 1]

    print((a % MOD * b % MOD) % MOD)

if __name__ == '__main__':
    main()

Solution (Python):
import sys




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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


n, m = read_int_list()
x = read_int_list()
y = read_int_list()


def compute_sum(q, a):
    return sum([(2 * p - q - 1) * a[p - 1] for p in range(1, q + 1)])


M = 10 ** 9 + 7
s = compute_sum(n, x)
t = compute_sum(m, y)
res = s * t % M
print(res)

Solution (Python):


n,m= map(int, input().split())
x=list(map(int, input().split()))
y=list(map(int, input().split()))
yoko=0
tate=0
for i in range (0,len(x)):
  yoko+=(n-2*i-1)*x[i]
for i in range (0,len(y)):
  tate+=(m-2*i-1)*y[i]

print(yoko*tate%(10**9+7))

Solution (Python):

x, y = [int(i) for i in input().split()]
xl = [int(i) for i in input().split()]
yl = [int(i) for i in input().split()]

xx = sum(  [ i*xl[i] - (x-i-1)*xl[i] for i in range(len(xl)) ]  )
yy = sum(  [ i*yl[i] - (y-i-1)*yl[i] for i in range(len(yl)) ]  )
ans = (xx * yy) % (10**9 + 7)
print(ans)

Solution (Python):
b = input().split()
c = [int(b[i]) for i in range(len(b))]

d = input().split()
e = [int(d[i]) for i in range(c[0])]

r = input().split()
f = [int(r[i]) for i in range(c[1])]

ansx = 0
for i in range(c[0]):
  tmp = i*e[i] - (c[0]-i-1)*e[i]
  ansx += tmp

ansy = 0
for j in range(c[1]):
  tmp = j*f[j] - (c[1]-j-1)*f[j]
  ansy += tmp

print((ansx * ansy) % (10**9 + 7))

Solution (Python):


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)

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

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

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

MOD = 1000000007;

xsum = 0;
ysum=0;
for i in range(n-1) :
	diff = x[i+1] - x[i]
	xsum += diff * (i+1) % MOD * (n-1-i) % MOD
for i in range(m-1) :
	diff = y[i+1] - y[i]
	ysum += diff * (i+1) % MOD * (m-1-i) % MOD
print(xsum * ysum % MOD);

Solution (Python):
a = list(map(int,input().split(" ")))
b = list(map(int,input().split(" ")))
c = list(map(int,input().split(" ")))

x = 0
y = 0

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

for i in range(1,a[1]):
    y = y + c[i] - c[0]
    
yy = y
for i in range(1,a[1]-1):
    yy = yy - ((c[i] - c[i - 1]) * (a[1] - i))
    y = y + yy

ans = x * y
ans = ans % (10**9 + 7)

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

def bruteforce():
    total = 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):
                    total += (x[j]-x[i]) * (y[l]-y[k])
    return total % MOD

def solve():
    width = 0
    for i in range(1, n):
        w = x[i] - x[i-1]
        width += w * (n-i)*i
        width %= MOD
    height = 0
    for i in range(1, m):
        h = y[i] - y[i-1]
        height += h * (m-i)*i
        height %= MOD

    return width * height % MOD

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

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

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

ans_x=0
ans_y=0

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


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

print(ans_x * ans_y % mod_number)

Solution (Python):



n , m = map(int, input().split())
X = [int(i) for i in input().split()]
Y = [int(i) for i in input().split()]

x_sum = 0
y_sum =0

for i in range(1,n+1):
    x_sum += (X[i-1] * (i - 1)) - (X[i-1] * (n - i))
    
for i in range(1,m+1):
    y_sum += (Y[i-1] * (i - 1)) - (Y[i-1] * (m - i))

print((x_sum * y_sum)%1000000007)

Solution (Python):
n,m = map(int, raw_input().split())
xls = map(int, raw_input().split())
yls = map(int, raw_input().split())
xsum = 0
for x in range(n):
    xsum += x * xls[x] - (n-x-1) * xls[x]
ysum = 0
for y in range(m):
    ysum += y * yls[y] - (m-y-1) * yls[y]
print (xsum * ysum) % (10**9 + 7)

Solution (Python):


n,m = map(int,raw_input().split())

x = map(int, raw_input().split())
y = map(int, raw_input().split())

mod = 10**9+7
xsum = 0
ysum = 0
for i in range(n):
    xsum += (2*(i+1)-n-1)*x[i]

for i in range(m):
    ysum += (2*(i+1)-m-1)*y[i]
area = xsum*ysum%mod
print(area)

Solution (Python):
s, t = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

def calc(li):
    div = 10 ** 9 + 7
    li_size = len(li)
    su_m = 0
    for k in range(li_size):
        su_m += ((2 * k + 1 - li_size) * li[k] ) % div
    return su_m

x_sum = calc(x)
y_sum = calc(y)
print((x_sum * y_sum ) % (10 ** 9 + 7))

Solution (Python):
import numpy as np
n,m = map(int , raw_input().split())
x = map(int, raw_input().split())
y = map(int, raw_input().split())

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) % (10**9+7)

Solution (Python):
n, m = map(int, raw_input().split())
xl = map(int, raw_input().split())
yl = map(int, raw_input().split())

def listsum(l):
    ret = 0
    n = len(l)
    for k, v in enumerate(l):
        ret += k * v
        ret -= (n - k - 1) * v
    return ret

ans = listsum(xl) * listsum(yl)
ans %= (10 ** 9 + 7)
print ans

Solution (Python):
nm = input()
n = int(nm.split()[0])
m = int(nm.split()[1])

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

ans = 0

ansx = 0
for k in range(1, n+1):
    ansx += (k-1)*x[k-1] - (n-k)*x[k-1]
ansx = ansx % (pow(10, 9) + 7)
 
ansy = 0
for k in range(1, m+1):
    ansy += (k-1)*y[k-1] - (m-k)*y[k-1]
ansy = ansy % (pow(10, 9) + 7)

ans = ansx * ansy
ans = ans % (pow(10, 9) + 7)

print(ans)

Solution (Python):


if __name__ == "__main__":
    n, m = map(int, raw_input().split(" "))
    x_list = map(int, raw_input().split(" "))
    y_list = map(int, raw_input().split(" "))

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

    y_sum = 0
    for j in range(1, m + 1):
        y_sum += (j - 1) * y_list[j-1] - (m - j) * y_list[j-1]

    print (x_sum * y_sum) % (10 ** 9 + 7)

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_sum = 0
for i in range(N):
    x_sum = (x_sum + X[i] * (N - i - 1) - X[i] * i) % MOD

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

result = (x_sum * y_sum) % MOD

print(result)

Solution (Python):
def read(): return list(map(int, input().split()))

n, m = read()
x = read()
y = read()

xs, ys = 0, 0
xs = sum([x[i] * (2 * i + 1 - n) for i in range(n)])
ys = sum([y[i] * (2 * i + 1 - m) for i in range(m)])

print((xs * ys) % 1000000007)

Solution (Python):
def read(): return list(map(int, input().split()))


MOD = 10 ** 9 + 7
n, m = read()
x = read()
y = read()

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

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

print((xs * ys) % MOD)

Solution (Python):
in1 = list(input().split())
nx = int(in1[0])
ny = int(in1[1])
x = list(input().split())
y = list(input().split())
sx = sum([ int(x[i])*(2*i - nx + 1) for i in range(nx) ])
sy = sum([ int(y[i])*(2*i - ny + 1) for i in range(ny) ])
print(sx*sy%(10**9 + 7))

Solution (Python):
import sys
sx,sy = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
ax = 0
ay = 0














for n in range(sx-1):
	ax += (x[n+1]-x[n])*(sx-n-1)*(n+1)
for n in range(sy-1):
	ay += (y[n+1]-y[n])*(sy-n-1)*(n+1)
print(ax*ay%(10**9+7))

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

Solution (Python):
def rren(): return list(map(int, input().split()))
n, m = rren()
x = rren()
y = rren()
ans = 0
x_sum = 0
y_sum = 0
for now_x in range(n):
    x_sum += x[now_x] * (now_x - (n-1 - now_x))
for now_y in range(m):
    y_sum += y[now_y] * (now_y - (m-1 - now_y))

print(x_sum * y_sum % 1000000007)

Solution (Python):



hou=10**9+7
mozir=input()
hyo=mozir.split(' ')
n=int(hyo[0])
m=int(hyo[1])

mozir=input()
hyo=mozir.split(' ')
TateLine=[ int(mono) for mono in hyo]


mozir=input()
hyo=mozir.split(' ')
YokoLine=[ int(mono) for mono in hyo]


TateYoso=0
for idx in range(0,n-1,1):
    TateYoso+= (n-(idx+1)) * (TateLine[n-(idx+1)]-TateLine[idx])
    TateYoso%= hou

YokoYoso=0
for idy in range(0,m-1,1):
    YokoYoso+= (m-(idy+1)) * (YokoLine[m-(idy+1)]-YokoLine[idy])
    YokoYoso%= hou

ans=(TateYoso*YokoYoso)%hou
print(ans)

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

Solution (Python):
from sys import stdin
n,m = map(int,stdin.readline().split())
a = map(int,stdin.readline().split())
b = map(int,stdin.readline().split())
a.sort()
b.sort()
x = []
y = []
for i in xrange(1,n):
    x.append(a[i] - a[i-1])
for i in xrange(1,m):
    y.append(b[i] - b[i-1])   
fir = 0
sec = 0
n = len(x)
m = len(y)
for i in xrange(n):
    fir += (i+1) * (n-i)*x[i]
for i in xrange(m):
    sec += (i+1) * (m-i) * y[i]
mod = 10**9 + 7
print (fir * sec)%mod

Solution (Python):
import sys
tmp = sys.stdin.readline().strip().split(" ")
n = int(tmp[0])
m = int(tmp[1])
xs = sys.stdin.readline().strip().split(" ")
ys = sys.stdin.readline().strip().split(" ")

s_x=0
s_y=0
r = pow(10,9)+7

for i in range(1,n+1):
	s_x = (s_x + (2*i-1-n)*int(xs[i-1])) % r

for i in range(1,m+1):
	s_y = s_y + (2*i-1-m)*int(ys[i-1]) % r

print((s_x*s_y)%r)

Solution (Python):


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 * yl % a)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n,m = LI()
    x = LI()
    y = LI()

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

    b = 0
    t = 0
    for i in range(1,m):
        sa = y[i] - y[i-1]
        t += sa * i
        t %= mod
        b += t
        b %= mod


    return a * b % mod



print(main())

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

tmp_x = 0
for i, xi in enumerate(x):
    tmp_x += (xi + 1) * (2 * i - (n - 1))
tmp_x = tmp_x % 1000000007

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

print ((tmp_x * tmp_y) % 1000000007)