Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=sorted(list(map(int,input().split())))
X=[A[0]]
if N>1 and A[0]==A[1]:
  ans=0
else:
  ans=1
f=True
if A[0]==1:
  if N>1 and A[0]==A[1]:
    print(0)
  else:
    print(1)
  exit(0)
for i in range(1,N):
  if A[i]==A[(i+1)%N]:
    f=False
    continue
  
  F=True
  for x in X:
    if A[i]%x==0:
      F=False
      break
  if F:
    X.append(A[i])
    if f:
      ans+=1
  f=True
print(ans)

Fixed submission:
N=int(input())
A=sorted(list(map(int,input().split())))
dp=[True for i in range(A[-1])]
ans=0
i=0
j=-1
while i<N:
  if i+1<N:
    while A[i]==A[i+1]:
      i+=1
      if i+1==N:
        break
  if dp[A[i]-1] and i-j==1:
    ans+=1
  for k in range(2*A[i],A[-1]+1,A[i]):
    dp[k-1]=False
  j=i
  i+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=sorted(list(map(int,input().split())))
X=[A[0]]
if N>1 and A[0]==A[1]:
  ans=0
else:
  ans=1
f=True
for i in range(1,N):
  if A[i]==A[(i+1)%N]:
    f=False
    continue
  
  F=True
  for x in X:
    if A[i]%x==0:
      F=False
      break
  if F:
    X.append(A[i])
    if f:
      ans+=1
  f=True
print(ans)

Fixed submission:
N=int(input())
A=sorted(list(map(int,input().split())))
dp=[True for i in range(A[-1])]
ans=0
i=0
j=-1
while i<N:
  if i+1<N:
    while A[i]==A[i+1]:
      i+=1
      if i+1==N:
        break
  if dp[A[i]-1] and i-j==1:
    ans+=1
  for k in range(2*A[i],A[-1]+1,A[i]):
    dp[k-1]=False
  j=i
  i+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
ans=1
for a in A:
  ans*=a
if ans>10**18:
  print(-1)
else:
  print(ans)

Fixed submission:
N=int(input())
A=sorted(list(map(int,input().split())))
if A[0]==0:
  print(0)
  exit(0)
ans=1
for a in A[::-1]:
  ans*=a
  if ans>10**18:
    print(-1)
    exit(0)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
P=[[0]*(N+1) for i in range(N+1)]
for i in range(M):
  a,b=map(int,input().split())
  P[a][b]=b
  P[b][a]=a
#AB=[list(map(int,input().split())) for i in range(M)]
ans=[0]*N
con=set()
now=[1]
while now!=[]:
  _now=[]
  for n in now:
    for p in P[n]:
      if p>0 and p not in con:
        ans[p-1]=n
        _now.append(p)
        con.add(p)
    #con.add(n)
  now=_now
print('Yes')
for a in ans[1:]:
  print(a)

Fixed submission:
N,M=map(int,input().split())
P=[[] for i in range(N+1)]
for i in range(M):
  a,b=map(int,input().split())
  P[a].append(b)
  P[b].append(a)
#AB=[list(map(int,input().split())) for i in range(M)]
ans=[0]*N
con=set()
now=[1]
while now!=[]:
  _now=[]
  for n in now:
    for p in P[n]:
      if p in con:
        continue
      ans[p-1]=n
      _now.append(p)
      con.add(p)
    #con.add(n)
  now=_now
print('Yes')
for a in ans[1:]:
  print(a)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
from collections import defaultdict
import math
d = defaultdict(int)
MOD=10**9+7
for i in range(N):
  a,b=map(int,input().split())
  x=math.gcd(a,b)
  if x==0:
    if a>b:
      d[(1,0)]+=1
    elif b>a:
      d[(0,1)]+=1
    else:
      d[(0,0)]+=1
  else:
    a,b=a//x,b//x
    if a<0:
      a,b=-a,-b
    d[(a,b)]+=1
ans=0
def C(x):
  X=math.factorial(x)
  _=0
  for i in range(1,x+1):
    _+=X//math.factorial(i)//math.factorial(x-i)
  return _
if d[(0,0)]>0:
  x=d[(0,0)]
  X=math.factorial(x)
  for i in range(1,x+1):
    ans+=X//math.factorial(i)//math.factorial(x-i)
ind=defaultdict(int)
index=1
_ans=[1]
for a,b in list(d.keys()):
  if b<0:
    _k=(-b,a)
  else:
    _k=(b,-a)
  if d[_k]==0:
    _ans.append(C(d[(a,b)])+1)
    index+=1
  else:
    if ind[_k]==0:
      _ans.append(C(d[(a,b)]))
      ind[(a,b)]=index
      index+=1
    else:
      _ans[ind[_k]]+=C(d[(a,b)])+1
_=1
for a in _ans:
  _*=a
print((ans+_-1)%MOD)

Fixed submission:
N=int(input())
from collections import defaultdict
import math
d = defaultdict(int)
MOD=10**9+7
for i in range(N):
  a,b=map(int,input().split())
  x=math.gcd(abs(a),abs(b))
  if a==0:
    if b==0:
      k=(0,0)
    else:
      k=(0,1)
  elif b==0:
    k=(1,0)
  else:
    if a<0:
      a,b=-a,-b
    if b<0:
      a,b=a//x,-((-b)//x)
    else:
      a,b=a//x,b//x
    k=(a,b)
  d[k]+=1

ind=defaultdict(int)
index=1
_ans=[1]
for a,b in list(d.keys()):
  if a==b==0:
    continue
  if b<=0:
    _k=(-b,a)
  else:
    _k=(b,-a)
  if d[_k]==0:
    _ans[0]*=pow(2,d[(a,b)])
  else:
    if ind[_k]==0:
      _ans.append(pow(2,d[(a,b)],MOD))
      ind[(a,b)]=index
      index+=1
    else:
      _ans[ind[_k]]+=pow(2,d[(a,b)],MOD)-1
ans=1
for a in _ans:
  ans=ans*a%MOD
print((d[(0,0)]+ans-1+MOD)%MOD)
Buggy python submission (verdict: Runtime Error):
A,B,C,K=map(input().split())
if A>=K:
  print(K)
elif A+B>=K:
  print(A)
else:
  print(A+A+B-K)

Fixed submission:
A,B,C,K=map(int,input().split())
if A>=K:
  print(K)
elif A+B>=K:
  print(A)
else:
  print(A+A+B-K)
Buggy python submission (verdict: Runtime Error):
N,M,K=map(int,input().split())
MOD=998244353
X=M*pow(M-1,N-1,MOD)
#X=M*pow(M-1,N-1)
ans=X%MOD
i=1
'''
s=[]
a=1
for j in range(1,K+1):
  a*=N-j
  a=a//j
  s.append(a%MOD)
'''
for k in range(1,K+1):
  i*=(N-k)
  i=i//k
  #ans+=(i*X[-1-k])%MOD
  #i%=MOD
  ans+=((i%MOD)*X*pow(M-1,-k,MOD))%MOD
  #X=X//M-1
  #ans+=(i*X)%MOD
  ans%=MOD
print(ans%MOD)

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

def cmb(n, r, mod):
  if ( r<0 or r>n ):
    return 0
  r = min(r, n-r)
  return g1[n] * g2[r] * g2[n-r] % mod

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
  g1.append( ( g1[-1] * i ) % mod )
  inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
  g2.append( (g2[-1] * inverse[-1]) % mod )

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

Buggy python submission (verdict: Runtime Error):
N,M,K=map(int,input().split())
MOD=998244353
X=M*pow(M-1,N-1,MOD)
#X=M*pow(M-1,N-1)
ans=X%MOD
i=1
s=[]
a=1
for j in range(1,K+1):
  a*=N-j
  a=a//j
  s.append(a%MOD)
for k in range(1,K+1):
  #i*=(N-k)
  #i=i/k
  #ans+=(i*X[-1-k])%MOD
  #i%=MOD
  ans+=(s[k-1]*X*pow(M-1,-k,MOD))%MOD
  #X=X//M-1
  #ans+=(i*X)%MOD
  ans%=MOD
print(ans%MOD)

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

def cmb(n, r, mod):
  if ( r<0 or r>n ):
    return 0
  r = min(r, n-r)
  return g1[n] * g2[r] * g2[n-r] % mod

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
  g1.append( ( g1[-1] * i ) % mod )
  inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
  g2.append( (g2[-1] * inverse[-1]) % mod )

ans=0
for k in range(K+1):
  ans+=(M*pow(M-1,N-1-k,mod)*cmb(N-1,k,mod))%mod
  ans=ans%mod
print(ans%mod)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
ans=0
for i in range(1,N):
  for j in range(N-i):
    if A[j+i]+A[j]==i:
      #print(j,j+i,i)
      ans+=1
print(ans)

Fixed submission:
from collections import defaultdict
di=defaultdict(int)
dj=defaultdict(int)
N=int(input())
A=list(map(int,input().split()))
for i,a in enumerate(A):
    di[i+a]+=1
    dj[i-a]+=1
X=set(di.keys())&set(dj.keys())
ans=0
for x in X:
    ans+=di[x]*dj[x]
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=list(map(int,input().split()))
x=sum(A)
if sum([i if a>=x/4/M else 0 for a in A])>=M:
  print('Yes')
else:
  print('No')

Fixed submission:
N,M=map(int,input().split())
A=list(map(int,input().split()))
x=sum(A)
if sum([1 if a>=x/4/M else 0 for a in A])>=M:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
X,Y,A,B,C=map(int,input().split())
P=sorted(list(map(int,input().split())))[::-1]+[-1]
Q=sorted(list(map(int,input().split())))[::-1]+[-1]
R=sorted(list(map(int,input().split())))[::-1]+[-1]
N=0
ans=0
while 1:
  if P[0]>=Q[0] and P[0]>R[0]:
    ans+=P.pop(0)
    X-=1
    if X+Y==N:
      break
    if X==0:
      P=[-1]
  if Q[0]>=P[0] and Q[0]>=R[0]:
    ans+=Q.pop(0)
    Y-=1
    if X+Y==N:
      break
    if Y==0:
      Q=[-1]
  if R[0]>=P[0] and R[0]>=Q[0]:
    ans+=R.pop(0)
    N+=1
    if X+Y==N:
      break
print(ans)

Fixed submission:
X,Y,A,B,C=map(int,input().split())
import numpy as np
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
R=list(map(int,input().split()))
Xa=np.array(P+Q+R)
Ya=np.array([i for i,j in enumerate([A,B,C]) for k in range(j)])
x = np.argsort(Xa)
Xa=Xa[x]
Xa=Xa[::-1]
Ya=Ya[x]
Ya=Ya[::-1]
ans=0
N=0
nokori=[X,Y]
for i in range(A+B+C):
  if Ya[i]==2:
    N+=1
    ans+=Xa[i]
  elif nokori[Ya[i]]>0:
    nokori[Ya[i]]-=1
    ans+=Xa[i]
  if sum(nokori)==N:
    break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
mode=0
for i in range(Q):
  query=list(input().split())
  if query[0]=='1':
    mode=(mode+1)%2
  if query[0]=='2':
    if query[1]=='1':
      if mode==0:
        S=query[2]+S
      else:
        S=S+query[2]
    else:
      if mode==0:
        S=S+query[2]
      else:
        S=query[2]+S
if mode==1:
  S=S[::-1]
print(S)

Fixed submission:
S=input()
Q=int(input())
mode=0
sento=''
matubi=''
for i in range(Q):
  query=list(input().split())
  if query[0]=='1':
    mode=(mode+1)%2
  if query[0]=='2':
    if query[1]=='1':
      if mode==0:
        sento=query[2]+sento
      else:
        matubi=matubi+query[2]
    else:
      if mode==0:
        matubi=matubi+query[2]
      else:
        sento=query[2]+sento
if mode==1:
  S=matubi[::-1]+S[::-1]+sento[::-1]
else:
  S=sento+S+matubi
print(S)
Buggy python submission (verdict: Runtime Error):
A=list(map(int,input().split()))
A=sorted(A)
if A[0]==A[1] and A[1]!=A[2]:
  print('Yes')
elif if A[2]==A[1] and A[1]!=A[0]:
  print('Yes')
else:
  print('No')

Fixed submission:
A=list(map(int,input().split()))
A=sorted(A)
if A[0]==A[1] and A[1]!=A[2]:
  print('Yes')
elif A[2]==A[1] and A[1]!=A[0]:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
from collections import defaultdict
d = defaultdict(int)
for i in range(N):
  s=input()
  d[s]+=1
x=max(d.values())
max_k_list=[]
while len(d)>0 and max(d.values())==x:
  max_k_list.append(max(d, key=d.get))
  del d[max_k_list[-1]]
max_k_list.sort()
for a in max_k_list:
  print(a)

Fixed submission:
N=int(input())
S = [input() for i in range(N)]
S.sort()
import itertools
gr = itertools.groupby(S)
ans=[]
n=0
for key, group in gr:
  a=len(list(group))
  if a>n:
    ans=[]
    n=a
    ans.append(key)
  elif a==n:
    ans.append(key)
for a in ans:
  print(a)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N=int(input())
lines = sys.stdin.readlines()
from collections import defaultdict
d = defaultdict(int)
for s in lines:
  d[s.rstrip('\n')]+=1
max_k_list = [kv[0] for kv in d.items() if kv[1] == max(d.values())]
max_k_list.sort()
for a in max_k_list:
  print(a)

Fixed submission:
N=int(input())
S = [input() for i in range(N)]
S.sort()
import itertools
gr = itertools.groupby(S)
ans=[]
n=0
for key, group in gr:
  a=len(list(group))
  if a>n:
    ans=[]
    n=a
    ans.append(key)
  elif a==n:
    ans.append(key)
for a in ans:
  print(a)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N=int(input())
from collections import defaultdict
d = defaultdict(int)
for i in range(N):
  S=input()
  d[S]+=1
max_k_list = [kv[0] for kv in d.items() if kv[1] == max(d.values())]
max_k_list.sort()
for a in max_k_list:
  print(a.rstrip('\n'))

Fixed submission:
N=int(input())
S = [input() for i in range(N)]
S.sort()
import itertools
gr = itertools.groupby(S)
ans=[]
n=0
for key, group in gr:
  a=len(list(group))
  if a>n:
    ans=[]
    n=a
    ans.append(key)
  elif a==n:
    ans.append(key)
for a in ans:
  print(a)

Buggy python submission (verdict: Time Limit Exceeded):
#import sys
#input = sys.stdin.readline
N=int(input())
from collections import defaultdict
d = defaultdict(int)
for i in range(N):
  S=input()
  d[S]+=1
max_k_list = [kv[0] for kv in d.items() if kv[1] == max(d.values())]
max_k_list.sort()
for a in max_k_list:
  print(a)

Fixed submission:
N=int(input())
S = [input() for i in range(N)]
S.sort()
import itertools
gr = itertools.groupby(S)
ans=[]
n=0
for key, group in gr:
  a=len(list(group))
  if a>n:
    ans=[]
    n=a
    ans.append(key)
  elif a==n:
    ans.append(key)
for a in ans:
  print(a)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
from collections import defaultdict
d = defaultdict(int)
for i in range(N):
  S=input()
  d[S]+=1
max_k_list = [kv[0] for kv in d.items() if kv[1] == max(d.values())]
A=sorted(max_k_list)
for a in A:
  print(a)

Fixed submission:
N=int(input())
S = [input() for i in range(N)]
S.sort()
import itertools
gr = itertools.groupby(S)
ans=[]
n=0
for key, group in gr:
  a=len(list(group))
  if a>n:
    ans=[]
    n=a
    ans.append(key)
  elif a==n:
    ans.append(key)
for a in ans:
  print(a)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
P=list(map(int,input().split()))
E=[0]*N
for i,p in enumerate(P):
  for j in range(p):
    E[i]+=(j+1)/p
ans=sum(E[:K])
_=sum(E[:K])
for i in range(1,N-K+1):
  _-=E[i-1]
  _+=E[i+K-1]
  if _>ans:
    ans=_
print(ans)

Fixed submission:
N,K=map(int,input().split())
P=list(map(int,input().split()))
E=[(p*(p+1)/2)/p for i,p in enumerate(P) ]
ans=sum(E[:K])
_=sum(E[:K])
for i in range(1,N-K+1):
  _-=E[i-1]
  _+=E[i+K-1]
  if _>ans:
    ans=_
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
if N==1:
  print(1)
  exit()
XL=[list(map(int,input().split())) for i in range(N)]
XL.sort(key=lambda x:x[0]-x[1])
i=0
normv=0
rmv=0
while True:
  if XL[i][0]+XL[i][1]<=XL[i+1][0]-XL[i+1][1]:
    i+=1
    normv+=1
  else:
    if XL[i]>XL[i+1]:
      XL.pop(i)
      rmv+=1
    elif XL[i][0]+XL[i][1] < XL[i+1][0]+XL[i+1][1]:
      XL.pop(i+1)
      i+=1
      normv+=1
      rmv+=1
    else:
      XL.pop(i)
      rmv+=1
  if rmv+normv==N-1:
    break
if len(XL)<2:
  pass
elif XL[-1][0]-XL[-1][0]<XL[-2][0]-XL[-2][0]:
  rmv+=1
else:
  normv+=1
print(len(XL))


Fixed submission:
N=int(input())
XL=[list(map(int,input().split())) for i in range(N)]
XL.sort(key=lambda x:x[0]+x[1])
ans=1
left=XL[0][0]+XL[0][1]
for i in range(1,N):
  if XL[i][0]-XL[i][1] >= left:
    ans+=1
    left=XL[i][0]+XL[i][1]
  else:
    pass
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
XL=[list(map(int,input().split())) for i in range(N)]
XL.sort(key=lambda x:x[0]-x[1])
i=0
normv=0
rmv=0
while True:
  if XL[i][0]+XL[i][1]<=XL[i+1][0]-XL[i+1][1]:
    i+=1
    normv+=1
  else:
    if XL[i]>XL[i+1]:
      XL.pop(i)
      rmv+=1
    elif XL[i][0]+XL[i][1] < XL[i+1][0]+XL[i+1][1]:
      XL.pop(i+1)
      i+=1
      normv+=1
      rmv+=1
    else:
      XL.pop(i)
      rmv+=1
  if rmv+normv==N-1:
    break
if len(XL)<2:
  pass
elif XL[-1][0]-XL[-1][0]<XL[-2][0]-XL[-2][0]:
  rmv+=1
else:
  normv+=1
print(len(XL))

Fixed submission:
N=int(input())
XL=[list(map(int,input().split())) for i in range(N)]
XL.sort(key=lambda x:x[0]+x[1])
ans=1
left=XL[0][0]+XL[0][1]
for i in range(1,N):
  if XL[i][0]-XL[i][1] >= left:
    ans+=1
    left=XL[i][0]+XL[i][1]
  else:
    pass
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
ST=[list(map(int,input().split())) for i in range(N)]
X=input()
ans=-1
for s,t in ST:
  if s !=X and ans==-1:
    continue
  else:
    if ans==-1:
      ans=0
    else:
      ans+=int(t)
print(ans)


Fixed submission:

N=int(input())
ST=[list(input().split()) for i in range(N)]
X=input()
ans=-1
for s,t in ST:
  if s !=X and ans==-1:
    continue
  else:
    if ans==-1:
      ans=0
    else:
      ans+=int(t)
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
ST=[list(map(int,input().split())) for i in range(N)]
X=input()
ans=-1
for s,t in ST:
  if s !=X and ans==-1:
    continue
  else:
    if ans==-1:
      ans=0
    else:
      ans+=t
print(ans)


Fixed submission:

N=int(input())
ST=[list(input().split()) for i in range(N)]
X=input()
ans=-1
for s,t in ST:
  if s !=X and ans==-1:
    continue
  else:
    if ans==-1:
      ans=0
    else:
      ans+=int(t)
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
syougen=[]
for i in range(N):
  A=int(input())
  X=[list(map(int,input().split())) for i in range(A)]
  syougen.append(X)

def search(l):
  global seigo
  for x,y in l:
    if y==1:
      seigo[x-1]=1
    else:
      seigo[x-1]=0
def chk(l):
  global seigo
  for x,y in l:
    if seigo[x-1] != y:
      if seigo[x-1]==100:
        seigo[x-1]=y
        if y==1:
          global syougen
          if chk(syougen[x-1],seigo):
            return True
      else:
      	return True
  return False

ans=0
for i in range(N):
  flg=True
  seigo=[100]*N
  _ans=0
  seigo[i]=1
  search(syougen[i])
  for j in range(N):
    if i==j:
      continue
    if seigo[j]==1:
      if chk(syougen[j]):
        flg=False
        break
    if seigo[j]==100:
      continue
  if flg:
    _ans=sum(seigo)%100
    if ans<_ans:
      ans=_ans
print(ans)

Fixed submission:
N=int(input())
syougen=[]
for i in range(N):
  A=int(input())
  X=[list(map(int,input().split())) for i in range(A)]
  syougen.append(X)

def search(l):
  global seigo,syougen,flg
  for x,y in l:
    if seigo[x-1]==100:
      seigo[x-1]=y
      if y==1:
        search(syougen[x-1])
    elif seigo[x-1]!=y:
      flg=False

ans=0
for i in range(N):
  flg=True
  seigo=[100]*N
  seigo[i]=1
  _ans=0
  search(syougen[i])
  if flg:
    if sum(seigo)>100:
      i=0
      while sum(seigo)>100:
        if seigo[i]==100:
          _seigo=seigo[:]
          flg=True
          seigo[i]=1
          search(syougen[i])
          if flg:
            pass
          else:
            seigo=_seigo[:]
            seigo[i]=0
        i+=1
        i%=N
    _ans=sum(seigo)%100
    if _ans>ans:
      ans=_ans
      maxseigo=seigo        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
l=len(format(max(A),'b'))
Z=[0]*l
for a in A:
  a=format(a,'b').zfill(l)
  for i,ai in enumerate(a):
    if ai=='0':
      Z[i]+=1
x=1
ans=0
for z in Z[::-1]:
  ans+=x*(z*(N-z))
  x*=2
print(ans%(10**9+7))

Fixed submission:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
l=len(format(A.max(),'b'))
MOD=10**9+7

tei=1
ans=0
for i in range(l):
  B=(A >> i) & 1
  one=np.count_nonzero(B)
  zero=N-one
  ans+=tei*one*zero
  tei*=2
print(ans%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
A.sort()
l=len(format(A[-1],'b'))
Z=[0]*l
for a in A:
  a=format(a,'b').zfill(l)
  for i,ai in enumerate(a):
    if ai=='0':
      Z[i]+=1
x=1
ans=0
for z in Z[::-1]:
  ans+=x*(z*(N-z))
  x*=2
print(ans%(10**9+7))

Fixed submission:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
l=len(format(A.max(),'b'))
MOD=10**9+7

tei=1
ans=0
for i in range(l):
  B=(A >> i) & 1
  one=np.count_nonzero(B)
  zero=N-one
  ans+=tei*one*zero
  tei*=2
print(ans%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
A.sort()
ans=0
for i in range(N):
  for j in range(i+1,N):
    ans+=(A[i]^A[j])
print(ans%(10**9+7))

Fixed submission:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
l=len(format(A.max(),'b'))
MOD=10**9+7

tei=1
ans=0
for i in range(l):
  B=(A >> i) & 1
  one=np.count_nonzero(B)
  zero=N-one
  ans+=tei*one*zero
  tei*=2
print(ans%MOD)
Buggy python submission (verdict: Runtime Error):
N=int(input())
P=[tuple(map(int,input().split())) for i in range(N-1)]
Path=[[] for i in range(N)]
for p in P:
  Path[p[0]-1].append(p[1]-1)
  Path[p[1]-1].append(p[0]-1)
colornum=1
dic={}
def bfs(nodes,p,pcolor,selfnum):
  global colornum
  if len(nodes)-1==0 and p!=-1:
    return
  c=1
  for n in nodes:
    if n == p:
      continue
    if c==pcolor:
      c+=1
    dic[(selfnum+1,n+1)]=c
    dic[(n+1,selfnum+1)]=c
    bfs(Path[n],selfnum,c,n)
    c+=1
  if c>colornum:
    colornum=c
bfs(Path[0],-1,0,0)
print(colornum-1)
for p in P:
  print(dic[p])

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
N=int(input())
P=[tuple(map(int,input().split())) for i in range(N-1)]
Path=[[] for i in range(N)]
for p in P:
  Path[p[0]-1].append(p[1]-1)
  Path[p[1]-1].append(p[0]-1)
colornum=1
dic={}
def bfs(nodes,p,pcolor,selfnum):
  global colornum
  if len(nodes)-1==0 and p!=-1:
    return
  c=1
  for n in nodes:
    if n == p:
      continue
    if c==pcolor:
      c+=1
    dic[(selfnum+1,n+1)]=c
    dic[(n+1,selfnum+1)]=c
    bfs(Path[n],selfnum,c,n)
    c+=1
  if c>colornum:
    colornum=c
bfs(Path[0],-1,0,0)
print(colornum-1)
for p in P:
  print(dic[p])
Buggy python submission (verdict: Runtime Error):
import math
X,Y=map(int, input().split())
if (X+Y)%3!=0:
  print(0)
  exit()
n=(X+Y)//3
for i in range(n+1):
  if 2*i +(n-i) == X:
    right=i
    up=n-i
    if 2*(n-i)+i !=Y:
      print(0)
      exit()
    break
  elif 2*(n-i)+i == X:
    up=i
    right=n-i
    if 2*i +(n-i) == Y:
      print(0)
      exit()
    break

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

a = cmb(n,right,mod)
print(a)

Fixed submission:
X,Y=map(int, input().split())
if (X+Y)%3!=0:
  print(0)
  exit()
n=(X+Y)//3
flg=True
for i in range(n+1):
  if 2*i +(n-i) == X:
    right=i
    up=n-i
    flg=False
    break
  elif 2*(n-i)+i == X:
    up=i
    right=n-i
    flg=False
    break
if flg:
  print(0)
  exit()
  

def cmb(n, r, mod):
    if r<0 or r>n :
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

a = cmb(n,right,mod)
print(a)

Buggy python submission (verdict: Runtime Error):
import math
X,Y=map(int, input().split())
if (X+Y)%3!=0:
  print(0)
  exit()
n=(X+Y)//3
for i in range(n+1):
  if 2*i +(n-i) == X:
    right=i
    up=n-i
    break
  elif 2*(n-i)+i == X:
    up=i
    right=n-i
    break

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

a = cmb(n,right,mod)
print(a)

Fixed submission:
X,Y=map(int, input().split())
if (X+Y)%3!=0:
  print(0)
  exit()
n=(X+Y)//3
flg=True
for i in range(n+1):
  if 2*i +(n-i) == X:
    right=i
    up=n-i
    flg=False
    break
  elif 2*(n-i)+i == X:
    up=i
    right=n-i
    flg=False
    break
if flg:
  print(0)
  exit()
  

def cmb(n, r, mod):
    if r<0 or r>n :
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

a = cmb(n,right,mod)
print(a)