Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
a = int(input())
array = list(map(int, input().strip().split()))
out = 0
for i in range(a):
    minn = min(array[0:i+1])
    out = out + 1 if array[i] == minn else out
print(out)

Fixed submission:
a = int(input())
array = list(map(int, input().strip().split()))
out = 0
min_num = array[0]
for i in array:
    min_num = min(min_num, i)
    out = out + 1 if i == min_num else out
print(out)

Buggy python submission (verdict: Time Limit Exceeded):
a = int(input())
array = list(map(int, input().strip().split()))
out = 0
for i in range(a):
    out = out + 1 if array[i] == min(array[0:i+1]) else out
print(out)

Fixed submission:
a = int(input())
array = list(map(int, input().strip().split()))
out = 0
min_num = array[0]
for i in array:
    min_num = min(min_num, i)
    out = out + 1 if i == min_num else out
print(out)

Buggy python submission (verdict: Runtime Error):
a = int(input())
array = list(map(int, input().strip().split()))
out = 0
for i in range(a):
    out = out + 1 if array[i] == min(array[0:i+1])
print(out)

Fixed submission:
a = int(input())
array = list(map(int, input().strip().split()))
out = 0
min_num = array[0]
for i in array:
    min_num = min(min_num, i)
    out = out + 1 if i == min_num else out
print(out)

Buggy python submission (verdict: Time Limit Exceeded):
a = int(input())
array = list(map(int, input().strip().split()))
out = 0
for i in range(a):
    if array[i] == min(array[0:i+1]):
        out = out + 1
print(out)

Fixed submission:
a = int(input())
array = list(map(int, input().strip().split()))
out = 0
min_num = array[0]
for i in array:
    min_num = min(min_num, i)
    out = out + 1 if i == min_num else out
print(out)

Buggy python submission (verdict: Time Limit Exceeded):
a = int(input())
array = list(map(int, input().strip().split()))
out = 0
for i in range(a):
    if array[i] == min(array[0:i+1]):
        out = out + 1
print(out)

Fixed submission:
a = int(input())
array = list(map(int, input().strip().split()))
out = 0
min_num = array[0]
for i in array:
    min_num = min(min_num, i)
    out = out + 1 if i == min_num else out
print(out)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().strip().split()))

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

print(' '.join(map(str, ans)))

Fixed submission:
import numpy as np
n = int(input())
A = list(map(int, input().strip().split()))
arr = np.array(A)


print(' '.join(map(str, np.argsort(arr) + 1)))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n = int(input())
nums = list(map(int, input().split()))
x = 10 ** 9 + 7

ans = 0

for i in range(1, n):
    ans += (sum(nums[:i]) % x) * nums[i]
    ans = ans % x

print(ans)


Fixed submission:
# -*- coding: utf-8 -*-

n = int(input())
nums = list(map(int, input().split()))
x = 10 ** 9 + 7

ans = 0

sums = [0] * (n - 1)

for j in range(n - 1):
    if j == 0:
        sums[0] = nums[0] % x
    else:
        sums[j] = (sums[j - 1] + nums[j]) % x

for i in range(1, len(nums)):
    ans += sums[i - 1] * nums[i]
    ans = ans % x

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n = int(input())
nums = list(map(int, input().split()))
x = 10 ** 9 + 7

ans = 0

for i in range(1, n):
    ans += sum(nums[:i]) * nums[i]
    ans = ans % x

print(ans)


Fixed submission:
# -*- coding: utf-8 -*-

n = int(input())
nums = list(map(int, input().split()))
x = 10 ** 9 + 7

ans = 0

sums = [0] * (n - 1)

for j in range(n - 1):
    if j == 0:
        sums[0] = nums[0] % x
    else:
        sums[j] = (sums[j - 1] + nums[j]) % x

for i in range(1, len(nums)):
    ans += sums[i - 1] * nums[i]
    ans = ans % x

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n = int(input())
nums = list(map(int, input().split()))
x = 10 ** 9 + 7

ans = 0

for i in range(n):
    for j in range(i + 1, n):
        item = (nums[i] % x) * (nums[j] % x)
        item = item % x
        ans += item
        ans = ans % x

print(ans)


Fixed submission:
# -*- coding: utf-8 -*-

n = int(input())
nums = list(map(int, input().split()))
x = 10 ** 9 + 7

ans = 0

sums = [0] * (n - 1)

for j in range(n - 1):
    if j == 0:
        sums[0] = nums[0] % x
    else:
        sums[j] = (sums[j - 1] + nums[j]) % x

for i in range(1, len(nums)):
    ans += sums[i - 1] * nums[i]
    ans = ans % x

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n,k = list(map(int, list(input().split())))
scores = list(map(int, list(input().split())))

s_k = 1
for j in range(k):
    s_k *= scores[j]

for i in range(k + 1, n + 1):
    _s_k = s_k
    remove = scores[i - k - 1]
    add    = scores[i - 1]

    if remove < add:
        print('Yes')
    else:
        print('No')


Fixed submission:
# -*- coding: utf-8 -*-

n,k = list(map(int, list(input().split())))
scores = list(map(int, list(input().split())))

for i in range(k + 1, n + 1):
    remove = scores[i - k - 1]
    add    = scores[i - 1]

    if remove < add:
        print('Yes')
    else:
        print('No')

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n,k = list(map(int, list(input().split())))
scores = list(map(int, list(input().split())))

s_k = 1
for j in range(k):
    s_k *= scores[j]

for i in range(k + 1, n + 1):
    _s_k = s_k
    remove = scores[i - k - 1]
    add    = scores[i - 1]
    s_k = s_k * add / remove

    if _s_k < s_k:
        print('Yes')
    else:
        print('No')


Fixed submission:
# -*- coding: utf-8 -*-

n,k = list(map(int, list(input().split())))
scores = list(map(int, list(input().split())))

for i in range(k + 1, n + 1):
    remove = scores[i - k - 1]
    add    = scores[i - 1]

    if remove < add:
        print('Yes')
    else:
        print('No')

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n,k = list(map(int, list(input().split())))
scores = list(map(int, list(input().split())))

for i in range(k + 1, n + 1):
    _s_k = 1
    s_k = 1
    for j in range(k):
        _s_k *= scores[i - j - 2]
        s_k *= scores[i - j - 1]

    if _s_k < s_k:
        print('Yes')
    else:
        print('No')


Fixed submission:
# -*- coding: utf-8 -*-

n,k = list(map(int, list(input().split())))
scores = list(map(int, list(input().split())))

for i in range(k + 1, n + 1):
    remove = scores[i - k - 1]
    add    = scores[i - 1]

    if remove < add:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n = int(input())

nums = list(map(int, input().split()))

ans = 1
for i in range(n):
    ans *= nums[i]

if ans > 10 ** 18:
    print(-1)
    exit()

print(ans)


Fixed submission:
# -*- coding: utf-8 -*-

n = int(input())

nums = sorted(list(map(int, input().split())))

ans = 1
for i in range(n):
    ans *= nums[i]

    if ans == 0:
        print(0)
        exit()

    if ans > 10 ** 18:
        print(-1)
        exit()

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


def main():
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    counter = Counter(a)
    ans: int = 0
    for key, value in counter.items():
        if value % 2 == 1:
            ans += 1
    print(ans)


main()


Fixed submission:
from collections import Counter


def main():
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    counter = Counter(a)
    ans = 0
    for key, value in counter.items():
        if value % 2 == 1:
            ans += 1
    print(ans)


main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,m=map(int,input().split())
a=[tuple(map(int,input().split())) for i in range(m)]

d=deque([(1,0)])
checked=[0]*n
checked[0]=1
ans=[0]*(n-1)
while len(d)>0:
    rm,dep=d.popleft()
    for i in a:
        if i[0]==rm or i[1]==rm:
            if checked[i[i.index(rm)-1]-1]==0:
                d.append((i[i.index(rm)-1],dep+1))
                checked[i[i.index(rm)-1]-1]=1
                ans[i[i.index(rm)-1]-2]=rm
print('Yes')
for i in ans:
    print(i)

Fixed submission:
from collections import deque
n,m=map(int,input().split())
a=[tuple(map(int,input().split())) for i in range(m)]
pr=[[] for i in range(n)]
for i in a:
    pr[max(i)-1].append(min(i))
    pr[min(i)-1].append(max(i))
d=deque([1])
checked=[0]*n
checked[0]=1
ans=[0]*(n-1)
while len(d)>0:
    rm=d.popleft()
    for i in pr[rm-1]:
        if checked[i-1]==0:
            d.append(i)
            checked[i-1]=1
            ans[i-2]=rm
    #print(d)
print('Yes')
for i in ans:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
pl=1
visit=[1]
loop=0
q=True
v=True
cnt=0
br=False
while q:
    cnt+=1
    pl=a[pl-1]
    for i in visit:
        if pl==i:
            loop=visit.index(pl)
            br=not br
            break
    if br:
        break
    visit.append(pl)
    if cnt==k:
        print(pl)
        v=not v
        break
    if cnt==10**7:
        q=not q
if v:
    loop_len=cnt-loop
    q=True
    k=(k-loop)%loop_len
    cnt=0
    if k==0:
        print(pl)
    else:
        while q:
            cnt+=1
            pl=a[pl-1]
            if cnt==k:
                print(pl)
                break
            if cnt==10**7:
                q=not q

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
pl=1
visit=[-1]*n
visit[0]=0
loop=0
q=True
v=True
cnt=0

while q:
    cnt+=1
    pl=a[pl-1]
    if visit[pl-1]!=-1:
        loop=visit[pl-1]
        break
    visit[pl-1]=cnt
    if cnt==k:
        print(pl)
        v=not v
        break
    if cnt==10**7:
        q=not q
if v:
    loop_len=cnt-loop
    q=True
    k=(k-loop)%loop_len
    cnt=0
    if k==0:
        print(pl)
    else:
        while q:
            cnt+=1
            pl=a[pl-1]
            if cnt==k:
                print(pl)
                break
            if cnt==10**7:
                q=not q
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=[list(map(int,input().split())) for i in range(k*2)]
ans=[1,1,1]
for i in range(1,k*2,2):
    for j in a[i]:
        ans[j-1]=0
print(sum(ans))

Fixed submission:
n,k=map(int,input().split())
a=[list(map(int,input().split())) for i in range(k*2)]
ans=[1]*n
for i in range(1,k*2,2):
    for j in a[i]:
        ans[j-1]=0
print(sum(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n-1):
    for j in range(i,n):
        if a[i]+a[j]==(j+1)-(i+1):
            ans+=1
print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
l=[0]*n
r=[0]*n
for i in range(n):
    if a[i]+i+1<n:
        l[a[i]+i+1]+=1
    if i+1-a[i]>0:
        r[i+1-a[i]]+=1
ans=0
for i in range(n):
    ans+=l[i]*r[i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
for i in range(1,n+1):
    print(a.count(i))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for i in range(len(a)):
    ans[a[i]-1]+=1
for i in ans:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
import math

k=int(input())
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            ans+=(math.gcd(i,math.gcd(j,l)))
print(ans)

Fixed submission:
from math import gcd

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

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

k=int(input())
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            ans+=(math.gcd(math.gcd(i,j),l))
print(ans)

Fixed submission:
from math import gcd

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

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

k=int(input())
ans=[]
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            ans.append(math.gcd(math.gcd(i,j),l))
print(sum(ans))

Fixed submission:
from math import gcd

k=int(input())
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            ans+=(gcd(i,gcd(j,l)))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))
c={}
for i in b:
    c[i]=a.count(i)
al=0
ans=[]
for i in c.values():
    al+=(i*(i-1))//2
for i in range(n):
    print(al - (c[a[i]]-1))

Fixed submission:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))

c=Counter(a)

al=0
for i in c.values():
    al+=(i*(i-1))//2
for i in range(n):
    print(al - (c[a[i]]-1))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))
c={}
for i in b:
    c[i]=a.count(i)
al=0
ans=[]
for i in c.values():
    al+=(i*(i-1))//2
for i in range(n):
    print(al - (c[a[i]]-1))

Fixed submission:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))

c=Counter(a)

al=0
for i in c.values():
    al+=(i*(i-1))//2
for i in range(n):
    print(al - (c[a[i]]-1))
Buggy python submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
if a==0:
    print(0)
else:
    blue=['b']*a
    red=['r']*b
    s=blue+red
    ans=(s[:n%(a+b)].count('b')) + (a*(n//(a+b)))
    print(ans)

Fixed submission:
n,a,b=map(int,input().split())
if a==0:
    print(0)
else:
    ans=(min(n%(a+b),a) + (a*(n//(a+b))))
    print(ans)

Buggy python submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
if a==0:
    print(0)
else:
    blue=['b']*a
    red=['r']*b
    s=blue+red
    print(s[:n%(a+b)].count('b') + a*(n//(a+b)))

Fixed submission:
n,a,b=map(int,input().split())
if a==0:
    print(0)
else:
    ans=(min(n%(a+b),a) + (a*(n//(a+b))))
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a=int(input())
b=[int(i) for i in input().split()]
c=[]
for i in range(a-1):
    for j in range(i+1,a):
        if b[i]==b[j]:
            c.append(1)
            break
if len(c)>0:
    print('NO')
else:
    print('YES')

Fixed submission:
a=int(input())
b=[int(i) for i in input().split()]
c=list(set(b))
if len(b)==len(c):
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Time Limit Exceeded):
a=int(input())
b=[int(i) for i in input().split()]
c=[]
for i in range(a-1):
    for j in range(i+1,a):
        if b[i]==b[j]:
            c.append(1)
            break
if len(c)>0:
    print('NO')
else:
    print('YES')

Fixed submission:
a=int(input())
b=[int(i) for i in input().split()]
c=list(set(b))
if len(b)==len(c):
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Time Limit Exceeded):
a=int(input())
b=[int(i) for i in input().split()]
c=[]
for i in range(a-1):
    for j in range(i+1,a):
        if b[i]==b[j]:
            c.append(1)
if len(c)>0:
    print('NO')
else:
    print('YES')

Fixed submission:
a=int(input())
b=[int(i) for i in input().split()]
c=list(set(b))
if len(b)==len(c):
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]

ma = 0
for i in range(a[0]-a[1]+1):
    c=b[i:i+a[1]]  #K個取りだす 
    ma=max(ma,sum(c))

print((ma+a[1])/2)

Fixed submission:
import numpy as np
n,k=map(int,input().split())
exp=list(map(lambda x: (int(x)+1)/2,input().split()))
l=np.cumsum(exp)
 
ans=l[k-1]
for i in range(0,n-k):
  x=l[i+k]-l[i]
  ans=max(ans,x)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]

ma = 0
for i in range(a[0]-a[1]+1):
    c=b[i:i+a[1]]  #K個取りだす 
    ma=max(ma,sum(c))

print((ma+a[1])/2)

Fixed submission:
import numpy as np
n,k=map(int,input().split())
exp=list(map(lambda x: (int(x)+1)/2,input().split()))
l=np.cumsum(exp)
 
ans=l[k-1]
for i in range(0,n-k):
  x=l[i+k]-l[i]
  ans=max(ans,x)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]

max_prod = 0
l=[]
for i in range(a[0] - a[1] + 1):
    chunk = b[i:i + a[1]]  # i, i + 1, ..., i + 12 番目の13個の数字を取り出す。
    prod = sum(chunk)# 部分リストのすべての値の和
    if prod>max_prod:
        l=chunk
    max_prod = max(max_prod, prod)  # 最大値更新

ans=0
for i in range(len(l)):
    ans+=(l[i]+1)/2
print(ans)

Fixed submission:
import numpy as np
n,k=map(int,input().split())
exp=list(map(lambda x: (int(x)+1)/2,input().split()))
l=np.cumsum(exp)
 
ans=l[k-1]
for i in range(0,n-k):
  x=l[i+k]-l[i]
  ans=max(ans,x)
print(ans)
Buggy python submission (verdict: Runtime Error):
N=input()
K=int(input())
m=len(N)

dp0=[[0]*(m+1) for _ in range(m+1)]
dp1=[[0]*(m+1) for _ in range(m+1)]
dp1[0][0]=1
for i in range(1,m+1):
    dp0[i][0]=1
    
for i in range(m):
    for j in range(m):
        if N[i]=='0':
            dp0[i+1][j+1]=dp0[i][j]*9 + dp0[i][j+1]
            dp1[i+1][j+1]=dp1[i][j+1]
        else:
            dp0[i+1][j+1]=dp0[i][j]*9 + dp0[i][j+1]+dp1[i][j]*(int(N[i])-1)+dp1[i][j+1]
            dp1[i+1][j+1]=dp1[i][j]
print(dp0[-1][K]+dp1[-1][K])

Fixed submission:
N=input()
K=int(input())
m=len(N)
 
dp0=[[0]*(m+1) for _ in range(m+1)]
dp1=[[0]*(m+1) for _ in range(m+1)]
dp1[0][0]=1
for i in range(1,m+1):
    dp0[i][0]=1
    
for i in range(m):
    for j in range(m):
        if N[i]=='0':
            dp0[i+1][j+1]=dp0[i][j]*9 + dp0[i][j+1]
            dp1[i+1][j+1]=dp1[i][j+1]
        else:
            dp0[i+1][j+1]=dp0[i][j]*9 + dp0[i][j+1]+dp1[i][j]*(int(N[i])-1)+dp1[i][j+1]
            dp1[i+1][j+1]=dp1[i][j]
if m<K:
  print(0)
else:
  print(dp0[-1][K]+dp1[-1][K])

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

dp0=[[0]*(m+1) for _ in range(m+1)]
dp1=[[0]*(m+1) for _ in range(m+1)]
dp1[0][0]=1
for i in range(1,m+1):
    dp0[i][0]=1
    
for i in range(m):
    for j in range(m):
        if N[i]=='0':
            dp0[i+1][j+1]=dp0[i][j]*9 + dp0[i][j+1]
            dp1[i+1][j+1]=dp1[i][j+1]
        else:
            dp0[i+1][j+1]=dp0[i][j]*9 + dp0[i][j+1]+dp1[i][j]*(int(N[i])-1)+dp1[i][j+1]
            dp1[i+1][j+1]=dp1[i][j]
print(dp0[-1][K]+dp1[-1][K])

Fixed submission:
N=input()
K=int(input())
m=len(N)
 
dp0=[[0]*(m+1) for _ in range(m+1)]
dp1=[[0]*(m+1) for _ in range(m+1)]
dp1[0][0]=1
for i in range(1,m+1):
    dp0[i][0]=1
    
for i in range(m):
    for j in range(m):
        if N[i]=='0':
            dp0[i+1][j+1]=dp0[i][j]*9 + dp0[i][j+1]
            dp1[i+1][j+1]=dp1[i][j+1]
        else:
            dp0[i+1][j+1]=dp0[i][j]*9 + dp0[i][j+1]+dp1[i][j]*(int(N[i])-1)+dp1[i][j+1]
            dp1[i+1][j+1]=dp1[i][j]
if m<K:
  print(0)
else:
  print(dp0[-1][K]+dp1[-1][K])
Buggy python submission (verdict: Time Limit Exceeded):
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
if a[1]>=a[0]:
    print(0)
else:
    c=[]
    if a[0]<=a[1]*2:
        for i in range(a[0]-a[1]):
            c.append(min(b))
            b.remove(min(b))
        print(sum(c))
    else:
        for i in range(a[1]):
            b.remove(max(b))
        print(sum(b))

Fixed submission:
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
if a[1]>=a[0]:
    print(0)
else:
    print(sum(sorted(b)[:a[0]-a[1]]))

Buggy python submission (verdict: Time Limit Exceeded):
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
if a[1]>=len(b):
    print(0)
else:
    c=[]
    for i in range(a[0]-a[1]):
        c.append(min(b))
        b.remove(min(b))
    print(sum(c))

Fixed submission:
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
if a[1]>=a[0]:
    print(0)
else:
    print(sum(sorted(b)[:a[0]-a[1]]))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
ans=0
p=10**9 + 7 
l=[0]*60
for i in range(60):
    for j in a:
        l[i]+=(j>>i)&1
    ans=(ans + (2**i) * l[i] * (n-l[i]))%p
print(ans) 

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=0
p=10**9 + 7 
l=[0]*60
for i in range(60):
    for j in a:
        l[i]+=(j>>i)&1
    ans=(ans + (2**i) * l[i] * (n-l[i]))%p
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]
SUM = 0
DIV = 10**9 + 7

for i in range(1,N):
    for j in range(i+1,N+1):
        XOR = A[i-1]^A[j-1]#XOR
        SUM = SUM + XOR
if SUM < DIV:
    print(SUM)
else:
    print(SUM%DIV)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=0
p=10**9 + 7 
l=[0]*60
for i in range(60):
    for j in a:
        l[i]+=(j>>i)&1
    ans=(ans + (2**i) * l[i] * (n-l[i]))%p
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map(int,input().split()))

dp=[0]
for i in range(1,n): # dp[i]の最小を決めていく。
    dpi=float('inf')
    for j in range(1,k+1):
        if i<j:
            break
        else:
            dpi=min(dp[i-j]+abs(h[i]-h[i-j]),dpi)
    dp.append(dpi)
print(dp[-1])

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

# nの足場までいく最小コストを a_n とする。
# a_1のコストは0,  a_2のコストは(h_1からの１通りなので)\h_1-h_2\
dp=[0]*n
dp[1]=abs(h[0]-h[1])
for i in range(2,n):
    dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))

print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=list(map(int,input().split()))

dp=[0]
for i in range(1,n): # dp[i]の最小を決めていく。
    dpi=float('inf')
    for j in range(1,k+1):
        if i<j:
            break
        else:
            dpi=min(dp[i-j]+abs(h[i]-h[i-j]),dpi)
    dp.append(dpi)
print(dp[-1])

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

dp=[0]
for i in range(1,n): # dp[i]の最小を決めていく。
    dpi=float('inf')
    for j in range(1,k+1):
        if i<j:
            break
        else:
            dpi=min(dp[i-j]+abs(h[i]-h[i-j]),dpi)
    dp.append(dpi)
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
	w[i], v[i] = map(int, input().split())
dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
    for j in range(W+1):
        if j-w[i]>=0:
            dp[i+1][j]=max(dp[i+1][j],dp[i][j-w[i]]+v[i])
        dp[i+1][j]=max(dp[i+1][j],dp[i][j])
print(dp[N][W])

Fixed submission:
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
	w[i], v[i] = map(int, input().split())
dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
    for j in range(W+1):
        if j-w[i]>=0:
            dp[i+1][j]=max(dp[i+1][j],dp[i][j-w[i]]+v[i])
        dp[i+1][j]=max(dp[i+1][j],dp[i][j])
print(dp[N][W])
Buggy python submission (verdict: Runtime Error):
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
	w[i], v[i] = map(int, input().split())
dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
    for j in range(W+1):
        if j-w[i]>=0:
            dp[i+1][j]=max(dp[i+1][j],dp[i][j-w[i]]+v[i])
        dp[i+1][j]=max(dp[i+1][j],dp[i][j])
print(dp[N][W])

Fixed submission:
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
	w[i], v[i] = map(int, input().split())

V = sum(v)
# dp[i][j]:i番目までの品物から価値がj以上になるよう選んだときの重さの総和の最小値
dp = [[float("inf")] * (V + 1) for _ in range(N + 1)]

dp[0][0] = 0
for i in range(N):
	for j in range(V + 1):
		# i+1番目を選ぶ場合
		if j - v[i] >= 0:
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i])
		# i+1番目を選ばない場合
		dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])

# dp[N][j]がW以下であるようなjの最大値が答えになる
ans = 0
for j in range(V + 1):
	if dp[N][j] <= W:
		ans = j

print(ans)