Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for i in range(n)]
ans = 0

ss = ['']*n
for i in range(n):
    ss[i] = sorted(s[i])

for i in range(n-1):
    for v in range(i+1,n):
        if ss[i] == ss[v]:
            ans += 1

print(ans)

Fixed submission:
n = int(input())
s = [input() for i in range(n)]

# ソートしたsリスト作成（ss）
ss = ['']*n
for i in range(n):
    ss[i] = ''.join(sorted(s[i]))
    
# ssのsetを作成して重複要素削除(sss)
sss = list(set(ss))

# sssから辞書作成
dict_ss = {}
for i in range(len(sss)):
    dict_ss[sss[i]] = 0

# ssにおいて「sssの要素に合致する要素」の検索＆個数計上
for i in range(n):
    dict_ss[ss[i]] += 1

# 計上した個数のリストを作成
# その個数から2個の組み合わせを計算（n C 2）、足し合わせてans
ans_l = [dict_ss[sss[i]] for i in range(len(sss))]
ans = 0
for i in range(len(ans_l)):
    ans += (ans_l[i]*(ans_l[i]-1))/2

print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
# https://kato-robotics.hatenablog.com/entry/2019/07/28/204812

S = input()

MOD = 10 ** 9 + 7

dp = [[0]*13 for _ in range(len(S)+1)]
dp[0][0] = 1

for i in range(len(S)):
    if S[i] == '?':
        for x in range(10):
            for j in range(13):
                dp[i+1][(j * 10 + x) % 13] += dp[i][j]
    else:
        x = int(S[i])
        for j in range(13):
            dp[i+1][(j * 10 + x) % 13] += dp[i][j]
    
    for j in range(13):
        dp[i+1][j] %= MOD

print(dp[len(S)][5])

Fixed submission:
# https://kato-robotics.hatenablog.com/entry/2019/07/28/204812

S = input()

MOD = 10 ** 9 + 7

dp = [[0]*13 for _ in range(len(S)+1)]
dp[0][0] = 1

for i in range(len(S)):
    if S[i] == '?':
        for x in range(10):
            for j in range(13):
                dp[i+1][(j * 10 + x) % 13] += dp[i][j]
    else:
        x = int(S[i])
        for j in range(13):
            dp[i+1][(j * 10 + x) % 13] += dp[i][j]
    
    for j in range(13):
        dp[i+1][j] %= MOD

print(dp[len(S)][5])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]

print(max(a[1:]))
for i in range(1,n-1):
    aa = max(a[0:i])
    ab = max(a[i+1:])
    print(max(aa,ab))
print(max(a[:n]))

Fixed submission:
N=int(input())
A=[int(input()) for i in range(N)]
sortA=sorted(A)
for i in range(N):
    if A[i]!=sortA[-1]:
        print(sortA[-1])
    else:
        print(sortA[-2])
Buggy python submission (verdict: Time Limit Exceeded):
import sys

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

if R <= 45:
    print(R*(R-1))
    sys.exit()
else:
    for i in range(L,R):
        for v in range(i+1,R+1):
            a = (i*v)%2019
            ans = min(ans,a)
            if a == 0:
                break
print(ans)

Fixed submission:
import sys

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

for i in range(L,R):
    for v in range(i+1,R+1):
        a = (i*v)%2019
        ans = min(ans,a)
        if a == 0:
            break
    else:
        continue
    break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

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

if R <= 45:
    print(R*(R-1))
    sys.exit()
else:
    for i in range(L,R):
        for v in range(i+1,R+1):
            a = (i*v)%2019
            ans = min(ans,a)
print(ans)

Fixed submission:
import sys

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

for i in range(L,R):
    for v in range(i+1,R+1):
        a = (i*v)%2019
        ans = min(ans,a)
        if a == 0:
            break
    else:
        continue
    break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
ans=N
for i in range(N):
    w=S[:i].count('W')
    e=S[i+1:].count('E')
    ans=min(ans,w+e)
    w=0
    e=0
print(ans)

Fixed submission:
N=int(input())
S=input()

wsum=[0]*N
if S[0]=='W':
    wsum[0]=1
else:
    wsum[0]=0    
for i in range(1,N):
    if S[i]=='W':
        wsum[i]=wsum[i-1]+1
    else:
        wsum[i]=wsum[i-1]

SR=S[::-1]
esum=[0]*N
if SR[0]=='E':
    esum[0]=1
else:
    esum[0]=0
for i in range(1,N):
    if SR[i]=='E':
        esum[i]=esum[i-1]+1
    else:
        esum[i]=esum[i-1]
esum=esum[::-1]

ans=N
for i in range(N):
    ans=min(ans,wsum[i]+esum[i]-1)
print(ans)
Buggy python submission (verdict: Runtime Error):
a=s.count('R')
if a==0:
    print(a)
elif s[1]=='S':
    print(a-1)
else:
    print(a)

Fixed submission:
s=input()
a=s.count('R')
if a==0:
    print(a)
elif s[1]=='S' and a==2:
    print(a-1)
else:
    print(a)
Buggy python submission (verdict: Runtime Error):
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
x=a+v*t
y=b+w*t
if x>=y:
    print('YES')
else:
    print('NO')

Fixed submission:
n=input()
b=n[:3]
print(b)
Buggy python submission (verdict: Runtime Error):
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if a>b:
    x=a-v+t
    y=b-w*t
else:
    x=a+v*t
    y=b+w*t
    if abs(x)>=abs(y) or abs(x)=0:
        print('YES')
    else:
        print('NO')

Fixed submission:

a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if a>b:
    x=a-v*t
    y=b-w*t
    if x<=y:
        print('YES')
    else:
        print('NO')
else:
    x=a+v*t
    y=b+w*t
    if x>=y:
        print('YES')
    else:
        print('NO')
Buggy python submission (verdict: Runtime Error):
s=input()
n=len(s)
if s[0]==s[-1] and s[0]==s[int((n-1)/2-1)] and s[int((n+3)/2-1)]==s[-1] and s[1]==s[-2] and s[2]==s[-3] and s[int((n+3)/2)]==s[-2]:
    print('Yes')
else:
    print('No')


Fixed submission:
s=input()
n=len(s)
k=n//2
a=s[:k]
b=s[-k:]
if s==s[::-1] and a==a[::-1] and b==b[::-1]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
input_unko = input('number')
input_tinko = input('number')
if input_unko * input_tinko % 2 == 0:
    print('Even')
else:
    print('Odd')

Fixed submission:
a,b = map(int, input().split())
if a*b % 2 == 0:
    print('Even')
else:
    print('Odd')
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input()) 
a=list(map(int,input().split())); 
ans=1; 
for i in a:
	ans=ans*i
x=10**18 
if ans>x:
	print(-1) 
else:
	print(ans)

Fixed submission:
n=int(input()) 
a=list(map(int,input().split())); 
ans=1; 

x=10**18 
flag=0;
for i in a:
	if i==0:
		flag=1
		break

for i in a:
	ans=ans*i
	if ans>x:
		break
if flag==1:
	ans=0
if ans>x :
	print(-1) 
else:
	print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
MOD = 998244353

nums = []

for i in range(K):
    l, r = map(int, input().split())
    nums.append([l, r])
# nums.sort()
# print(nums)


dp = [0] * (N + 1)
dp[1] = 1
cumsum = [0, 1]

for i in range(2, N + 1):
    for l, r in nums:
        if i - l > 0:
            # print(i, l, r)
            # r = min(r, N)
            dp[i] += cumsum[i - l] - cumsum[max(i - r - 1, 0)]
    cumsum.append(cumsum[-1] + dp[i])

print(dp[-1] % MOD)
# print(dp)
# print(cumsum)


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

nums = []

for i in range(K):
    l, r = map(int, input().split())
    nums.append([l, r])
# nums.sort()
# print(nums)


dp = [0] * (N + 1)
dp[1] = 1
cumsum = [0, 1]

for i in range(2, N + 1):
    for l, r in nums:
        # print(l,r)
        if i - l > 0:
            # print(i, l, r)
            # r = min(r, N)
            dp[i] += (cumsum[i - l] - cumsum[max(i - r - 1, 0)]) % MOD
    cumsum.append(cumsum[-1] + dp[i])

print(dp[-1] % MOD)
# print(dp)
# print(cumsum)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
MOD = 998244353

nums = []

for i in range(K):
    l, r = map(int, input().split())
    for j in range(l, r + 1):
        nums.append(j)
nums.sort()
# print(nums)


dp = [0] * (N + 1)
dp[1] = 1
for i in range(2, N + 1):
    for n in nums:
        if i > n:
            dp[i] += dp[i - n] % MOD
        else:
            break

print(dp[-1]%MOD)


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

nums = []

for i in range(K):
    l, r = map(int, input().split())
    nums.append([l, r])
# nums.sort()
# print(nums)


dp = [0] * (N + 1)
dp[1] = 1
cumsum = [0, 1]

for i in range(2, N + 1):
    for l, r in nums:
        # print(l,r)
        if i - l > 0:
            # print(i, l, r)
            # r = min(r, N)
            dp[i] += (cumsum[i - l] - cumsum[max(i - r - 1, 0)]) % MOD
    cumsum.append(cumsum[-1] + dp[i])

print(dp[-1] % MOD)
# print(dp)
# print(cumsum)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
MOD = 998244353

nums = []

for i in range(K):
    l, r = map(int, input().split())
    for j in range(l, r + 1):
        nums.append(j)
nums.sort()
# print(nums)


dp = [0] * (N + 1)
dp[1] = 1
for i in range(2, N + 1):
    for n in nums:
        if i > n:
            dp[i] += dp[i - n]
        else:
            break

print(dp[-1]%MOD)


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

nums = []

for i in range(K):
    l, r = map(int, input().split())
    nums.append([l, r])
# nums.sort()
# print(nums)


dp = [0] * (N + 1)
dp[1] = 1
cumsum = [0, 1]

for i in range(2, N + 1):
    for l, r in nums:
        # print(l,r)
        if i - l > 0:
            # print(i, l, r)
            # r = min(r, N)
            dp[i] += (cumsum[i - l] - cumsum[max(i - r - 1, 0)]) % MOD
    cumsum.append(cumsum[-1] + dp[i])

print(dp[-1] % MOD)
# print(dp)
# print(cumsum)
Buggy python submission (verdict: Time Limit Exceeded):
import collections

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

l = [0] * (10**5 + 1)
c = collections.Counter(A)
for key in c:
    l[key] = c[key]

for i in range(Q):
    if B[i] in c:
        c[C[i]] += c[B[i]]
        c.pop(B[i])
    ans = 0
    for item in c:
        ans += item * c[item]
    print(ans)


Fixed submission:
import collections

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

l = [0] * (10**5 + 1)
# print(l)
# print(len(l))
c = collections.Counter(A)
# print(c)
for key in c:
    l[key] = c[key]
# print(l)
ans = 0
for item in c:
    ans += item * c[item]

# print(ans)  # i=0

for i in range(Q):
    if B[i] in c:
        # print(c)
        ans = ans - B[i] * c[B[i]] + C[i] * c[B[i]]
        c[C[i]] += c[B[i]]
        c.pop(B[i])
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

# print(N)
# print(A)
# print(Q)
# print(B)
# print(C)

ans = []

for i in range(Q):
    for j in range(N):
        if A[j] == B[i]:
            A[j] = C[i]

    ans_item = sum(A)
    ans.append(ans_item)


# print(ans)
for item in ans:
    print(item)


Fixed submission:
import collections

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

l = [0] * (10**5 + 1)
# print(l)
# print(len(l))
c = collections.Counter(A)
# print(c)
for key in c:
    l[key] = c[key]
# print(l)
ans = 0
for item in c:
    ans += item * c[item]

# print(ans)  # i=0

for i in range(Q):
    if B[i] in c:
        # print(c)
        ans = ans - B[i] * c[B[i]] + C[i] * c[B[i]]
        c[C[i]] += c[B[i]]
        c.pop(B[i])
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
#print(N)
#print(A)
ans = 1
for i in A:
  ans = ans * i
if ans <= 10 ** 18:
  print(ans)
else:
  print(-1)

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

A = sorted(A, reverse=True)
#print(A)

if A[-1] == 0:
  print(0)
  exit()
  
ans = 1

for i in A:
  ans = ans * i
  if ans > 10 ** 18:
    print(-1)
    exit()

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque
import copy

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(reverse=True)

p1 = deque(p)
q1 = deque(q)
r1 = deque(r)
p2 = copy.deepcopy(p1)
q2 = copy.deepcopy(q1)
r2 = copy.deepcopy(r1)


ans = 0

ans1 = 0
for _ in range(X):
    if len(r1) > 0:
        if p1[0] > r1[0]:
            ans1 += p1.popleft()
        else:
            ans1 += r1.popleft()
    else:
        ans1 += p1.popleft()

for _ in range(Y):
    if len(r1) > 0:
        if q1[0] > r1[0]:
            ans1 += q1.popleft()
        else:
            ans1 += r1.popleft()
    else:
        ans1 += q1.popleft()

ans2 = 0
for _ in range(Y):
    if len(r2) > 0:
        if q2[0] > r2[0]:
            ans2 += q2.popleft()
        else:
            ans2 += r2.popleft()
    else:
        ans2 += q2.popleft()

for _ in range(X):
    if len(r2) > 0:
        if p2[0] > r2[0]:
            ans2 += p2.popleft()
        else:
            ans2 += r2.popleft()
    else:
        ans2 += p2.popleft()

ans = max(ans1, ans2)
print(ans)


Fixed submission:
X = int(input())
ans = 0
ans += 1000 * (X // 500)
X = X % 500
ans += 5 * (X // 5)
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque

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(reverse=True)

p = deque(p)
q = deque(q)
r = deque(r)

ans = 0
for _ in range(X):
    if p[0] >= r[0]:
        ans += p.popleft()
    else:
        ans += r.popleft()
for _ in range(Y):
    if q[0] >= r[0]:
        ans += q.popleft()
    else:
        ans += r.popleft()

print(ans)


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(reverse=True)

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

all = p + q + r
all.sort(reverse=True)
ans = sum(all[:X + Y])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
p = list(map(int, input().split()))
temp = 0
for i in range(N - K + 1):
    temp = max(temp, sum(p[i:i + K]))
# print(temp)
print((temp + K) / 2)


Fixed submission:
import collections

N, K = map(int, input().split())
p = list(map(int, input().split()))

# サイコロ（1...p）の期待値は(1+p)/2
cum_sum = [0]
for i in range(0, N):
    cum_sum.append(cum_sum[i] + (1 + p[i]) / 2)
# print(cum_sum)
# 調べる区間は[1,...,K],...,[N-K+1,...N]
ans = 0
for i in range(1, N - K + 2):
    temp = cum_sum[i + K - 1] - cum_sum[i - 1]
    # print(temp)
    ans = max(ans, temp)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split())
magic = [list(map(int, input().split())) for i in range(N)]

# dp[damage] := モンスターに damage を与えるために必要な最小コスト

# damage = 0,1,2,...,H
dp = [10**9] * (H + 1)
dp[0] = 0
for h in range(H):
    for damage, cost in magic:
        next_index = min(h + damage, H)
        dp[next_index] = min(dp[next_index], dp[h] + cost)

# print(dp)
print(dp[-1])


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

# dp[damage] := モンスターに damage を与えるために必要な最小コスト

# damage = 0,1,2,...,H
dp = [10**9] * (H + 1)
dp[0] = 0
for h in range(H):
    for damage, cost in magic:
        next_index = min(h + damage, H)
        dp[next_index] = min(dp[next_index], dp[h] + cost)

# print(dp)
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
MOD = 10**9 + 7
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


prime = [0] * (10**6 + 1)
for i in range(N):
    c = Counter(prime_factorize(A[i]))
    for j in c.items():
        prime[j[0]] = max(j[1], prime[j[0]])
lcm = 1
for i in range(10**6):
    if prime[i] > 0:
        lcm *= pow(i, prime[i], MOD)

ans = 0
for i in range(N):
    ans += lcm // A[i]
    ans %= MOD
print(ans)


Fixed submission:
import math
import sys
input = sys.stdin.readline

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

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

mod = 10**9 + 7
# A全体の最小公倍数
a_lcm = 1
for a in A:
    a_lcm = lcm(a_lcm, a)

# Bの総和
b_sum = 0
for i in range(N):
    b_sum += a_lcm // A[i]

print(b_sum % mod)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
left_max_num = 0
for i in range(1, N + 1):
    if i in a:
        left_max_num = i
        a = a[a.index(i) + 1:]
    else:
        break
if left_max_num != 0:
    print(N - left_max_num)
else:
    print(-1)


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

num = 0
for item in a:
    if item == (num + 1):
        num += 1

if num != 0:
    print(N - num)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
left_max_num = 0
for i in range(1, N + 1):
    if i in a:
        left_max_num = i
        a = a[a.index(i) + 1:]
    else:
        break
if left_max_num != 0:
    print(N - left_max_num)
else:
    print(-1)


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

num = 0
for item in a:
    if item == (num + 1):
        num += 1

if num != 0:
    print(N - num)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
from collections import deque
N, u, v = map(int, input().split())

G = [[] for _ in range(N + 1)]
for i in range(N - 1):
    a, b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)


def bfs(s):
    dist = [-1] * (N + 1)
    dist[s] = 0
    d = deque([s])
    while len(d) > 0:
        v = d.popleft()
        for w in edge[v]:
            if dist[w] < 0:
                dist[w] = dist[v] + 1
                d.append(w)
    return dist


tkhs = bfs(u)
aok = bfs(v)
ans = 0
for i in range(1, N + 1):
    if tkhs[i] < aok[i]:
        ans = max(ans, aok[i] - 1)
print(ans)


Fixed submission:
from collections import deque
N, u, v = map(int, input().split())

G = [[] for _ in range(N + 1)]
for i in range(N - 1):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)


def bfs(s):
    dist = [-1] * (N + 1)
    dist[s] = 0
    d = deque([s])
    while len(d) > 0:
        v = d.popleft()
        for w in G[v]:
            if dist[w] < 0:
                dist[w] = dist[v] + 1
                d.append(w)
    return dist


tkhs = bfs(u)
aok = bfs(v)
ans = 0
for i in range(1, N + 1):
    if tkhs[i] < aok[i]:
        ans = max(ans, aok[i] - 1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

mod = 10**9 + 7

ans = 0
# 制約より、aはそれぞれ60桁以内で表せる
# i+1(=1,2,...,60)桁目についてそれぞれ考える
for i in range(60):
    k = 1 << i  # k = 100....00(2) = 2**i(10)
    cnt_1 = 0
    cnt_0 = 0

    for ai in a:
        if k & ai:
            cnt_1 += 1
        else:
            cnt_0 += 1
    # 1 XOR 0 = 1 となる個数 = cnt_1 * cnt_0
    ans += (k % mod * cnt_1 * cnt_0) % mod

print(ans % mod)


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

mod = 10**9 + 7

ans = 0
# 制約より、aはそれぞれ60桁以内で表せる
# i+1(=1,2,...,60)桁目についてそれぞれ考える
for i in range(60):
    k = 1 << i  # k = 100....00(2) = 2**i(10)
    cnt_1 = 0
    cnt_0 = 0

    for ai in a:
        if k & ai:
            cnt_1 += 1
        else:
            cnt_0 += 1
    # 1 XOR 0 = 1 となる個数 = cnt_1 * cnt_0
    ans += (k % mod * cnt_1 * cnt_0) % mod

print(ans % mod)

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

mod = 10**9 + 7

ans = 0
# 制約より、aはそれぞれ60桁以内で表せる
# i+1(=1,2,...,60)桁目についてそれぞれ考える
for i in range(60):
    k = 1 << i  # k = 100....00(2) = 2**i(10)
    cnt_1 = 0
    cnt_0 = 0

    for ai in a:
        if k & ai:
            cnt_1 += 1
        else:
            cnt_0 += 1
    # 1 XOR 0 = 1 となる個数 = cnt_1 * cnt_0
    ans += (k * cnt_1 * cnt_0) % mod

print(ans % mod)


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

mod = 10**9 + 7

ans = 0
# 制約より、aはそれぞれ60桁以内で表せる
# i+1(=1,2,...,60)桁目についてそれぞれ考える
for i in range(60):
    k = 1 << i  # k = 100....00(2) = 2**i(10)
    cnt_1 = 0
    cnt_0 = 0

    for ai in a:
        if k & ai:
            cnt_1 += 1
        else:
            cnt_0 += 1
    # 1 XOR 0 = 1 となる個数 = cnt_1 * cnt_0
    ans += (k % mod * cnt_1 * cnt_0) % mod

print(ans % mod)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
tmp_x = -1
tmp_x_diff = -1
for i in range(N - 1):
    sum1 = sum(A[:i + 1])
    sum2 = sum(A[i + 1:])
    diff = abs(sum1 - sum2)
    if tmp_x_diff == -1 or diff < tmp_x_diff:
        tmp_x = i
        tmp_x_diff = diff
print(tmp_x_diff)


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

cumsum = [0]
for i in range(N):
    cumsum.append(cumsum[-1] + A[i])

tmp_x = -1
tmp_x_diff = -1
for i in range(N - 1):
    sum1 = cumsum[i + 1]
    sum2 = cumsum[-1] - cumsum[i + 1]
    diff = abs(sum2 - sum1)
    if tmp_x_diff == -1 or diff < tmp_x_diff:
        tmp_x = i
        tmp_x_diff = diff
print(tmp_x_diff)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            if L[i] < L[j] + L[k] and L[j] < L[k] + L[i] and L[k] < L[i] + L[j]:
                ans += 1
print(ans)


Fixed submission:
from bisect import bisect_left

n = int(input())
l = sorted(list(map(int, input().split())))
ans = 0

# a<b<c として、aとbを固定する
# 残る条件は c<a+b のみ
# aとbの固定方法がO(N^2), cの二分探索がO(logN)、結局O(N^2logN)
# 二分探索は事前にソートが必要

# ex. 2, 4(a), 4, 7(b), | 8, 9, 9 | (ここにa+b=11が挿入される), 12, 14
# cとして適切なのは8,9,9の3通り
# bisect_rightだとa+bが存在した時にバグる

for ai in range(n):
    for bi in range(ai + 1, n):
        ans += bisect_left(l, l[ai] + l[bi]) - bi - 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = [0] * len(A)

for i in A:
    ans[i - 1] = A.index(i) + 1

print(*ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans = [0] * N

for i in range(1, N + 1):
    ans[A[i - 1] - 1] = i

print(*ans)

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

ans = []
for i in range(1, len(A) + 1):
    temp = A.index(i)
    ans.append(temp + 1)

print(*ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans = [0] * N

for i in range(1, N + 1):
    ans[A[i - 1] - 1] = i

print(*ans)