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



Sample input:
3 3
1 3 4
1 3 6


Sample output:
60

Submission status: Wrong Answer

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

xdl = []
ydl = []
for x2,x1 in zip(xl[1:],xl[:-1]):
    xdl.append(x2-x1)

for y2,y1 in zip(yl[1:],yl[:-1]):
    ydl.append(y2-y1)


MOD = 10**9+7
ys = 0
for i,d in enumerate(xdl):
    pattern = (i+1)*(m-1-i)
    ys += pattern*d
    ys%=MOD

ans = 0

for i,d in enumerate(ydl):
    pattern = (i+1)*(n-1-i)
    ans += pattern*ys*d
    ans%=MOD

print(ans)

Submission status: Wrong Answer

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

X = abs(x[n-1]-x[0])%mod
Y = abs(y[m-1]-y[0])%mod
K = pow(2,n+m-4,mod)

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

Submission status: Wrong Answer

Solution code:
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(DX)-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(4)))
        Y = list(accumulate(randrange(1,8) for _ in range(4)))
        a1 = solve(X,Y)
        a2 = naive(X,Y)
        if a1 != a2:
            print(X,Y)
            print(a1)
            print(a2)
            return

if __name__ == '__main__':
    # test()
    N,M = map(int,input().split())
    X = tuple(map(int,input().split()))
    Y = tuple(map(int,input().split()))
    print(solve(X,Y))
    # print(naive(X,Y))

Submission status: Wrong Answer

Solution code:
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(DX)-i)*dy for i,dy in enumerate(DY))
    return a*b


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(4)))
        Y = list(accumulate(randrange(1,8) for _ in range(4)))
        a1 = solve(X,Y)
        a2 = naive(X,Y)
        if a1 != a2:
            print(X,Y)
            print(a1)
            print(a2)
            return

if __name__ == '__main__':
    # test()
    N,M = map(int,input().split())
    X = tuple(map(int,input().split()))
    Y = tuple(map(int,input().split()))
    print(solve(X,Y))
    # print(naive(X,Y))

Submission status: Wrong Answer

Solution code:
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-1):
    sum_y += (2*j - m + 1) * y[j]
ans = sum_x * sum_y
print(ans%1000000007)

Submission status: Wrong Answer

Solution code:
import sys
import math
import fractions
import bisect
import queue
import heapq
import collections
import itertools
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint=====================================
N, K = map(int, input().split())
N, M = map(int, input().split())
A, B = map(int, input().split())

H, W = map(int, input().split())

L, R = map(int, input().split())

1行のstring=================================
S, T = input().split()

1行の整数配列================================
P = list(map(int,input().split()))

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
D = list(map(int,input().split()))

L = list(map(int,input().split()))
R = list(map(int,input().split()))

T = list(map(int,input().split()))

改行あり整数==================================
X = []
Y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    X.append(x1)
    Y.append(y1)

A = []
for i in range(N):
    a=int(input())
    A.append(a)

Pair = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    Pair.append((x1, y1))
    
2次元整数配列=====================================
A = []
for i in range(N):
    tmp = list(map(int,input().split()))
    A.append(tmp)


N行M列の初期化====================================
dp = [[VAL] * RETU for i in range(GYO)]

'''


        
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)]

N -= 1
M -= 1

countX = [(i+1)*(N-i)*DX[i] for i in range(N)]
countY = [(i+1)*(N-i)*DY[i] for i in range(M)]


sumX = sum(countX)
sumY = sum(countY)

sumX %= MOD
sumY %= MOD

ans = sumX * sumY % MOD

print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
import math
import fractions
import bisect
import queue
import heapq
import collections
import itertools
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint=====================================
N, K = map(int, input().split())
N, M = map(int, input().split())
A, B = map(int, input().split())

H, W = map(int, input().split())

L, R = map(int, input().split())

1行のstring=================================
S, T = input().split()

1行の整数配列================================
P = list(map(int,input().split()))

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
D = list(map(int,input().split()))

L = list(map(int,input().split()))
R = list(map(int,input().split()))

T = list(map(int,input().split()))

改行あり整数==================================
X = []
Y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    X.append(x1)
    Y.append(y1)

A = []
for i in range(N):
    a=int(input())
    A.append(a)

Pair = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    Pair.append((x1, y1))
    
2次元整数配列=====================================
A = []
for i in range(N):
    tmp = list(map(int,input().split()))
    A.append(tmp)


N行M列の初期化====================================
dp = [[VAL] * RETU for i in range(GYO)]

'''


        
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)]

N -= 1
M -= 1

countX = [(i+1)*(N-i) for i in range(N)]
countY = [(i+1)*(N-i) for i in range(M)]

local = 0
for i in range(M):
    local += countY[i] * DY[i]
local *= DX[0] * countX[0]

ans = local % MOD
for i in range(1, N):
    local = local * countX[i] * DX[i] / countX[i-1] / DX[i-1]
    ans += local
    ans = int(ans)
    ans %= MOD

print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
def MI(): return 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 = [n+i for i in range(n//2)] + [n+i for i in range(n//2-1,-1,-1)]
else:
    rx = [n+i for i in range(n//2)] + [n+(n//2)] + [n+i for i in range(n//2-1,-1,-1)]
if m % 2 == 0:
    ry = [m+i for i in range(m//2)] + [m+i for i in range(m//2-1,-1,-1)]
else:
    ry = [m+i for i in range(m//2)] + [m+(m//2)] + [m+i for i in range(m//2-1,-1,-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)

Submission status: Wrong Answer

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

mod = 10**9 + 7

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
print(H, W)
S = H*W

print(S % mod)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
print(((max(x)-min(x))*(n-1)*(max(y)-min(y))*(m-1))%(10**9+7))

Submission status: Wrong Answer

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

if m>2 and n>2:
    X2=[(X[1]-X[0])%mod,(X[-2]-X[1])%mod,(X[-1]-X[-2])%mod]
    Y2=[(Y[1]-Y[0])%mod,(Y[-2]-Y[1])%mod,(Y[-1]-Y[-2])%mod]
    ans=0
    a,b1,b2,c=m*n,(2*m-2)*n,(2*n-2)*m,(2*m-2)*(2*n-2)
    ans+=(X2[0]*Y2[0] + X2[2]*Y2[0] + X2[0]*Y2[2] + X2[2]*Y2[2])*a%mod
    ans+=(X2[1]*Y2[0]+X2[1]*Y2[2])*b1%mod
    ans+=(X2[0]*Y2[1]+X2[2]*Y2[1])*b2%mod
    ans+=X2[1]*Y2[1]*c%mod
    print(ans%mod)
else:
    print(mod)

Submission status: Wrong Answer

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

S = 0

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

print(S)

Submission status: Wrong Answer

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

S = 0

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

print(S)

Submission status: Wrong Answer

Solution code:
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

xsum = sum(xl)
ysum = sum(yl)
for i in range(n):
    xi += xsum - xl[i]*(n-i)
    xsum -= xl[i] 
    
for j in range(m):
    yi += ysum - yl[j]*(m-j)
    ysum -= yl[j]

print(xi*yi)

Submission status: Wrong Answer

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

xi=0
yi=0

xsum = sum(xl)
ysum = sum(yl)
for i in range(n):
    xi += xsum - xl[i]*(n-i)
    xsum -= xl[i] 
    
for j in range(m):
    yi += ysum - yl[j]*(m-j)
    ysum -= yl[j]

print(xi*yi)

Submission status: Wrong Answer

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

MOD=10**9+7
ans=abs(x[0]-x[-1])*abs(y[0]-y[-1])*(n-1)*(m-1)%MOD
print(ans)

Submission status: Wrong Answer

Solution code:
# 解説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 - (N - k - 1) * z) % MOD
    return ans

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

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


def read_values():
    return 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)

    print(res_x * res_y % mod)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
lists=list(map(int,input().split()))
sub=list(map(int,input().split()))
mod=10**9+7
J=0
s=0
if n>=3 and m>=3:
    J=n*m*(lists[-2]-lists[1])*(sub[-2]-sub[1])
if True:    
    s=0
    for i in range(n-1):
        s+=(m-1)*(lists[i+1]-lists[i])*(i+1)*(n-1-i)*(sub[-1]-sub[-2]+sub[1]-sub[0])
        s=s%mod
    for j in range(1,m-2):
        s+=(n-1)*(sub[j+1]-sub[j])*(j+1)*(m-1-j)*(lists[-1]-lists[-2]+lists[1]-lists[0])
        s=s%mod
print((s+J)%mod)

Submission status: Wrong Answer

Solution code:
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()
coef_y = np.arange(m)*2 - (m-1)
Y *= coef_y
ysum = (Y%MOD).sum()
answer = xsum * ysum % MOD
print(answer % MOD)

Submission status: Wrong Answer

Solution code:
mod=1000000007
n,m=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+l)//2))
    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+l)//2))
    yc=yc%mod
print((xc*yc)%mod)

Submission status: Wrong Answer

Solution code:
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)
print(xsum * ysum % mod)

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
#mint
class ModInt:
    def __init__(self, x):
        self.x = x % mod
    
    def __str__(self):
        return str(self.x)
    
    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x)
        else:
            return ModInt(self.x + other)

    __radd__ = __add__
        
    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x)
        else:
            return ModInt(self.x - other)

    def __rsub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x)
        else:
            return ModInt(other - self.x)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x)
        else:
            return ModInt(self.x * other)

    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, mod-2,mod))
        else:
            return ModInt(self.x * pow(other, mod - 2, mod))
            
    def __rtruediv(self, other):
        if isinstance(other, self):
            return ModInt(other * pow(self.x, mod - 2, mod))
        else:
            return ModInt(other.x * pow(self.x, mod - 2, mod))
            

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, mod))
        else:
            return ModInt(pow(self.x, other, mod))
            

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, mod))
        else:
            return ModInt(pow(other, self.x, mod))

def main():
    N,M=MI()
    X=LI()
    Y=LI()
    ans = ModInt(0)
    for i,x in enumerate(X[:-1]):
        for j,y in enumerate(Y[:-1]):
            s = (X[i+1]-x) * (Y[j+1]-y)
            print(s,(i+1) * (N-(i+1)) * (j+1) * (M-(j+1)) * s)
            ans += (i+1) * (N-(i+1)) * (j+1) * (M-(j+1)) * s
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
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()]
x.sort(reverse=True)
y.sort(reverse=True)

ans_x=0
for i in range(n):
    ans_x+=x[i]*(n-(2*(i+1)-1))
ans_y=0
for j in range(m):
    ans_y+=y[j]*(m-(2*(j+1)-1))
print(ans_x*ans_y)

Submission status: Wrong Answer

Solution code:
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]
sx.reverse()
sxd = 0  
for i in range(n-1):
    sxd += sx[-i - 2] - x[i] * (n - 1 - i)

sy = [0] * m
sy[0] = y[0]
for k in range(m-1):
    sy[k+1] = sy[k] + y[k+1]
sy.reverse()
syd = 0
for k in range(m-1):
    syd += sy[-k - 2] - y[k] * (m - 1 - k) 

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

print(ans)

Submission status: Wrong Answer

Solution code:
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 = 1e9+7
xtot = 0
ytot = 0
for i in range(n):
	xtot += (2*i-n+1)*x[i]
	xtot %= mod
for i in range(m):
	ytot += (2*i-m+1)*y[i]
	ytot %= mod
print(int((xtot*ytot)%mod))

Submission status: Wrong Answer

Solution code:
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 = 1e9+7
xtot = 0
ytot = 0
for i in range(n):
	xtot += (2*i-n+1)*x[i]
for i in range(m):
	ytot += (2*i-m+1)*y[i]
xtot = xtot % mod
ytot = ytot % mod
print(int((xtot*ytot)%mod))

Submission status: Wrong Answer

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

total = 0
for l in range(len(y)-1):
	for k in range(len(x)-1):
		for i in range(1,len(x)):
			for j in range(1,len(y)):
				total += ((x[i]-x[k])*(y[j]-y[l]))%1000000007
				total %= 1000000007

print(total%1000000007)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LI()
    if b - a == c - b:
        print("YES")
    else:
        print("NO")
    return

#B
def B():
    o = S()
    e = S()
    for i in range(len(e)):
        print(o[i] + e[i], end="")
    if len(e) != len(o):
        print(o[-1], end="")
    print()
    return

#C
def C():
    l = [inf] * 27
    n = II()
    for _ in range(n):
        b = [0] * 27
        for si in S():
            b[ord(si) - 97] += 1
        for i in range(27):
            l[i] = min(l[i], b[i])
    ans = []
    for i in range(27):
        ans.append(chr(97 + i) * l[i])
    print("".join(ans))
    return

#D
def D():
    n, m = LI()
    x = LI()
    y = LI()
    print((x[-1] - x[0]) * (y[-1] - y[0]) * (2 ** (n - 2)) * (2 ** (m - 2)) % mod)
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Wrong Answer

Solution code:
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+1:
      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):
    if i==0:
      area+=(edge2[i]*c1[i])%mod
      area+=(edge2[-(i+1)]*c1[i])%mod
    else:      
      area+=(edge2[i]*c1[i])%mod
      area+=(edge2[-(i+1)]*c1[i])%mod
      area%=mod
else:
  for i in range((m-1)//2+1):
    if i==(m-1)//2+1:
      area+=(edge2[i]*c1[i])%mod
    else:
      area+=(edge2[i]*c1[i])%mod
      area+=(edge2[-(i+1)]*c1[i])%mod
      area%=mod
area%=mod
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+1:
      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])%mod
    ans+=(area*edge1[-(i+1)]*c2[i])%mod
    ans%=mod
else:
  for i in range((n-1)//2+1):
    if i==0:
      ans+=(area*edge1[i]*c2[i])%mod
      ans+=(area*edge1[-(i+1)]*c2[i])%mod
      ans%=mod
    elif i==1:
      ans+=(area*edge1[i]*c2[i])%mod
      ans+=(area*edge1[-(i+1)]*c2[i])%mod
      ans%=mod
    else:
      ans+=(area*edge1[i]*c2[i])%mod
print(ans%mod)

Submission status: Wrong Answer

Solution code:

if __name__ == "__main__":
    n, m = map(int, input().split())
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))

    S = ((n - 1) * (m - 1) * (max(x) - min(x)) * (max(y) - min(y))) 
    print(S % (10 ** 9 + 7))

Submission status: Wrong Answer

Solution code:
n,m,=map(int,input().split())
*b,=map(int,input().split())
*a,=map(int,input().split())
mod=10**9+7
ans=(n-1)*(m-1)*(max(b)-min(b))*(max(a)-min(a))%mod
print(ans)

Submission status: Wrong Answer

Solution code:
a,b = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
t = x[-1] -x[0]
f = y[-1] -y[0]
s = t*f
v = 2**(a-2)
c = 2**(b-2)
print(s*v*c)

Submission status: Wrong Answer

Solution code:
a,b = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
t = x[-1] -x[0]
f = y[-1] -y[0]
s = t*f
v = 2**(a-1)
c = 2**(b-1)
print(s*v*c)

Submission status: Wrong Answer

Solution code:
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])
    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)

Submission status: Wrong Answer

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

sum_x,sum_y=[0]*(n-1),[0]*(m-1)
sum_x[0]=x[1]-x[0]
sum_y[0]=y[1]-y[0]
mod=10**9+7

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

print((sum_x[-1]*sum_y[-1])%mod)

Submission status: Wrong Answer

Solution code:
o = input()
e = input()
for i in range(min(len(o),len(e))):
    print('%s%s' % (o[i],e[i]), end='')
if len(o)>len(e): print(o[-1])

Submission status: Wrong Answer

Solution code:
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 % mod
ansx = ansx * (m - 1)
ansx = ansx % mod


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)

Submission status: Wrong Answer

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

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

X1=[len(X) for i in range(len(X))]
for k in range(1,int(len(X)/2)+1):
    X1[k]=X1[k-1]+(len(X)-2*k)
    X1[len(X)-k-1]=X1[k-1]+(len(X)-2*k)
#print(X1)
    
Y1=[len(Y) for i in range(len(Y))]
for l in range(1,int(len(Y)/2)):
    Y1[l]=Y1[l-1]+(len(Y)-2*l)
    Y1[len(Y)-l-1]=Y1[l-1]+(len(Y)-2*l)
#print(Y1)

i=0
j=0
X2=[]
for i in range(len(X1)):
    X2.append(X[i]*X1[i])
Y2=[]
for j in range(len(Y1)):
    Y2.append(Y[j]*Y1[j])
    
print(sum(X2)%(10**9+7)*sum(Y2)%(10**9+7))

Submission status: Wrong Answer

Solution code:
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]
  print("x",x)

y = 0

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

print(x*y%mod)

Submission status: Wrong Answer

Solution code:
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]
print(sx*sy)

Submission status: Wrong Answer

Solution code:
n,m  = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
P = 10**9+7
def xx(x,n):
	t = 0
	for i in range(n-1):
		t = (t + i*(n-(i-1)) * (x[i+1]-x[i])) % P
	return t
print((xx(x,n) * xx(y,m)) % P)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m = map(int, input().split())
X = [int(x) for x in input().split()]
Y = [int(x) for x in input().split()]
p = 10 ** 9 + 7
S = np.asarray([[(X[i + 1] - X[i]) * (Y[j + 1] - Y[j]) % p for j in range(m - 1)] for i in range(n - 1)])
m = np.asarray([[(n - i - 1) * (i + 1) * (m - j - 1) * (j + 1) % p for j in range(m - 1)] for i in range(n - 1)])
print(np.sum(S * m) % p)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m = map(int, input().split())
X = [int(x) for x in input().split()]
Y = [int(x) for x in input().split()]
p = 10 ** 9 + 7
S = np.asarray([[(X[i + 1] - X[i]) * (Y[j + 1] - Y[j]) % p for j in range(m - 1)] for i in range(n - 1)])
m = np.asarray([[(n - i - 1) * (i + 1) * (m - j - 1) * (j + 1) for j in range(m - 1)] for i in range(n - 1)])
print(np.sum(S * m) % p)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding=utf-8

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

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

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

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

Submission status: Wrong Answer

Solution code:
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 - n + 1) * y[i]

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

Submission status: Wrong Answer

Solution code:
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 - n + 1) * y[i]

print(x_sum * y_sum)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

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

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

X_ans = 0
Y_ans = 0

for i in range(n):
    X_ans += ((i-1)-(n-i))*X[i]
    
for j in range(m):
    Y_ans += ((j-1)-(n-j))*Y[j]
        
print((X_ans * Y_ans)%(10**9+7))

Submission status: Wrong Answer

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

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

X_diff = []
Y_diff = []

for i in range(len(X)-1):
    X_diff.append((X[i+1]-X[i]))
                  
for i in range(len(Y)-1):
    Y_diff.append((Y[i+1]-Y[i]))
    
    
def diff(l, n):
    a = 0
    for i in range(len(l) - n + 1):
        a += sum(l[i:i+n])
    return a

X_ans = 0
Y_ans = 0

for i in range(1, n+1):
    X_ans += diff(X_diff, i)
for j in range(1, m+1):
    Y_ans += diff(Y_diff, j)
        
print(X_ans * Y_ans)