Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())  # 個数
A = np.array([int(i) for i in input().split()], dtype=np.int64)  # 整数

sum_j = [sum(A[i + 1:N]) % 1000000007 for i in range(N - 1)]
mod_A = np.dot(A[0:N-1], sum_j) % 1000000007

print(mod_A)

Fixed submission:
N = int(input())  # 個数
A = [int(i) for i in input().split()]  # 整数

sum_Aij = 0
sum_j = [0] * (N - 1)
for i in range(N - 1, 0, -1):
    sum_j[i - 1] = (A[i] + (0 if i == N - 1 else sum_j[i])) % 1000000007
    sum_Aij += sum_j[i - 1] * A[i - 1] % 1000000007

print(sum_Aij % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())  # 個数
A = np.array([int(i) for i in input().split()], dtype=np.int64)  # 整数

sum_a = 0
for i in range(N-1):
    for j in range(i+1, N):
        sum_a += (A[i] * A[j]) % 1000000007

print(sum_a % 1000000007)

Fixed submission:
N = int(input())  # 個数
A = [int(i) for i in input().split()]  # 整数

sum_Aij = 0
sum_j = [0] * (N - 1)
for i in range(N - 1, 0, -1):
    sum_j[i - 1] = (A[i] + (0 if i == N - 1 else sum_j[i])) % 1000000007
    sum_Aij += sum_j[i - 1] * A[i - 1] % 1000000007

print(sum_Aij % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())  # 個数
A = [int(i) % 1000000007 for i in input().split()]  # 整数

sum_A = 0
for i in range(N-1):
    sum_A += A[i] * sum(A[i+1:N]) % 1000000007

print(sum_A % 1000000007)


Fixed submission:
N = int(input())  # 個数
A = [int(i) for i in input().split()]  # 整数

sum_Aij = 0
sum_j = [0] * (N - 1)
for i in range(N - 1, 0, -1):
    sum_j[i - 1] = (A[i] + (0 if i == N - 1 else sum_j[i])) % 1000000007
    sum_Aij += sum_j[i - 1] * A[i - 1] % 1000000007

print(sum_Aij % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())  # 個数
A = [int(i) for i in input().split()]  # 整数

sum = 0
for i in range(N-1):
    sum_j = 0
    for j in range(i+1, N):
        sum_j += A[j]
    sum += A[i] * sum_j

print(sum % 1000000007)


Fixed submission:
N = int(input())  # 個数
A = [int(i) for i in input().split()]  # 整数

sum_Aij = 0
sum_j = [0] * (N - 1)
for i in range(N - 1, 0, -1):
    sum_j[i - 1] = (A[i] + (0 if i == N - 1 else sum_j[i])) % 1000000007
    sum_Aij += sum_j[i - 1] * A[i - 1] % 1000000007

print(sum_Aij % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())  # 個数
A = [int(i) for i in input().split()]  # 整数

sum = 0
for i in range(N-1):
    for j in range(i+1, N):
        sum += A[i]*A[j]

print(sum % 1000000007)


Fixed submission:
N = int(input())  # 個数
A = [int(i) for i in input().split()]  # 整数

sum_Aij = 0
sum_j = [0] * (N - 1)
for i in range(N - 1, 0, -1):
    sum_j[i - 1] = (A[i] + (0 if i == N - 1 else sum_j[i])) % 1000000007
    sum_Aij += sum_j[i - 1] * A[i - 1] % 1000000007

print(sum_Aij % 1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter 
import sys

N = int(input())
A = list(map(int, input().split()))

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

A.sort()
if A[0] == 1:
    s = 0
else:
    d = prime_factorize(A[0])
    dlist = list(Counter(d).keys())
    for i in dlist:
        for j in range(1,N):
            if A[j] % i != 0:
                break
            if j == N-1:
                print("not coprime")
                sys.exit()


t = 0
cnt = [0] * (10 ** 6)
for i in A:
    a = prime_factorize(i)
    alist = list(Counter(a).keys())
    for j in alist:
        cnt[j] += 1
        if cnt[j] >= 2:
            t = 1
            break
    if t == 1:
        break

if t == 0:
    print("pairwise coprime")
else:
    print("setwise coprime")

    
    


Fixed submission:
from collections import Counter 
import sys

N = int(input())
A = list(map(int, input().split()))

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

A.sort()
if A[0] != 1:
    d = prime_factorize(A[0])
    dlist = list(Counter(d).keys())
    for i in dlist:
        for j in range(1,N):
            if A[j] % i != 0:
                break
            if j == N-1:
                print("not coprime")
                sys.exit()


cnt = [0] * (10 ** 6)
for i in A:
    a = prime_factorize(i)
    alist = list(Counter(a).keys())
    for j in alist:
        cnt[j] += 1
        if cnt[j] >= 2:
            print("setwise coprime")
            sys.exit()

print("pairwise coprime")
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
P = [0] + list(map(int, input().split()))
C = [0] + list(map(int, input().split()))

cnt = [1] * (N+1)
retsu = []
for i in range(1,N+1):
    idx = i
    r = []
    for _ in range(N):
        if cnt[idx] == 0:
            break
        r.append(C[P[idx]])
        cnt[idx] = 0
        idx = P[idx]
    if r:
        retsu.append(r)

ans = -1 * (10 ** 9) - 1
for i in retsu:
    s = sum(i)
    l = len(i)
    plus = 0
    if s <= 0 or K <= l:
        pass
    else:
        plus += s * (K // l)
        if K % l == 0:
            plus -= s
    K %= l
    if K == 0:
        K = l
    
    moto = i + i
    point = [[0] * N for _ in range(l+K-1)]
    kari = -1 * (10 ** 9) - 1
    for i in range(l+K-1):
        for j in range(N):
            if i == j:
                point[i][j] = moto[i]
            elif i - j >= K or i < j:
                continue
            else:
                point[i][j] = moto[i] + point[i-1][j]
            kari = max(kari, point[i][j])
    ans = max(ans, plus + kari)
print(ans)

Fixed submission:
N, KK = map(int, input().split())
P = [0] + list(map(int, input().split()))
C = [0] + list(map(int, input().split()))

cnt = [1] * (N+1)
retsu = []
for i in range(1,N+1):
    idx = i
    r = []
    for _ in range(N):
        if cnt[idx] == 0:
            break
        r.append(C[P[idx]])
        cnt[idx] = 0
        idx = P[idx]
    if r:
        retsu.append(r)

ans = -1 * (10 ** 10)
for z in retsu:
    K = KK
    s = sum(z)
    l = len(z)
    if K <= l:
        plus = 0
    elif s <= 0:
        plus = 0
        K = l
    else:
        plus = s * (K // l)
        if K % l == 0:
            plus -= s
    K %= l
    if K == 0:
        K = l
    
    moto = z + z
    point = [[0] * l for _ in range(l+K-1)]
    kari = -1 * (10 ** 10)
    for i in range(l+K-1):
        for j in range(l):
            if i == j:
                point[i][j] = moto[i]
            elif i - j >= K or i < j:
                continue
            else:
                point[i][j] = moto[i] + point[i-1][j]
            kari = max(kari, point[i][j])
    ans = max(ans, plus + kari)
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())

s = 1
while N > 26 ** s:
    N -= 26 ** s
    s += 1

ans = ""
N -= 1
for i in range(s):
    ans += chr(ord("a") + ord(N % 26))
    N = N // 26

print(ans[::-1])

Fixed submission:
N = int(input())

s = 1
while N > 26 ** s:
    N -= 26 ** s
    s += 1

ans = ""
N -= 1
for i in range(s)[::-1]:
    a = N // (26 ** i)
    N -= (26 ** i) * a
    ans += chr(ord("a") + a)
    
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())

x = [list(map(int, input().split())) for _ in range(N)]

y = []
for i,j in x:
    y.append([j, i])

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

mini = 10 ** 10
maxi = 0
if N % 2 == 1:
    idx = (N+1) // 2 - 1
    for i,j in x[idx:]:
        mini = min(mini,j)
    for i,j in y[idx:]:
        maxi = max(maxi, j)
    if maxi <= mini:
        ans = y[idx][0] - x[idx][0] + 1 
    else:
        ams = y[idx][0] - maxi +mini - x[idx][0] + 2 
        
else:
    idx = N // 2
    for i,j in x[idx:]:
        mini = min(mini,j)
    for i,j in y[idx:]:
        maxi = max(maxi, j)
    if maxi + y[idx-1][1] <= mini + x[idx-1][1]:
        ans = y[idx][0]+y[idx-1][0] - x[idx][0]-x[idx-1][0] + 1
    else:
        ans = y[idx][0]+y[idx-1][0] - maxi - y[idx-1][1] +mini + x[idx-1][1] - x[idx][0]-x[idx-1][0]

print(ans)

Fixed submission:
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N)]

ba = []
for i, j in ab:
    ba.append([j, i])

ab.sort()
ba.sort(reverse = True)

if N % 2 == 1:
    n = (N+1) // 2 - 1
    ans = ba[n][0] - ab[n][0] + 1
    
else:
    n = N // 2 - 1
    ans = (ba[n][0] + ba[n+1][0]) - (ab[n][0] + ab[n+1][0]) + 1

print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())

x = [list(map(int, input().split())) for _ in range(N)]

y = []
for i,j in x:
    y.append([j, i])

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

mini = 10 ** 10
maxi = 0
if N % 2 == 1:
    idx = (N+1) // 2 - 1
    for i,j in x[idx:]:
        mini = min(mini,j)
    for i,j in y[idx:]:
        maxi = max(maxi, j)
    if maxi <= mini:
        ans = y[idx][0] - x[idx][0] + 1 
    else:
        ams = y[idx][0] - maxi +mini - x[idx][0] + 2 
        
else:
    idx = N // 2
    for i,j in x[idx:]:
        mini = min(mini,j)
    for i,j in y[idx:]:
        maxi = max(maxi, j)
    if maxi + y[idx-1][1] <= mini + x[idx-1][1]:
        ans = y[idx][0]+y[idx-1][0] - x[idx][0]-x[idx-1][0] + 1
    else:
        ans = y[idx][0]+y[idx-1][0] - maxi - y[idx-1][1] +mini + x[idx-1][1] - x[idx][0]-x[idx-1][0]

print(ans)

Fixed submission:
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N)]

ba = []
for i, j in ab:
    ba.append([j, i])

ab.sort()
ba.sort(reverse = True)

if N % 2 == 1:
    n = (N+1) // 2 - 1
    ans = ba[n][0] - ab[n][0] + 1
    
else:
    n = N // 2 - 1
    ans = (ba[n][0] + ba[n+1][0]) - (ab[n][0] + ab[n+1][0]) + 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M, K = map(int, input().split())

mod = 998244353
f = [1]
for i in range(1,N+1):
    f.append((f[-1] * i) % mod)
def comb(n,r):
    return f[n] * (pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod) % mod

ans = 0

for i in range(K+1):
    k = ((M * pow((M-1), N-1-i, mod)) % mod) * comb(N-1,i)
    k %= mod
    ans += k
    ans %= mod
    
print(ans)
    
    
    


Fixed submission:
N, M, K = map(int, input().split())

mod = 998244353
f = [1]
for i in range(1,N+1):
    f.append((f[-1] * i) % mod)
def comb(n,r):
    return f[n] * (pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod) % mod

ans = 0

for i in range(K+1):
    k = ((M * pow((M-1), N-1-i, mod)) % mod) * comb(N-1,i)
    k %= mod
    ans += k
    ans %= mod
    
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

cnt = [0] * (2*(10 ** 5) + 10) 
for i in range(N):
    if A[i]+1 >= 2*(10 ** 5):
        continue
    cnt[A[i]+i] += 1

ans = 0
for i in range(N)[1:]:
    if A[i]-i >= 0:
        continue
    ans += cnt[abs(A[i]-i)]

print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

cnt = [0] * (2*(10 ** 5) + 10) 
for i in range(N):
    if A[i]+i >= 2*(10 ** 5):
        continue
    cnt[A[i]+i] += 1

ans = 0
for i in range(N)[1:]:
    if A[i]-i >= 0:
        continue
    ans += cnt[abs(A[i]-i)]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()

S = S[::-1]
N = len(S)
cnt = [0] * 2019
mod = 2019
m = 0
cnt[0] += 1
for i in range(N):
    s = int(S[i]) * ((10 ** i) % mod)
    s %= mod
    m += s
    m %= mod
    cnt[m] += 1


ans = 0
for i in cnt:
    ans += (i * (i-1)) // 2

print(ans)

Fixed submission:
S = input()

S = S[::-1]
N = len(S)
cnt = [0] * 2019
mod = 2019
m = 0
cnt[0] += 1
for i in range(N):
    s = int(S[i]) * (pow(10, i, mod))
    s %= mod
    m += s
    m %= mod
    cnt[m] += 1


ans = 0
for i in cnt:
    ans += (i * (i-1)) // 2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd

K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1, K+1):
        t = gcd(i,j)
        for k in range(1, K+1):
            ans += gcd(k,t)

print(ans)

Fixed submission:
from fractions import gcd

K = int(input())
ans = (K * (K+1)) // 2

for i in range(1,K-1):
    for j in range(i+1,K):
        t = gcd(i,j)
        for k in range(j+1,K+1):
            ans += gcd(k,t) * 6

for i in range(1,K):
    for j in range(i+1,K+1):
        ans += gcd(i,j) * 6
    
print(ans)
Buggy python submission (verdict: Runtime Error):
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse = True)
q.sort(reverse = True)
r.sort()

p = p[:X]
q = q[:Y]
z = []

while len(r) != 0 and r[-1] > min(p[-1], q[-1]):
    k = r.pop()
    if p[-1] < q[-1]:
        del p[-1]
    else:
        del q[-1]
    z.append(k)   

print(sum(p) + sum(q) + sum(z))

Fixed submission:
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse = True)
q.sort(reverse = True)
r.sort()

p = p[:X]
a = q[:Y] + p
z = []
a.sort(reverse = True)

while len(a) != 0 and len(r) != 0 and r[-1] > a[-1]:
    k = r.pop()
    del a[-1]
    z.append(k)   

print(sum(a) + sum(z))
Buggy python submission (verdict: Time Limit Exceeded):
H, W, K = map(int, input().split())
S = [list(input()) for i in range(H)]

fans = 10 ** 5
for i in range(1 << (H-1)):
    slc = []
    scnt = 1
    ans = 0
    switch = 1
    for j in range(H-1):
        if (i >> j) % 2 == 1:
            slc.append(j+1)
            scnt += 1
            ans += 1
    slc.append(H)
    stock = [0] * scnt 
    for j in range(W):
        kari = [0] * scnt
        ss = slc[0]
        idx = 0
        for k in range(H):
            if ss == k:
                idx += 1
                ss = slc[idx]
            if S[k][j] == "1":
                kari[idx] += 1
            if kari[idx] > K:
                switch = 0
                break
        if switch == 0:
            break
        for k in range(scnt):
            if stock[k] + kari[k] <= K:
                stock[k] += kari[k]
            else:
                stock = kari
                ans += 1
                break
    if switch == 1:
        fans = min(fans, ans)

print(fans)

Fixed submission:
H, W, K = map(int, input().split())
S = [list(input()) for i in range(H)]

fans = 10 ** 5
for i in range(1 << (H-1)):
    slc = []
    scnt = 1
    ans = 0
    switch = 1
    for j in range(H-1):
        if (i >> j) % 2 == 1:
            slc.append(j+1)
            scnt += 1
            ans += 1
    slc.append(H)
    stock = [0] * scnt 
    for j in range(W):
        kari = [0] * scnt
        ss = slc[0]
        idx = 0
        for k in range(H):
            if ss == k:
                idx += 1
                ss = slc[idx]
            if S[k][j] == "1":
                kari[idx] += 1
            if kari[idx] > K:
                switch = 0
                break
        if switch == 0:
            break
        for k in range(scnt):
            if stock[k] + kari[k] <= K:
                stock[k] += kari[k]
            else:
                stock = kari
                ans += 1
                break
    if switch == 1:
        fans = min(fans, ans)

print(fans)
Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int, input().split())

mod = 10 ** 9 + 7
f = [1]
for i in range(1,2*(10 ** 9)+1):
    f.append((f[-1] * i) % mod)
def comb(n,r):
    return f[n] * (pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod) % mod


ans = pow(2, n, mod) - 1 - comb(n, a) - comb(n, b)
if ans < 0:
    ans += mod

print(ans)

Fixed submission:
n, a, b = map(int, input().split())

mod = 10 ** 9 + 7
f = [1]
for i in range(1,2*(10 ** 5)+1):
    f.append((f[-1] * i) % mod)
def comb(n,r):
    z = 1
    for i in range(n-r+1, n+1):
        z *= i
        z %= mod
    return (z * pow(f[r], mod-2, mod)) % mod

ans = (pow(2, n, mod) - 1 - comb(n, a) - comb(n, b)) % mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())
a = []
b = []
for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

INF = float("inf")
    
dp = [[INF] * (1+10**4) for i in range(1+10**3)]


dp[0][0] = 0

for i in range(n):
    for j in range(h+1):
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        dp[i+1][min(h, j+a[i])] = min(dp[i+1][min(h, j+a[i])], dp[i+1][j] + b[i])

print(dp[n][h])


Fixed submission:
h, n = map(int, input().split())
a = []
b = []
for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

INF = float("inf")
    
dp = [[INF] * (1+10**4) for i in range(1+10**3)]


dp[0][0] = 0

for i in range(n):
    for j in range(h+1):
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        dp[i+1][min(h, j+a[i])] = min(dp[i+1][min(h, j+a[i])], dp[i+1][j] + b[i])

print(dp[n][h])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from fractions import gcd
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))


mod = 10 ** 9 + 7

l = 1
for i in A:
    l = (l * i) // gcd(l,i)
    
ans = 0
for i in range(N):
    ans += (l // A[i]) % mod
    ans %= mod
    
print(ans)

Fixed submission:
import sys
from fractions import gcd
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))


mod = 10 ** 9 + 7

l = 1
ans = 0
for i in A:
    l = (l * i) // gcd(l,i)
    ans += pow(i, mod-2, mod)
    ans %= mod
l %= mod
ans = (l * ans) % mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from fractions import gcd
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))


mod = 10 ** 9 + 7

l = 1
for i in A:
    l = (l * i) // gcd(l,i)
    
ans = 0
for i in range(N):
    ans += l // A[i]
    ans %= mod
    
print(ans)

Fixed submission:
import sys
from fractions import gcd
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))


mod = 10 ** 9 + 7

l = 1
ans = 0
for i in A:
    l = (l * i) // gcd(l,i)
    ans += pow(i, mod-2, mod)
    ans %= mod
l %= mod
ans = (l * ans) % mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

def gcd(a, b):
    while b :
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 10 ** 9 + 7

l = 1
for i in A:
    l = lcm(l,i)
    
ans = 0
for i in range(N):
    ans += l // A[i]
    ans %= mod
    
print(ans)

Fixed submission:
import sys
from fractions import gcd
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))


mod = 10 ** 9 + 7

l = 1
ans = 0
for i in A:
    l = (l * i) // gcd(l,i)
    ans += pow(i, mod-2, mod)
    ans %= mod
l %= mod
ans = (l * ans) % mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

def gcd(a, b):
    while b :
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 10 ** 9 + 7

l = 1
for i in A:
    l = lcm(l,i)
    
ans = 0
for i in range(N):
    ans += l // A[i]
    ans %= mod
    
print(ans)

Fixed submission:
import sys
from fractions import gcd
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))


mod = 10 ** 9 + 7

l = 1
ans = 0
for i in A:
    l = (l * i) // gcd(l,i)
    ans += pow(i, mod-2, mod)
    ans %= mod
l %= mod
ans = (l * ans) % mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
x = list(map(int, input().split()))

mod = 10 ** 9 + 7
f = [1]
for i in range(1,N+1):
    f.append((f[-1] * i) % mod)
def comb(n,r):
    return f[n] * (pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod) % mod

ans = 0
l = [0] + [(((comb(N-1,2+i) * f[N-(3+i)]) % mod) * f[i]) % mod for i in range(N-2)] + [f[N-2]]


for i in range(N-1):
    for j in range(i+1,N):
        ans += (l[j-i] * (x[j] - x[i])) % mod
        ans %= mod
        if j == N - 1:
            l[j-i-1] = l[j-i-1] + l[j-i]

print(ans)

Fixed submission:
N = int(input())
x = list(map(int, input().split()))

mod = 10 ** 9 + 7

c = [1]
for i in range(1,N-1):
    c.append(c[i-1]+pow(i+1,mod-2,mod))

ans = 0
for i in range(N-1):
    ans += (c[i] * (x[i+1] - x[i])) % mod
    ans %= mod
    
for i in range(1,N):
    ans *= i
    ans %= mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

mod = 10 ** 9 + 7
s = [0] * 60

for i in range(N):
    for j in range(60):
        if (A[i] >> j) & 1 == 1:
            s[j] += 1

ans = 0            
for i in range(60):
    ans += (((N - s[i]) * s[i]) << i) % mod
    ans %= mod
    
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

mod = 10 ** 9 + 7
s = [0] * 60

for i in range(N):
    for j in range(60):
        if (A[i] >> j) & 1 == 1:
            s[j] += 1

ans = 0            
for i in range(60):
    ans += (((N - s[i]) * s[i]) << i) % mod
    ans %= mod
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
N = int(input())
S = input()

a = []
for i in range(10):
    a.append(str(i))
    
ans = 0    
s = 0
for i in a:
    for j in a:
        for k in a:
            for l in range(N):
                if S[l] == i and s == 0:
                    s = 1
                elif S[l] == j and s == 1:
                    s = 2
                elif S[l] == k and s == 2:
                    ans += 1
                    break
            s = 0
            
print(ans)

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
S = input()

a = []
for i in range(10):
    a.append(str(i))
    
ans = 0    
s = 0
for i in a:
    for j in a:
        for k in a:
            for l in range(N):
                if S[l] == i and s == 0:
                    s = 1
                elif S[l] == j and s == 1:
                    s = 2
                elif S[l] == k and s == 2:
                    ans += 1
                    break
            s = 0
            
print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate

H, W, K = map(int, input().split())
s = [input() for _ in range(H)]

ans = []
acc = 0
l = 0
for i in s:
    cnt = i.count("#")
    if cnt == 0:
        if not ans:
            l += 1
        else:
            ans.append(ans[-1])
    else:
        k = [0] * W
        for j in range(W):
            if i[j] == "#":
                k[j] = 1
        k = list(accumulate(k))
        for j in range(W):
            if k[j] == 0:
                k[j] = 1
            k[j] += acc
        ans.append(k)
    if l >= 1:
        for _ in range(l):
            ans.append(ans[-1])
        l = 0
    acc += cnt
        
for i in ans:
    print(" ".join(map(str, i)))

Fixed submission:
from itertools import accumulate

H, W, K = map(int, input().split())
s = [input() for _ in range(H)]

ans = []
acc = 0
l = 0
for i in s:
    cnt = i.count("#")
    if cnt == 0:
        if not ans:
            l += 1
        else:
            ans.append(ans[-1])
    else:
        k = [0] * W
        for j in range(W):
            if i[j] == "#":
                k[j] = 1
        k = list(accumulate(k))
        for j in range(W):
            if k[j] == 0:
                k[j] = 1
            k[j] += acc
        ans.append(k)
    if ans and l >= 1 :
        for _ in range(l):
            ans.append(ans[-1])
        l = 0
    acc += cnt
        
for i in ans:
    print(" ".join(map(str, i)))