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: Time Limit Exceeded

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 - 3, 0, -2):
    N.append(N[-1] + i)
    # N.append((N[i] + (n - 1 - 2 * (i + 1))) % MOD)

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

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

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

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

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

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


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

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

print ((X_sum * Y_sum) % MOD)

Submission status: Time Limit Exceeded

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]

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

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

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


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

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

print ((X_sum * Y_sum) % MOD)

Submission status: Time Limit Exceeded

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

a = [abs(x[x1]-x[x2]) for x1 in range(n) for x2 in range(x1+1,n)]
b = [abs(y[x1]-y[x2]) for x1 in range(m) for x2 in range(x1+1,m)]

print (sum(x * y for x in a for y in b) % (10 ** 9 +7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

ans=0
for i in lx:
    for j in ly:
        ans+=i*j
        ans%=mod
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import os
import sys

import numpy as np

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

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

MOD = 10 ** 9 + 7

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


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

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

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

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

    return _ModInt


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

#  あるエリアが何回カウントされるか
xc = np.cumsum([MI(x) for x in range(len(X), -len(X), -2)])
yc = np.cumsum([MI(y) for y in range(len(Y), -len(Y), -2)])

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

Submission status: Time Limit Exceeded

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

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

print(x*y%modulo)

Submission status: Time Limit Exceeded

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

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

print(x*y%modulo)

Submission status: Time Limit Exceeded

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)
    ans += S
print(ans % p)

Submission status: Time Limit Exceeded

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)

Submission status: Time Limit Exceeded

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
S = [[(X[i + 1] - X[i]) * (Y[j + 1] - Y[j]) for j in range(m - 1)] for i in range(n - 1)]
for i in range(n - 1):
  for j in range(m - 1):
    S[i][j] *= (n - i - 1) * (i + 1)
    #S[i][j] %= p
    S[i][j] *= (m - j - 1) * (j + 1)
    #S[i][j] %= p
print(sum([sum(s) for s in S]) % p)

Submission status: Time Limit Exceeded

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
S = [[(X[i + 1] - X[i]) * (Y[j + 1] - Y[j]) for j in range(m - 1)] for i in range(n - 1)]
for i in range(n - 1):
  for j in range(m - 1):
    S[i][j] *= (n - i - 1) * (i + 1)
    S[i][j] %= p
    S[i][j] *= (m - j - 1) * (j + 1)
    S[i][j] %= p
print(sum([sum(s) for s in S]) % p)

Submission status: Time Limit Exceeded

Solution code:
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+=( len(x[:i])-len(x[i+1:]) )*x[i]

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


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

Submission status: Time Limit Exceeded

Solution code:
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):
    for j in range(i+1,n):
        xrange=xrange+(x[j]-x[i])
yrange=0
for i in range(m):
    for j in range(i+1,m):
        yrange=yrange+(y[j]-y[i])
ans=(xrange*yrange)%mod
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,m=[int(x) for x in input().split()]
X=[int(x) for x in input().split()]
Y=[int(x) for x in input().split()]
from itertools import product,combinations
mod=10**9+7
ans=0
for x,y in product(combinations(X,2),combinations(Y,2)):
    ans=(ans+(x[1]-x[0])*(y[1]-y[0]))%mod
print(ans)

Submission status: Time Limit Exceeded

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

mode = 10**9+7
xlist = [ [n-1-j for j in range(n-1-i) ] for i in range(n-1)]
ylist = [ [m-1-j for j in range(m-1-i) ] for i in range(m-1)]
s = 0
for i in range(n-1):
    for j in xlist[i] :
        for k in range(m-1):
            for l in ylist[k] :
                #print(i,j,k,l)
                s += ((x[j] - x[i])*(y[l]-y[k]))
print(s%mode)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

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

sumx = sumx % modula;
sumy = sumy % modula;
print((sumx*sumy) % modula)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
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,n-1):
  for j in range (i+1,n):
    yoko+=x[j]-x[i]
for i in range (0,m-1):
  for j in range (i+1,m):
    tate+=y[j]-y[i]

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
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)-1):
  for j in range (i+1,len(x)):
    yoko+=x[j]-x[i]
for i in range (0,len(y)-1):
  for j in range (i+1,len(y)):
    tate+=y[j]-y[i]

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

Submission status: Time Limit Exceeded

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


s=0;
#xの左位置
for ix1 in range(x-1):
    #xの右位置
    for ix2 in range(ix1+1,x):
        wide = xl[ix2] - xl[ix1]
        #yの下位置
        for iy1 in range(y-1):
            #xの右位置
            for iy2 in range(iy1+1,y):
                height = yl[iy2] - yl[iy1]
                s += wide * height
                #print(str(wide)+' '+str(height)+' '+str(s)+';  '+str(yl[iy1])+' '++str(iy2))

ans = s % (10**9 + 7)
print(ans)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

height = []
for i in range(len(y)-1):
    for j in range(i+1,len(y)):
        height.append(abs(int(y[i])-int(y[j])))

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

Submission status: Time Limit Exceeded

Solution code:
a = list(map(int,input().split(" ")))
b = list(map(int,input().split(" ")))
c = list(map(int,input().split(" ")))
bs = b
cs = 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 = abs(x)
 
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a = list(map(int,input().split(" ")))
b = list(map(int,input().split(" ")))
c = list(map(int,input().split(" ")))
bs = b
cs = 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: Time Limit Exceeded

Solution code:
a = list(map(int,input().split(" ")))
b = list(map(int,input().split(" ")))
c = list(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: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
x = []
y = []
raw_input()
x = map(int, raw_input().strip().split())
y = map(int, raw_input().strip().split())
s = 0
for i in range(0, len(x) - 1):
    for j in range(i, len(x)):
        for k in range(0, len(y) - 1):
            for l in range(k, len(y)):
                s += (x[j] - x[i]) * (y[l] - y[k])
print s % (10 ** 9 + 7)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(N):
    for j in range(M):
        pos = i * j + (N - i - 1) * (M - j - 1)
        neg = i * (M - j - 1) + (N - i - 1) * j
        SUM = (SUM + X[i] * Y[j] * (pos - neg)) % MOD
print(SUM)

Submission status: Time Limit Exceeded

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

for i in range(N):
    for j in range(M):
        for k in range(i, N):
            for l in range(j, M):
                SUM = (SUM + (X[k] - X[i]) * (Y[l] - Y[j])) % MOD
print(SUM)

Submission status: Time Limit Exceeded

Solution code:
import itertools

def aaa(l):
    for i in xrange(len(l)-1):
        for j in xrange(i+1, len(l)):
            yield (l[i],l[j])


n,m=map(int,raw_input().split())
X=map(int,raw_input().split())
Y=map(int,raw_input().split())
X.sort()
Y.sort()
r=0
for xa,xb in aaa(X):
    for ya,yb in aaa(Y):
        r=(r+abs(xa-xb)*abs(ya-yb))%(1000000000+7)
print r

Submission status: Time Limit Exceeded

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

sum = 0

for i in range(n):
    for j in range(n):
            if i>j:
                for p in range(m):
                    for q in range(m):
                            if p > q:
                                sum += (x[i]-x[j])*(y[p]-y[q])
print sum % (10**9+7)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m = input().split()
n = int(n)
m = int(m)
x_list =list()
y_list = list()

x_list= input().split()
y_list= input().split()

for i in range(n):
    x_list[i] = int(x_list[i])

for i in range(m):
    y_list[i] = int(y_list[i])

all_menseki = 0
waru = 10**9 + 7
amari = 0
for x_min_i,x_min in enumerate(x_list[:-1]):
    for x_max in x_list[x_min_i:]:
        for y_min_i,y_min in enumerate(y_list[:-1]):
            for y_max in y_list[y_min_i:]:
                x = x_max - x_min
                y = y_max - y_min
                amari = (amari + (x % waru) * (y % waru)) % waru    

print(amari)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, raw_input().split())
X = map(int, raw_input().split())
Y = map(int, raw_input().split())

mdl = 1000000007

numx = n - 1
numy = m - 1

A = 0
incrx = numx
multx = 0
for ix in xrange(numx/2 + numx%2):
    multx += incrx
    multy = 0
    incry = numy
    for iy in xrange(numy/2 + numy%2):
        multy += incry
        ly = (Y[-1 - iy] - Y[iy])
        lx = (X[-1 - ix] - X[ix])
        A += (((lx * ly)%mdl) * incrx * incry)%mdl
        incry -= 2
    incrx -= 2
print A % mdl

Submission status: Time Limit Exceeded

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

sum = 0

for i in range(n-1):
    for j in range(n):
        for k in range(n):
            if j-k == i+1:
                for p in range(m-1):
                    for q in range(m):
                        for r in range(m):
                            if q-r == p+1:
                                sum += (x[j]-x[k])*(y[q]-y[r])
print sum % (10**9+7)

Submission status: Time Limit Exceeded

Solution code:
nm = input().split()
n = int(nm[0])
m = int(nm[1])
X = input().split()
Y = input().split()
X = map(int, X)
X = list(X)
Y = map(int, Y)
Y = list(Y)
T = 0
S = 0
for i in range(n - 1):
	x1 = X[i]
	x2 = X[i + 1]
	for j in range(m - 1):
		s = (x2 - x1) * (Y[j + 1] - Y[j])
		s = (j + 1) * (m - j - 1) * s
		S += s
	T += (i + 1) * (n - i - 1) * S
	S = 0
ans = T % 1000000007
print(ans)

Submission status: Time Limit Exceeded

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

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

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

area = 0
for i in range(n):
    for j in range(i,n):
        for k in range(m):
            for l in range(k,m):
                area += (x[j]-x[i])*(y[l]-y[k])
                area = area%1000000007
print(area)

Submission status: Time Limit Exceeded

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):
    tmp_x = x[i]
    sum_x += sum(list(filter(lambda ele: ele > 0, (map(lambda ele: ele - tmp_x, x)))))

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

ans = sum_x * sum_y

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

Submission status: Time Limit Exceeded

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

area = 0
r = 10**9+7
for xi in itertools.combinations(x,2):
    for yi in itertools.combinations(y,2):
        area = (area + (xi[1]-xi[0])*(yi[1]-yi[0]))%r

print(area)

Submission status: Time Limit Exceeded

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):
    tmp_x = x[i]
    l_x = list(filter(lambda ele: ele > 0, (map(lambda ele: ele - tmp_x, x))))
    sum_x += sum(l_x)

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

ans = sum_x * sum_y

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

Submission status: Time Limit Exceeded

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

t = input().split(" ")
x = []
for i in range(n):
    x.append(int(t[i]))
    
t = input().split(" ")
y = []
for i in range(m):
    y.append(int(t[i]))

r = 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):
                r += (x[j] - x[i]) * (y[l] - y[k])
print(r % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
strs = input().split()
n = int(strs[0])
m = int(strs[1])

x_strs = input().split()
y_strs = input().split()

x_list = []
y_list = []
width_list = []
height_list = []

for i in range(n):
    x = int(x_strs[i])
    x_list.append(x)
    for x_ in x_list:
        width_list.append(x - x_)

for i in range(m):
    y = int(y_strs[i])
    y_list.append(y)
    for y_ in y_list:
        height_list.append(y - y_)

sum_squire = 0

for w in width_list:
    for h in height_list:
        sum_squire += w * h

ans = sum_squire % (10**9 + 7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, raw_input().split())
X = map(int, raw_input().split())
Y = map(int, raw_input().split())

mdl = 1000000007

numx = n - 1
numy = m - 1

A = 0
incrx = numx
multx = 0
for ix in xrange(numx):
    multx += incrx
    multy = 0
    incry = numy
    for iy in xrange(numy):
        multy += incry
        ly = (Y[iy + 1] - Y[iy])
        lx = (X[ix + 1] - X[ix])
        A += (((lx * ly)%mdl) * multx * multy)%mdl
        incry -= 2
    incrx -= 2
print A % mdl

Submission status: Time Limit Exceeded

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

xd = int(x[-1]) - int(x[0])
yd = int(y[-1]) - int(y[0])
# print(xd * yd)
# print(len(x) - 1, len(y) - 1)
# print("-----")

# cx = 1
# cy = 1
calced = []
x = list(map(int, x))
y = list(map(int, y))
for cy in range(1, len(y)):
    for cx in range(1, len(x)):
        for targety in y[cy:]:
            for targetx in x[cx:]:
                # print(x[cx - 1], y[cy - 1], targetx, targety)
                calced.append((targetx - x[cx - 1]) * (targety - y[cy - 1]))
# print(calced)
print(sum(calced) % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
n,m = input().split()
n = int(n)
m = int(m)
x_list =list()
y_list = list()

x_list= input().split()
y_list= input().split()

all_menseki = 0
waru = 10**9 + 7
amari = 0
for x_min_i,x_min in enumerate(x_list[:-1]):
    for x_max in x_list[x_min_i:]:
        for y_min_i,y_min in enumerate(y_list[:-1]):
            for y_max in y_list[y_min_i:]:
                x = int(x_max) - int(x_min)
                y = int(y_max) - int(y_min)
                amari = (amari + (x % waru) * (y % waru)) % waru    

print(amari)

Submission status: Time Limit Exceeded

Solution code:
strs = input().split()
n = int(strs[0])
m = int(strs[1])

x_strs = input().split()
y_strs = input().split()

x_list = []
y_list = []

for i in range(n):
    x_list.append(int(x_strs[i]))

for i in range(m):
    y_list.append(int(y_strs[i]))

width_list = []
height_list = []
for i_start in range(n):
    for i_end in range(i_start, n):
        width_list.append(x_list[i_end] - x_list[i_start])

for i_start in range(m):
    for i_end in range(i_start, m):
        height_list.append(y_list[i_end] - y_list[i_start])

sum_squire = 0

for w in width_list:
    for h in height_list:
        sum_squire += w * h

ans = sum_squire % (10**9 + 7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
nm = input().split()
n = int(nm[0])
m = int(nm[1])
X = input().split()
Y = input().split()
X = map(int, X)
X = list(X)
Y = map(int, Y)
Y = list(Y)
S = 0
for i in range(n - 1):
	x1 = X[i]
	x2 = X[i + 1]
	for j in range(m - 1):
		s = (x2 - x1) * (Y[j + 1] - Y[j])
		s = (i + 1) * (n - i - 1) * (j + 1) * (m - j - 1) * s
		S += s
ans = S % 1000000007
print(ans)

Submission status: Time Limit Exceeded

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

x_ = []
for i in range(n-1):
    for j in range(i+1,n):
        x_.append( int(x[j])-int(x[i]) )
y_ = []
for i in range(m-1):
    for j in range(i+1,m):
        y_.append( int(y[j])-int(y[i]) )

area = [a*b for a in x_ for b in y_]
print( sum(area)%(10**9+7) )

Submission status: Time Limit Exceeded

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):
    tmp_x = x[i]
    l_x_1 = list(map(lambda ele: ele - tmp_x, x))
    l_x_2 = list(filter(lambda ele: ele > 0, l_x_1))
    sum_x += sum(l_x_2)

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

ans = sum_x * sum_y

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

Submission status: Time Limit Exceeded

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

s = 0

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

s %= (10**9 + 7)

print(s)

Submission status: Time Limit Exceeded

Solution code:
nm = input().split()
n = int(nm[0])
m = int(nm[1])
X = input().split()
Y = input().split()
X = map(int, X)
X = list(X)
Y = map(int, Y)
Y = list(Y)
S = 0
for i in range(n - 1):
	for j in range(m - 1):
		s = (X[i + 1] - X[i]) * (Y[j + 1] - Y[j])
		s = (i + 1) * (n - i - 1) * (j + 1) * (m - j - 1) * s
		S += s
ans = S % 1000000007
print(ans)

Submission status: Time Limit Exceeded

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 = 0
    for i in range(len(A)):
        for j in range(i+1, len(A)):
            l = A[j] - A[i]
            all += l
    return all

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

Submission status: Time Limit Exceeded

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

import os
import sys
import math
import numpy as np

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


# 1 つの最小長方形は (n-1)*(m-1) 回加算される

S = 0
mod = 10 ** 9 + 7

for x in range(n-1):
	for y in range(m-1):
		var = (X[x+1]-X[x]) * (Y[y+1]-Y[y])
		# print(var)
		x_times = (x+1) * (n-x-1)
		y_times = (y+1) * (m-y-1)

		S += ((var * x_times * y_times) % mod)


print(S%mod)

Submission status: Time Limit Exceeded

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

print(ans%1000000007)

Submission status: Time Limit Exceeded

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

import os
import sys
import math
import numpy as np

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


# 1 つの最小長方形は (n-1)*(m-1) 回加算される

S = 0
for x in range(n-1):
	for y in range(m-1):
		var = (X[x+1]-X[x]) * (Y[y+1]-Y[y])
		# print(var)
		x_times = (x+1) * (n-x-1)
		y_times = (y+1) * (m-y-1)

		S += (var * x_times * y_times)

mod = 10 ** 9 + 7
print(S%mod)

Submission status: Time Limit Exceeded

Solution code:
nm = str(input()).split(' ')
xAry = str(input()).split(' ')
yAry = str(input()).split(' ')

result = 0

for ms in range(int(nm[1])-1):
    for me in range(ms+1,int(nm[1])):
        for ns in range(int(nm[0])-1):
            for ne in range(ns+1,int(nm[0])):
                #print('%s,%s,%s,%s'%(ms,me,ns,ne))
                result += (int(yAry[me])-int(yAry[ms]))*(int(xAry[ne])-int(xAry[ns]))

result %= 1000000007

print(result)

Submission status: Time Limit Exceeded

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

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

print(result % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
nm = input().split()
n = int(nm[0])
m = int(nm[1])
X = input().split()
Y = input().split()
X = map(int, X)
X = list(X)
Y = map(int, Y)
Y = list(Y)
S = 0
for i in range(n):
	for j in range(n - i):
		for k in range(m):
			for l in range(m - k):
				S += (X[i + j] - X[i]) * (Y[k + l] - Y[k])
ans = S % 1000000007
print(ans)