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: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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(bruteforce())
    print(solve())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# D - 井井井 / ###
# 問題URL:http://abc058.contest.atcoder.jp/tasks/arc071_b

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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding:utf-8

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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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
# #test
# sx = 8のとき
# 1 1 1 1 1 1 1
# 1 2 2 2 2 2 1
# 1 2 3 3 3 2 1
# 1 2 3 4 3 2 1
# 1 2 3 3 3 2 1
# 1 2 2 2 2 2 1
# 1 1 1 1 1 1 1
# (x[1]-x[0])*sx
# (x[2]-x[1])*sx+sx-2
# (x[3]-x[2])*sx+sx-2+sx-4
# (x[n+1]-x[n])*(sx+sx-2*n)*(n+1)/2
# sxが奇数の時
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))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding=UTF-8
#単純にやっていったら間に合わないよ

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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Runtime Error

Solution code:
import sys

input = sys.stdin.buffer.readline
in_n = lambda: int(input())
in_nn = lambda: map(int, input().split())
in_s = lambda: input().rstrip().decode('utf-8')
in_map = lambda: [s == ord('.') for s in input() if s != ord('\n')]

MOD = 10**9 + 7
INF = 8 * 10**18


def main():

    N, M = in_nn()
    X = list(in_nn())
    Y = list(in_nn())

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

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

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

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

    print(x_sum * y_sum % MOD)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
dbg = lambda *args, **kwargs: print(*args, **kwargs, file=sys.stderr)

MOD = 10 ** 9 + 7
N, M = inm()
X = inl()
Y = inl()
assert len(X) == N
assert len(Y) == M


def solve():
    xsum = [0] * N
    xsum[N - 1] = (X[N - 1] - X[N - 2]) % MOD
    for k in range(2, N):
        xsum[N - k] = xsum[N - k + 1] + k * (X[N - k] - X[N - k - 1])
        xsum[N - k] %= MOD

    # for i in range(N):
    #     dbg(f"> {i=} {xsum[i]=}")

    ysum = [0] * M
    ysum[M - 1] = (Y[M - 1] - Y[M - 2]) % MOD
    for k in range(2, M + 1):
        ysum[M - k] = ysum[M - k + 1] + k * (Y[M - k] - Y[M - k - 1])
        ysum[M - k] %= MOD

    # for j in range(M):
    #     dbg(f"> {j=} {ysum[j]=}")

    return sum(xsum[1:]) % MOD * (sum(ysum[1:]) % MOD) % MOD


print(solve())

Submission status: Runtime Error

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

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: Runtime Error

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

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: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
int main()
{

    int n, m;
    cin >> n >> m;
    VL x(n), y(m);
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];
    sort(ALL(x));
    sort(ALL(y));
    ll sx = 0;
    rep(i, n)
    {
        sx += MOD * n + i * x[i];
        sx %= MOD;
        sx -= (MOD * n + (n - 1 - i) * x[i]) % MOD;
        while (sx < 0)
            sx += MOD;
    }
    ll sy = 0;
    rep(i, m)
    {
        sy += MOD * m + i * y[i];
        sy %= MOD;
        sy -= (MOD * m + (m - 1 - i) * y[i]) % MOD;
        while (sy < 0)
            sy += MOD;
    }
    cout << (sx * sy) % MOD << endl;
    ;
    return 0;
}

Submission status: Runtime Error

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())
x_len = X[1:] - X[:-1]
y_len = Y[1:] - Y[:-1]

square = x_len[:, None] * y_len[None, :]
answer = 0
for i in range(n-1):
    answer += (square[i] % MOD).sum()
    answer %= MOD

answer *= (n-1) * (m-1)
print(answer%MOD)
# 43

Submission status: Runtime Error

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())
x_len = X[1:] - X[:-1]
y_len = Y[1:] - Y[:-1]

square = x_len[:, None] * y_len[None, :] % MOD
answer = (n-1) * (m-1) * square.sum() % MOD
print(answer%MOD)
# 43

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
X=0;Y=0
mod=10**9+7
for i in range(n-1):
  X+=(a[i+1]-a[i])*(i+1)*(n-i-1)
  X%=mod
for i in range(n-1):
  Y+=(b[i+1]-b[i])*(i+1)*(n-i-1)
  Y%=mod
print(X*Y%mod)

Submission status: Runtime Error

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

Xd = []
for i in range(n-1):
    Xd.append(X[i+1]-X[i])
    
Yd = []
for i in range(m-1):
    Yd.append(Y[i+1]-Y[i])
    
Xd[1] = 2*Xd[0] + 2*Xd[1]
for i in range(n-3):
    Xd[i+2] = 2*Xd[i+1] - Xd[i] + (i+3)*Xd[i+2]
    Xd[i+2] %= mod
    
Yd[1] = 2*Yd[0] + 2*Yd[1]
for i in range(m-3):
    Yd[i+2] = 2*Yd[i+1] - Yd[i] + (i+3)*Yd[i+2]
    Yd[i+2] %= mod
    
print(Xd[-1]*Yd[-1]%mod)

Submission status: Runtime Error

Solution code:

n,m =list(map(int,input().split(" ")))
xs  =list(map(int,input().split(" ")))
ys =list(map(int,input().split(" ")))
MOD = (10**9) + 7
x_diff = [abs(i - j) for i,j in zip(xs[:n-1],xs[1:n]) ]
y_diff = [abs(i - j) for i,j in zip(ys[:n-1],ys[1:n]) ]

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

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



print (x* y % MOD )

Submission status: Runtime Error

Solution code:
MOD = 10 ** 9 + 7
n, m = 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)//2 - 1):
    N.append((N[i] + (n - 1 - 2 * (i + 1))) % MOD)

M = [m - 1]
for i in range((m)//2 - 1):
    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]

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)

Submission status: Runtime Error

Solution code:
MOD = 10 ** 9 + 7
import numpy as np
n, m = 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)//2 - 1):
    N.append((N[i] + (n - 1 - 2 * (i + 1))) % MOD)

M = [m - 1]
for i in range((m)//2 - 1):
    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 (N)
# print (M)

N = np.array(N, dtype = 'int64')
M = np.array(M, dtype = 'int64')

X = np.array(x[:-1], dtype = 'int64')
Y = np.array(y[:-1], dtype = 'int64')

# print (N)
# print (M)
# print (X)
# print (Y)

X *= N
Y *= M

X %= MOD
Y %= MOD

# print (X)
# print (Y)
# print ((np.sum(X) * np.sum(Y)) % MOD)

# X_sum = np.sum(X) % MOD
# Y_sum = np.sum(Y) % MOD

X_sum = 0
for i in X:
    X_sum += i
    X_sum %= MOD

Y_sum = 0
for i in Y:
    Y_sum += i
    Y_sum %= MOD

print ((X_sum * Y_sum) % MOD)

Submission status: Runtime Error

Solution code:
MOD = 10 ** 9 + 7
import numpy as np
n, m = 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)//2 - 1):
    N.append((N[i] + (n - 1 - 2 * (i + 1))) % MOD)

M = [m - 1]
for i in range((m)//2 - 1):
    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 (N)
# print (M)

N = np.array(N, dtype = 'int64')
M = np.array(M, dtype = 'int64')

X = np.array(x[:-1], dtype = 'int64')
Y = np.array(y[:-1], dtype = 'int64')

# print (N)
# print (M)
# print (X)
# print (Y)

X *= N
Y *= M

X %= MOD
Y %= MOD

# print (X)
# print (Y)
# print ((np.sum(X) * np.sum(Y)) % MOD)

X_sum = np.sum(X) % MOD
Y_sum = np.sum(Y) % MOD

print ((X_sum * Y_sum) % MOD)

Submission status: Runtime Error

Solution code:
MOD = 10 ** 9 + 7
import numpy as np
n, m = 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)//2 - 1):
    N.append((N[i] + (n - 1 - 2 * (i + 1))) % MOD)

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

if N[0] % 2 == 0:
    N += N[::-1]
else:
    N += N[1::-1]
if M[0] % 2 == 0:
    M += M[::-1]
else:
    M += M[1::-1]

# print (N)
# print (M)

N = np.array(N, dtype = 'int64')
M = np.array(M, dtype = 'int64')

X = np.array(x[:-1], dtype = 'int64')
Y = np.array(y[:-1], dtype = 'int64')

# print (N)
# print (M)
# print (X)
# print (Y)

X *= N
Y *= M

X %= MOD
Y %= MOD

# print (X)
# print (Y)
# print ((np.sum(X) * np.sum(Y)) % MOD)

X_sum = np.sum(X) % MOD
Y_sum = np.sum(Y) % MOD

print ((X_sum * Y_sum) % MOD)

Submission status: Runtime Error

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_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(n-1):
    y_sum += (y[i+1] - y[i]) * (i + 1) * (n - i - 1)
    y_sum %= mod

print((x_sum * y_sum) % mod)

Submission status: Runtime Error

Solution code:
def exe(x, y):
  X = [0] * x
  Y = [0] * y
  for i in range(x):
    X[i] = (i + 1) * (x - i) * a[i] % MOD
  for i in range(y):
    Y[i] = (i + 1) * (y - i) * b[i] % MOD
  print((sum(X) % MOD) * (sum(Y) % MOD) % MOD)
  

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

Submission status: Runtime Error

Solution code:
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(n):
    Y+=y[i]*(n-2*i-1)
    Y%=mo
print(X*Y%mo)

Submission status: Runtime Error

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(n):
    sy+=i*y[i]-(n-i-1)*y[i]
print(sx*sy)

Submission status: Runtime Error

Solution code:
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*x[j]-(m-j-1)*x[j])
print(vx*vy%mod)

Submission status: Runtime Error

Solution code:
import numpy
n, m = map(int, input().split(' '))
line_x = list(map(int, input().split(' ')))
line_y = list(map(int, input().split(' ')))
masu_x = [n-1]
masu_y = [m-1]
for i in range(1, n-1):
    masu_x.append(masu_x[i-1] + n - 1 - 2 * i)
for i in range(1, m-1):
    masu_y.append(masu_y[i-1] + m - 1 - 2 * i)
masu_x = numpy.mat(masu_x)
masu_y = numpy.mat(masu_y)
masu_multi = numpy.dot(masu_y.T, masu_x)
masu_area = numpy.zeros(tuple(masu_multi.shape))
for i in range(n-1):
    for j in range(m-1):
        masu_area[j][i] = ((line_x[i+1] - line_x[i]) * (line_y[j+1] - line_y[j])) % 1000000007
print(int(numpy.sum(numpy.array(masu_multi) * numpy.flipud(masu_area) % 1000000007) % 1000000007))

Submission status: Runtime Error

Solution code:
import numpy
n, m = map(int, input().split(' '))
line_x = list(map(int, input().split(' ')))
line_y = list(map(int, input().split(' ')))
masu_x = [n-1]
masu_y = [m-1]
for i in range(1, n-1):
    masu_x.append(masu_x[i-1] + n - 1 - 2 * i)
for i in range(1, m-1):
    masu_y.append(masu_y[i-1] + m - 1 - 2 * i)
masu_x = numpy.mat(masu_x)
masu_y = numpy.mat(masu_y)
masu_multi = numpy.dot(masu_y.T, masu_x)
masu_area = numpy.zeros(tuple(masu_multi.shape))
for i in range(n-1):
    for j in range(m-1):
        masu_area[j][i] = ((line_x[i+1] - line_x[i]) * (line_y[j+1] - line_y[j])) % 1000000007
print(numpy.sum(numpy.array(masu_multi) * numpy.flipud(masu_area) % 1000000007) % 1000000007)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
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()]

def kk(z):
  zk=[]
  zi=z[0]
  ns=0
  nl=len(z)
  
  for i in z:
    if zi!=i:
      zk.append(abs(i-zi) *(ns*(nl-ns))% (10**9 + 7))
    zi=i
    ns+=1
  return zk

nx=np.array(kk(x), dtype = 'int64').reshape(len(x)-1,1)
ny=np.array(kk(y), dtype = 'int64')
nxy=nx*ny
print((nxy.sum()) % (10**9 + 7))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split(" "));
xs = list(map(int, input().split(" ")));
ys = list(map(int, input().split(" ")));
modula=1000000007

sumx=0;
sumy=0;
answer=0;
for i in range(0, n-1):
    for j in range(i+1, n):
        for k in range(0, m-1):
            for l in range(k+1, m):
                answer = (((xs[j]-xs[i])%modula) * (ys[l]-ys[k])%modula)) % modula

print(answer);

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split(" "));
xs = list(map(int, input().split(" ")));
ys = list(map(int, input().split(" ")));
modula=1000000007

sumx=0;
sumy=0;
answer=0;
for i in range(0, n-1):
    for j in range(i+1, n):
        for i in range(0, m-1):
            for j in range(i+1, m):
                answer = (((xs[j]-xs[i])%modula) * (ys[j]-ys[i])%modula)) % modula

print(answer);

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split(" "));
xs = map(int, input().split(" "));
ys = map(int, input().split(" "));


sumx=0;
for i in range(0, n-1):
    for j in range(i+1, n):
        sumx += (xs[j]-xs[i]) % 1000000007

sumy=0;
for i in range(0, m-1):
    for j in range(i+1, m):
        sumx += (ys[j]-ys[i]) % 1000000007

print((sumx*sumy) % 1000000007)

Submission status: Runtime Error

Solution code:
n = int(input()) - 1
a = sorted(list(input()))
while n:
    c = input()
    a = [i for i in a if i in c]
    n -= 1
print(''.join(a))

Submission status: Runtime Error

Solution code:
a = map(int,input().split(" "))
b = map(int,input().split(" "))
c = map(int,input().split(" "))
bs = sorted(b)
cs = sorted(c)

x = 0

f = range(a[0])
g = range(a[1])

for i in range(a[0]):
    for ii in range(i,a[0]):
        for j in range(a[1]):
            for jj in range(j,a[1]):
                x = x + ((bs[ii] - bs[i]) * (cs[jj] - cs[j]))
                if x > (10**9 + 7):
                    x = x % (10**9 + 7)

ans = x

print(ans)

Submission status: Runtime Error

Solution code:
a = map(int,input().split(" "))
b = map(int,input().split(" "))
c = map(int,input().split(" "))
bs = sorted(b)
cs = sorted(c)

x = 0

f = range(a[0])
g = range(a[1])

for i in range(a[0]):
    for ii in range(i,a[0]):
        for j in range(a[1]):
            for jj in range(j,a[1]):
                x = x + ((bs[ii] - bs[i]) * (cs[jj] - cs[j]))
                print(bs[ii] , bs[i] , cs[jj] , cs[j] , x)
                if x > (10**9 + 7):
                    x = x % (10**9 + 7)

ans = x


print(ans)

Submission status: Runtime Error

Solution code:
a = map(int,input().split())
b = map(int,input().split())
c = map(int,input().split())

d = max(b)- min(b)
e = max(c)- min(c)

f = sum(range(a[0]))
g = sum(range(a[1]))

ans = (d * e * f * g) % (10**9 + 7)

print(ans)

Submission status: Runtime Error

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

d = max(b)- min(b)
e = max(c)- min(c)

f = sum(range(a[0]))
g = sum(range(a[1]))

ans = (d * e * f * g) % (10**9 + 7)

print(ans)

Submission status: Runtime Error

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

d = max(b)- min(b)
e = max(c)- min(c)

f = sum(range(a[0]))
g = sum(range(a[1]))

ans = (d * e * f * g) % (10**9 + 7)



print( (10**9 + 7))

print(ans)