Problem p03762 (python)

Fixed submission:
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[-2::-1]

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

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

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

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


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

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

print ((X_sum * Y_sum) % MOD)

Buggy submission (verdict: Runtime Error):
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)

Buggy submission (verdict: Runtime Error):
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)

Buggy submission (verdict: Runtime Error):
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)

Buggy submission (verdict: Runtime Error):
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)