Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
import fractions
import copy
import numpy as np

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
n = ip()
s = input()
scut = [s[i] for i in range(len(s))]
scut.sort()
for i in range(n-1):
	s = input()
	sncut = [s[i] for i in range(len(s))]
	sncut.sort()
	nextline = []
	while len(sncut) and len(scut):
	  if sncut[0] == scut[0]:
	  	nextline.append(sncut[0])
	  	scut.pop(0)
	  	sncut.pop(0)
	  elif sncut[0] > scut[0]:
	  	scut.pop(0)
	  else: sncut.pop(0)
	scut = copy.copy(nextline)
print(''.join(nextline))

Fixed submission:
import math
import fractions
import copy
import numpy as np

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
n = ip()
s = input()
scut = [s[i] for i in range(len(s))]
scut.sort()
if n == 1:
	print(''.join(scut))
	exit(0)
for i in range(n-1):
	s = input()
	sncut = [s[i] for i in range(len(s))]
	sncut.sort()
	nextline = []
	while len(sncut) and len(scut):
	  if sncut[0] == scut[0]:
	  	nextline.append(sncut[0])
	  	scut.pop(0)
	  	sncut.pop(0)
	  elif sncut[0] > scut[0]:
	  	scut.pop(0)
	  else: sncut.pop(0)
	scut = copy.copy(nextline)
print(''.join(nextline))
Buggy python submission (verdict: Runtime Error):
from statistics import mean, median,variance,stdev
import sys
import math

x = input().split()
#y = input().split()
a = []
#for i in range(len(x)):
 #  a.append(int(x[i]))
if a[0] <1200:print("ABC")
else:print("ARC")

Fixed submission:
from statistics import mean, median,variance,stdev
import sys
import math

x = input().split()
#y = input().split()
a = []
for i in range(len(x)):
   a.append(int(x[i]))
if a[0] <1200:print("ABC")
else:print("ARC")
Buggy python submission (verdict: Runtime Error):
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy

def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("GREATER")
    elif (x<y): print("LESS")
    else: print("EQUAL")

def ip():
    return int(input())


def calculate(a):
    s = 0
    for i in range(len(a)):
        for k in range(i+1,len(a)):
            s+=(a[i]*a[k])
    return s

#n = ip()                              #入力整数1つ
h,w= (int(i) for i in input().split())      #入力整数横2つ
#n,a,b = (int(i) for i in input().split())    #入力整数横3つ
#n,a,b,c= (int(i) for i in input().split())  #入力整数横4つ
#s = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(h)]
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
a =[]
for i in range(n):
	a.append(input())
for i in range(n):
	print(a[i])
	print(a[i])


Fixed submission:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy

def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("GREATER")
    elif (x<y): print("LESS")
    else: print("EQUAL")

def ip():
    return int(input())


def calculate(a):
    s = 0
    for i in range(len(a)):
        for k in range(i+1,len(a)):
            s+=(a[i]*a[k])
    return s

#n = ip()                              #入力整数1つ
n,m= (int(i) for i in input().split())      #入力整数横2つ
#n,a,b = (int(i) for i in input().split())    #入力整数横3つ
#n,a,b,c= (int(i) for i in input().split())  #入力整数横4つ
#s = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(h)]
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
a =[]
for i in range(n):
	a.append(input())
for i in range(n):
	print(a[i])
	print(a[i])
Buggy python submission (verdict: Runtime Error):
from statistics import mean, median,variance,stdev
import sys
import math
import fractions
def j(a):
    if a==1: print("YES")
    else :print("NO")


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

#x = int(input())                              #入力整数1つ
#x,y = (int(i) for i in input().split())      #入力整数横2つ
x,y,z = (int(i) for i in input().split())    #入力整数横3つ
#a,b,c,k = (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
#x = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
lower = (x//z)*z
if lower < x: lower+=z
high = (y//z)*z
print((high - low)/z+1)

Fixed submission:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
#n = ip()                                     #入力整数1つ
x,y,z= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[input() for i in range(x)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
low = (x//z)*z
if low < x: low+=z
high = (y//z)*z
print((high - low)//z+1)
Buggy python submission (verdict: Runtime Error):
k,n=map(int,input().split())
a=list(map(int,input().split()))
d=abs(d[0]-d[-1])
for i in range(n-1):
  d=max(d,abs(a[i]-a[i+1]))
print(k-d)

Fixed submission:
k,n=map(int,input().split())
a=list(map(int,input().split()))+[k]
d=abs(a[0]+(k-a[-2]))
for i in range(n):
  d=max(d,abs(a[i]-a[i+1]))
print(k-d)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input(),split())
if 2*((a*b)**0.5)<c**2-a-b:
  print('Yes')
else:
  print('No')

Fixed submission:
a,b,c=map(int,input().split())
if c>=a+b and 4*a*b<(c-a-b)**2:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
for _ in range(q):
  t=list(input().split())
  if len(t)==1:
    s=s[::-1]
  else:
    if int(t[1])==1:
      s=t[2]+s
    else:
      s=s+t[2]
print(s)

Fixed submission:
s=list(input())
q=int(input())
t1,t2=[],[]
cnt=0
for _ in range(q):
  t=list(input().split())
  if len(t)==1:
    cnt+=1
    t1,t2=t2,t1
  else:
    if int(t[1])==1:
      t1+=[t[2]]
    else:
      t2+=[t[2]]
if cnt%2==1:
  s=s[::-1]
u=t1[::-1]+s+t2
print(''.join(u))

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
q=int(input())
for _ in range(q):
  t=list(input().split())
  if len(t)==1:
    s=s[::-1]
  else:
    if int(t[1])==1:
      s=[t[2]]+s
    else:
      s=s+[t[2]]
print(''.join(s))


Fixed submission:
s=list(input())
q=int(input())
t1,t2=[],[]
cnt=0
for _ in range(q):
  t=list(input().split())
  if len(t)==1:
    cnt+=1
    t1,t2=t2,t1
  else:
    if int(t[1])==1:
      t1+=[t[2]]
    else:
      t2+=[t[2]]
if cnt%2==1:
  s=s[::-1]
u=t1[::-1]+s+t2
print(''.join(u))

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
q=int(input())
for _ in range(q):
  t=list(input().split())
  if len(t)==1:
    s=s[::-1]
  else:
    if int(t[1])==1:
      s=[t[2]]+s
    else:
      s=s+[t[2]]
print(''.join(s))

Fixed submission:
s=list(input())
q=int(input())
t1,t2=[],[]
cnt=0
for _ in range(q):
  t=list(input().split())
  if len(t)==1:
    cnt+=1
    t1,t2=t2,t1
  else:
    if int(t[1])==1:
      t1+=[t[2]]
    else:
      t2+=[t[2]]
if cnt%2==1:
  s=s[::-1]
u=t1[::-1]+s+t2
print(''.join(u))
Buggy python submission (verdict: Runtime Error):
a=[list(map(int,input().split()))]
n=int(input())
for _ in range(n):
  b=int(input())
  for i in range(3):
    for j in range(3):
      if a[i][j]==b:
        a[i][j]=-1
for i in range(3):
  if a[i][0]==a[i][1]==a[i][2]==-1:
    print('Yes')
    exit()
  if a[0][i]==a[1][i]==a[2][i]==-1:
    print('Yes')
    exit()
if a[0][0]==a[1][1]==a[2][2]==-1 or a[0][2]==a[1][1]==a[2][0]==-1:
  print('Yes')
  exit()
print('No')


Fixed submission:
a=[list(map(int,input().split())) for i in range(3)]
n=int(input())
for _ in range(n):
  b=int(input())
  for i in range(3):
    for j in range(3):
      if a[i][j]==b:
        a[i][j]=-1
for i in range(3):
  if a[i][0]==a[i][1]==a[i][2]==-1:
    print('Yes')
    exit()
  if a[0][i]==a[1][i]==a[2][i]==-1:
    print('Yes')
    exit()
if a[0][0]==a[1][1]==a[2][2]==-1 or a[0][2]==a[1][1]==a[2][0]==-1:
  print('Yes')
  exit()
print('No')

Buggy python submission (verdict: Runtime Error):
a=[list(map(int,input().split()))]
n=int(input())
for i in range(n):
  b=int(input())
  for i in range(3):
    for j in range(3):
      if a[i][j]==b:
        a[i][j]=-1
for i in range(3):
  if a[i][0]==a[i][1]==a[i][2]==-1:
    print('Yes')
    exit()
  if a[0][i]==a[1][i]==a[2][i]==-1:
    print('Yes')
    exit()
if a[0][0]==a[1][1]==a[2][2]==-1 or a[0][2]==a[1][1]==a[2][0]==-1:
  print('Yes')
  exit()
print('No')

Fixed submission:
a=[list(map(int,input().split())) for i in range(3)]
n=int(input())
for _ in range(n):
  b=int(input())
  for i in range(3):
    for j in range(3):
      if a[i][j]==b:
        a[i][j]=-1
for i in range(3):
  if a[i][0]==a[i][1]==a[i][2]==-1:
    print('Yes')
    exit()
  if a[0][i]==a[1][i]==a[2][i]==-1:
    print('Yes')
    exit()
if a[0][0]==a[1][1]==a[2][2]==-1 or a[0][2]==a[1][1]==a[2][0]==-1:
  print('Yes')
  exit()
print('No')
Buggy python submission (verdict: Time Limit Exceeded):
def comb(n,k,p):
  from math import factorial
  if n<0 or k<0 or n<k:return 0
  if n==0 and k==0:return 1
  a=factorial(n)%p
  b=factorial(k)%p
  c=factorial(n-k)%p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  if b==0:
    return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return (d*d)%p
  else:
    return (a*power_func(a,b-1,p))%p
n,k=map(int,input().split())
mod=10**9+7
ans=0
r=min(k,n)
for i in range(r+1):
  ans=(ans+comb(n,i,mod)*comb(n-1,i,mod))%mod
print(ans)

Fixed submission:
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
def power_func(a,b,p):
  if b==0:
    return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return (d*d)%p
  else:
    return (a*power_func(a,b-1,p))%p
n,k=map(int,input().split())
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 )
ans=0
r=min(k,n)
for i in range(r+1):
  ans=(ans+cmb(n,i,mod)*cmb(n-1,i,mod))%mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil
import sys
input=sys.stdin.readline
k,q=map(int,input().split())
d=list(map(int,input().split()))
for _ in range(q):
  n,x,m=map(int,input().split())
  dd=[d[i]%m for i in range(k)]
  cnt1=0
  cnt2=0
  for i in range(k):
    if dd[i]==0:
      cnt1+=ceil((n-i-1)/k)
  a=x
  for i in range(k):
    a+=ceil((n-i-1)/k)*dd[i]
  cnt2=a//m-x//m
  print(n-1-cnt1-cnt2)

Fixed submission:
import sys
input=sys.stdin.readline
k,q=map(int,input().split())
d=list(map(int,input().split()))
for _ in range(q):
  n,x,m=map(int,input().split())
  dd=[d[i]%m for i in range(k)]
  for i in range(k):
    if dd[i]==0:
      dd[i]=m
  s=x%m+sum(dd)*((n-1)//k)+sum(dd[:(n-1)%k])
  print(n-1-s//m)

Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil,floor
k,q=map(int,input().split())
d=list(map(int,input().split()))
for _ in range(q):
  n,x,m=map(int,input().split())
  dd=[d[i]%m for i in range(k)]
  cnt1=0
  cnt2=0
  for i in range(k):
    if dd[i]==0:
      cnt1+=ceil((n-i-1)/k)
  a=x
  for i in range(k):
    a+=ceil((n-i-1)/k)*dd[i]
  cnt2=a//m-x//m
  print(n-1-cnt1-cnt2)


Fixed submission:
import sys
input=sys.stdin.readline
k,q=map(int,input().split())
d=list(map(int,input().split()))
for _ in range(q):
  n,x,m=map(int,input().split())
  dd=[d[i]%m for i in range(k)]
  for i in range(k):
    if dd[i]==0:
      dd[i]=m
  s=x%m+sum(dd)*((n-1)//k)+sum(dd[:(n-1)%k])
  print(n-1-s//m)

Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil,floor
k,q=map(int,input().split())
d=list(map(int,input().split()))
for _ in range(q):
  n,x,m=map(int,input().split())
  dd=[d[i]%m for i in range(k)]
  cnt1=0
  cnt2=0
  for i in range(k):
    if dd[i]==0:
      cnt1+=ceil((n-i-1)/k)
  a=x
  for i in range(k):
    a+=ceil((n-i-1)/k)*dd[i]
  cnt2=a//m-x//m
  print(n-1-cnt1-cnt2)

Fixed submission:
import sys
input=sys.stdin.readline
k,q=map(int,input().split())
d=list(map(int,input().split()))
for _ in range(q):
  n,x,m=map(int,input().split())
  dd=[d[i]%m for i in range(k)]
  for i in range(k):
    if dd[i]==0:
      dd[i]=m
  s=x%m+sum(dd)*((n-1)//k)+sum(dd[:(n-1)%k])
  print(n-1-s//m)
Buggy python submission (verdict: Runtime Error):
import Counter
n=int(input())
s=[input() for i in range(n)]
c=Counter(s)
l=list(c)
l.sort(key=lambda x:x[1],reverse=True)
a=l[0][1]
i=0
while i<n and l[i][1]==a:
  print(l[i][0])
  i+=1

Fixed submission:
from collections import Counter
n=int(input())
s=[input() for i in range(n)]
c=Counter(s)
t=[]
u=c.most_common()
v=u[0][1]
t.append(u[0][0])
for i in range(1,len(c)):
  a=u[i][1]
  if v>a:
    break
  else:
    t.append(u[i][0])
t.sort()
for i in t:
  print(i)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n=int(input())
s=[input() for i in range(n)]
c=Counter(s)
t=[]
v=c.most_common()[0][1]
t.append(c.most_common()[0][0])
for i in range(1,len(c)):
  a=c.most_common()[i][1]
  if v>a:
    break
  else:
    t.append(c.most_common()[i][0])
t.sort()
for i in t:
  print(i)

Fixed submission:
from collections import Counter
n=int(input())
s=[input() for i in range(n)]
c=Counter(s)
t=[]
u=c.most_common()
v=u[0][1]
t.append(u[0][0])
for i in range(1,len(c)):
  a=u[i][1]
  if v>a:
    break
  else:
    t.append(u[i][0])
t.sort()
for i in t:
  print(i)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
s=[input() for i in range(n)]
c=Counter(s)
t=[]
v=c.most_common()[0][1]
t.append(c.most_common()[0][0])
for i in range(1,n):
  a=c.most_common()[i][1]
  if v>a:
    break
  else:
    t.append(c.most_common()[i][0])
t.sort()
for i in t:
  print(i)

Fixed submission:
from collections import Counter
n=int(input())
s=[input() for i in range(n)]
c=Counter(s)
t=[]
u=c.most_common()
v=u[0][1]
t.append(u[0][0])
for i in range(1,len(c)):
  a=u[i][1]
  if v>a:
    break
  else:
    t.append(u[i][0])
t.sort()
for i in t:
  print(i)
Buggy python submission (verdict: Runtime Error):
h,n=map(int,input())
a = list(map(int,input().split()))
print('Yes' if sum(a)>=h else 'No')

Fixed submission:
h,n=map(int,input().split())
a = list(map(int,input().split()))
print('Yes' if sum(a)>=h else 'No')
Buggy python submission (verdict: Runtime Error):
import math
h=int(input())
m=int(math.long(h,2))
print(2**(h+1)-1)


Fixed submission:
import math
h=int(input())
m=int(math.log(h,2))
print(int(2**(m+1)-1))

Buggy python submission (verdict: Runtime Error):
h=int(input())
m=int(math.long(h,2))
print(2**(h+1)-1)

Fixed submission:
import math
h=int(input())
m=int(math.log(h,2))
print(int(2**(m+1)-1))
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
g=a[0]
for i in range(1,n):
  g=g*a[i]/gcd(g,a[i])
suml=0
for i in range(n):
  suml+=g/a[i]
  suml%=10**9+7
print(int(suml))

Fixed submission:
import fractions
n=int(input())
a=[int(i) for i in input().split()]
g=1
dx=fractions.gcd
for i in a:
  g*=i//dx(g,i)
suml=0
mod=10**9+7
for i in a:
  suml+=g*pow(i,mod-2,mod)
  suml%=mod
print(suml)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
cnt=[0]*(n+1)
l=[0]*(n+1)
ac=0
wa=0
for i in range(m):
  p,s=input().split()
  p=int(p)
  if l[p]!=0:
    continue
  if l[p]==0 and s=='WA':
    cnt[i]+=1
  if l[p]==0 and s=='AC':
    ac+=1
    l[p]=1
for i in range(1,n+1):
  if l[i]!=0:
    wa+=cnt[i]
print(ac,wa)

Fixed submission:
n,m=map(int,input().split())
cnt=[0]*(n+1)
l=[0]*(n+1)
ac=0
wa=0
for i in range(m):
  p,s=input().split()
  p=int(p)
  if l[p]==1:
    continue
  if l[p]==0 and s=='WA':
    cnt[p]+=1
  if l[p]==0 and s=='AC':
    ac+=1
    l[p]=1
for i in range(1,n+1):
  if l[i]==1:
    wa+=cnt[i]
print(ac,wa)
Buggy python submission (verdict: Runtime Error):
from itertools import permutations
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
l=list(itertools.permutations([i for i in range(1,n+1)]))
a=0
b=0
for i in range(len(l)):
  if l[i]==p:
    a=i
  if l[i]==q:
    b=i
print(abs(a-b))

Fixed submission:
import itertools as it
s = list(range(1,int(input())+1))
a = list(it.permutations(s))
p,q = [tuple(map(int,input().split())) for i in range(2)]
print(abs(a.index(p)-a.index(q)))
Buggy python submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
if a+b<=k:
  print("0 0")
elif a>=k:
  print((a-k)+" "+b)
else print(0+" "+(a+b-k))

Fixed submission:
a,b,k=map(int,input().split())
if a+b<=k:
  print(0,0)
elif a>=k:
  print(a-k,b)
else :print(0,a+b-k)
Buggy python submission (verdict: Runtime Error):
print(6-int(input)-int(input))

Fixed submission:
print(6-int(input())-int(input()))
Buggy python submission (verdict: Runtime Error):
import math
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
if max(a)==0:
  print(0)
  exit()
m=math.floor(math.log2(max(a)))+1
ans=0
for i in range(m):
  cnt0=0
  cnt1=0
  for j in range(n):
    if a[j]>>i&1:
      cnt1+=1
    else:
      cnt0+=1
  ans+=(2**i)*(cnt1*cnt0)
  ans%=mod
print(ans)

Fixed submission:
import numpy as np
n=int(input())
a=np.array([int(i) for i in input().split()])
mod=int(1e9+7)
ans=0
for k in range(60):
  b=(a>>k)&1
  m=np.count_nonzero(b)
  ans+=m*(n-m)*2**k
  ans%=mod
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
m=math.floor(math.log2(max(a)))+1
ans=0
for i in range(m):
  cnt0=0
  cnt1=0
  for j in range(n):
    if a[j]>>i&1:
      cnt1+=1
    else:
      cnt0+=1
  ans+=(2**i)*(cnt1*cnt0)
  ans%=mod
print(ans)

Fixed submission:
import numpy as np
n=int(input())
a=np.array([int(i) for i in input().split()])
mod=int(1e9+7)
ans=0
for k in range(60):
  b=(a>>k)&1
  m=np.count_nonzero(b)
  ans+=m*(n-m)*2**k
  ans%=mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
INF=10**9+7
md=len(bin(max(a)))-2
ans=0
for i in range(md):
  cnt1=sum([1 for j in a if (j>>i)&1])
  ans+=cnt1*(n-cnt1)*(1<<i)
  ans%=INF
print(ans%INF)


Fixed submission:
import numpy as np
n=int(input())
a=np.array([int(i) for i in input().split()])
mod=int(1e9+7)
ans=0
for k in range(60):
  b=(a>>k)&1
  m=np.count_nonzero(b)
  ans+=m*(n-m)*2**k
  ans%=mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
INF=10**9+7
md=len(bin(max(a)))
ans=0
for i in range(md):
  cnt1=sum([1 for j in a if (j>>i)&1])
  ans+=cnt1*(n-cnt1)*(1<<i)
  ans%=INF
print(ans%INF)

Fixed submission:
import numpy as np
n=int(input())
a=np.array([int(i) for i in input().split()])
mod=int(1e9+7)
ans=0
for k in range(60):
  b=(a>>k)&1
  m=np.count_nonzero(b)
  ans+=m*(n-m)*2**k
  ans%=mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import copy
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):
    if i==j:
      continue
    b=copy.deepcopy(a)
    b.remove(a[i])
    b.remove(a[j])
    ans+=bisect.bisect_left(b,a[i]+a[j])-j+1
print(ans)

Fixed submission:
import bisect
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+=bisect.bisect_left(a,a[i]+a[j])-j-1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import copy
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):
    if i==j:
      continue
    b=copy.deepcopy(a)
    b.remove(a[i])
    b.remove(a[j])
    ans+=bisect.bisect_left(b,a[i]+a[j])-j+1
print(ans)

Fixed submission:
import bisect
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+=bisect.bisect_left(a,a[i]+a[j])-j-1
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
h=map(int,input().split())
dp=[0]*n
for i in range(1,n):
  if h[i-1]>=h[i]:
    dp[i]=dp[i-1]+1
  else:
    dp[i]=0
print(max(dp))

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
for i in range(1,n):
  if h[i-1]>=h[i]:
    dp[i]=dp[i-1]+1
  else:
    dp[i]=0
print(max(dp))
Buggy python submission (verdict: Time Limit Exceeded):
n,Q=map(int,input().split())
g=[[] for i in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  g[a-1].append(b-1)
  g[b-1].append(a-1)
depth=[-1]*n
depth[0]=0
q=[0]
while q:
  x=q.pop()
  for t in g[x]:
    if depth[t]==-1:
      depth[t]=depth[x]+1
      q.append(t)
cnt=[0]*n
for _ in range(Q):
  p,x=map(int,input().split())
  q=[p-1]
  while q:
    y=q.pop()
    cnt[y]+=x
    for t in g[y]:
      if depth[t]>depth[y]:
        q.append(t)
print(*cnt)

Fixed submission:
n,Q=map(int,input().split())
g=[[] for i in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  g[a-1].append(b-1)
  g[b-1].append(a-1)
depth=[-1]*n
depth[0]=0
q=[0]
while q:
  x=q.pop()
  for t in g[x]:
    if depth[t]==-1:
      depth[t]=depth[x]+1
      q.append(t)
cnt=[0]*n
for _ in range(Q):
  p,x=map(int,input().split())
  cnt[p-1]+=x
q=[0]
visited=[False]*n
while q:
  x=q.pop()
  visited[x]=True
  for t in g[x]:
    if not visited[t]:
      cnt[t]+=cnt[x]
      q.append(t)
print(*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n,Q=map(int,input().split())
g=[[] for i in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  g[a-1].append(b-1)
  g[b-1].append(a-1)
depth=[-1]*n
depth[0]=0
q=[0]
while q:
  x=q.pop()
  for t in g[x]:
    if depth[t]==-1:
      depth[t]=depth[x]+1
      q.append(t)
cnt=[0]*n
for _ in range(Q):
  p,x=map(int,input().split())
  q=[p-1]
  while q:
    y=q.pop()
    cnt[y]+=x
    for t in g[y]:
      if depth[t]>depth[y]:
        q.append(t)
print(*cnt)

Fixed submission:
n,Q=map(int,input().split())
g=[[] for i in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  g[a-1].append(b-1)
  g[b-1].append(a-1)
depth=[-1]*n
depth[0]=0
q=[0]
while q:
  x=q.pop()
  for t in g[x]:
    if depth[t]==-1:
      depth[t]=depth[x]+1
      q.append(t)
cnt=[0]*n
for _ in range(Q):
  p,x=map(int,input().split())
  cnt[p-1]+=x
q=[0]
visited=[False]*n
while q:
  x=q.pop()
  visited[x]=True
  for t in g[x]:
    if not visited[t]:
      cnt[t]+=cnt[x]
      q.append(t)
print(*cnt)