Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math

S = list(input())
Q = input()

for i in range(int(Q)):
  Query = input().split()
  if len(Query) == 1:
    S.reverse()
  else:
    C = Query[2]
    if int(Query[1]) == 1:
      S.insert(0,C)
    else:
      S.insert(len(S),C)

print(''.join(S))

Fixed submission:
from collections import deque
import sys

S = input()
Q = int(input())
t = deque(S)
rev = False

for _ in range(Q):
  Query = input().split()
  if Query[0] == '1':
    rev = not rev
    
  else:
    F = Query[1]
    C = Query[2]
    if F == '1':
      if rev:
        t.append(C)
      else:
        t.appendleft(C)
    else:
      if rev:
        t.appendleft(C)
      else:
        t.append(C)

result = ''.join(t) 
if rev:
  print(result[::-1])
else:
  print(result)
Buggy python submission (verdict: Runtime Error):
a=input()
p1=a[0]
p2=a[1]
p3=a[3]
 
if p1==p2==p3:
 print("No")
else:
 print("Yes")

Fixed submission:
a=input()
p1=a[-1]
p2=a[0]
p3=a[1]
 
if p1==p2==p3:
  print("No")
else:
  print("Yes")

Buggy python submission (verdict: Runtime Error):
a=input()
p1=a[0]
p2=a[1]
p3=a[3]
 
if p1==p2==p3:
	print("No")
else:
	print("Yes")

Fixed submission:
a=input()
p1=a[-1]
p2=a[0]
p3=a[1]
 
if p1==p2==p3:
  print("No")
else:
  print("Yes")

Buggy python submission (verdict: Runtime Error):
a=input()
p1=a[0]
p2=a[1]
p3=a[3]

if p1==p2==p3:
  print("No")
else:
  print("Yes")

Fixed submission:
a=input()
p1=a[-1]
p2=a[0]
p3=a[1]
 
if p1==p2==p3:
  print("No")
else:
  print("Yes")
Buggy python submission (verdict: Runtime Error):
 N=int(raw_input())
A=int(raw_input())
prom N*N-A

Fixed submission:
N=int (raw_input())
A=int(raw_input())
print N*N-A
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
Q = int(input())
for i in range(Q):
    t = input()
    if len(t) == 1:
        s = s[::-1]
    else:
        if t[2] == '1':
            s = t[4] + s
        else:
            s += t[4]
print(s)

Fixed submission:
s = input()
Q = int(input())
r = -1
head = ''
tail = ''
for i in range(Q):
    t = input()
    if t[0] == '1':
        r *= -1
    else:
        if t[2] == '1':
            if r == 1:
                tail += t[4]
            else:
                head = t[4] + head
        else:
            if r == 1:
                head = t[4] + head
            else:
                tail += t[4]
if r == 1:
    print(tail[::-1] + s[::-1] + head[::-1])
else:
    print(head + s + tail)
Buggy python submission (verdict: Runtime Error):
import math

N,X=input().split()
N=int(N)
X=int(X)
x = [int(i) for i in input().split()]
x.append(X)
x.sort()
de=[]#deference 差
for i in range( 0, len(x)-1 ):
    dei=x[i+1]-x[i]
    if(dei>0):
        de.append(dei)

#最大公約数だった
#その数を作る素因数をすべて抜き出し、
#一致するものをすべて抜き出せばできる
gcd=de[0]#最大公約数
for i in range(1,len(de)):
    gcd=math.gcd(gcd,de[i])
print(gcd)

Fixed submission:
#import math
import fractions

N,X=input().split()
N=int(N)
X=int(X)
x = [int(i) for i in input().split()]
x.append(X)
x.sort()
de=[]#deference 差
for i in range( 0, len(x)-1 ):
    dei=x[i+1]-x[i]
    if(dei>0):
        de.append(dei)

#最大公約数だった
#その数を作る素因数をすべて抜き出し、
#一致するものをすべて抜き出せばできる
gcddd=de[0]#最大公約数
for i in range(1,len(de)):
    gcddd=fractions.gcd(gcddd,de[i])
print(gcddd)

Buggy python submission (verdict: Runtime Error):
N,X=input().split()
N=int(N)
X=int(X)

x = [int(i) for i in input().split()]
x.append(X)
x.sort()

de=[]#deference 差
for i in range( 0, len(x)-1 ):
    dei=x[i+1]-x[i]
    if(dei>0):
        de.append(dei)

#最大公約数だった
#その数を作る素因数をすべて抜き出し、
#一致するものをすべて抜き出せばできる
import math
gcd=de[0]#最大公約数
for i in range(1,len(de)):
    gcd=math.gcd(gcd,de[i])

print(gcd)

Fixed submission:
#import math
import fractions

N,X=input().split()
N=int(N)
X=int(X)
x = [int(i) for i in input().split()]
x.append(X)
x.sort()
de=[]#deference 差
for i in range( 0, len(x)-1 ):
    dei=x[i+1]-x[i]
    if(dei>0):
        de.append(dei)

#最大公約数だった
#その数を作る素因数をすべて抜き出し、
#一致するものをすべて抜き出せばできる
gcddd=de[0]#最大公約数
for i in range(1,len(de)):
    gcddd=fractions.gcd(gcddd,de[i])
print(gcddd)
Buggy python submission (verdict: Runtime Error):
# coding:utf-8


from math import ceil

import numpy as np

strInput = input()
N, A, B = np.array(strInput.split(' ')).astype(int)
numGroup = floor(N / (A + B))
numExtendBall = N % (A + B)
if numExtendBall >= A:
    numExtendBlueBall = A
else:
    numExtendBlueBall = numExtendBall
print(numGroup * A + numExtendBlueBall)


Fixed submission:
# coding:utf-8


from math import floor

import numpy as np

strInput = input()
N, A, B = np.array(strInput.split(' ')).astype(int)
numGroup = floor(N / (A + B))
numExtendBall = N % (A + B)
if numExtendBall >= A:
    numExtendBlueBall = A
else:
    numExtendBlueBall = numExtendBall
print(numGroup * A + numExtendBlueBall)

Buggy python submission (verdict: Runtime Error):
# coding:utf-8


import numpy as np

strInput = input()
N, A, B = np.array(strInput.split(' ')).astype(int)
lsStrBall = []
while True:
    lsStrBall += ['b'] * A
    lsStrBall += ['r'] * B
    if len(lsStrBall) >= N:
        break

arrStrBall = np.array(lsStrBall)
print((arrStrBall[:N] == 'b').sum())


Fixed submission:
# coding:utf-8


from math import floor

import numpy as np

strInput = input()
N, A, B = np.array(strInput.split(' ')).astype(int)
numGroup = floor(N / (A + B))
numExtendBall = N % (A + B)
if numExtendBall >= A:
    numExtendBlueBall = A
else:
    numExtendBlueBall = numExtendBall
print(numGroup * A + numExtendBlueBall)
Buggy python submission (verdict: Runtime Error):
n = list(map(input().split()))
if len(set(n)) == 1:
    print("No")
else:
    print("Yes")

Fixed submission:
n = input()
s = list(n)
if len(set(s)) == 1:
    print("No")
else:
    print("Yes")

Buggy python submission (verdict: Runtime Error):
n = list(map(input().split()))
if len(set(n)) == 2:
    print("No")
else:
    print("Yes")

Fixed submission:
n = input()
s = list(n)
if len(set(s)) == 1:
    print("No")
else:
    print("Yes")

Buggy python submission (verdict: Runtime Error):
n = list(map(input().split()))
if len(set(n)) == 3:
    print("No")
else:
    print("Yes")

Fixed submission:
n = input()
s = list(n)
if len(set(s)) == 1:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n % 2 == 1:
  print (n-1) /2
print(n/2)

Fixed submission:
n = int(input())
if n % 2 == 1:
  print(int((n+1) / 2))
  exit(0)
print(int(n/2))
Buggy python submission (verdict: Runtime Error):
n = list(map(int, input().split()))
if n[0] == n[1]:
    if n[0] == n[2]:
    print("Yes")
print("No")

Fixed submission:
n = list(map(int, input().split()))
if n[0] != n[1]:
    if n[1] == n[2]:
        print("Yes")
        exit()
    if n[0] == n[2]:
        print("Yes")
        exit()
    if n[0] != n[2]:
        print("No")
        exit()
if n[0] == n[1]:
    if n[0] != n[2]:
        print("Yes")
        exit()
print("No")

Buggy python submission (verdict: Runtime Error):
n = list(map(int, input().split()))
if n[0] !== n[1]:
    print("Yes")
    exit(0)
if n[0] !== n[2]:
    print("Yes")
    exit(0)
print("No")

Fixed submission:
n = list(map(int, input().split()))
if n[0] != n[1]:
    if n[1] == n[2]:
        print("Yes")
        exit()
    if n[0] == n[2]:
        print("Yes")
        exit()
    if n[0] != n[2]:
        print("No")
        exit()
if n[0] == n[1]:
    if n[0] != n[2]:
        print("Yes")
        exit()
print("No")

Buggy python submission (verdict: Runtime Error):
n = list(map(int, input().split()))
if n[0] !== n[1]:
    print("Yes")
    return
if n[0] !== n[2]:
    print("Yes")
    return
print("No")

Fixed submission:
n = list(map(int, input().split()))
if n[0] != n[1]:
    if n[1] == n[2]:
        print("Yes")
        exit()
    if n[0] == n[2]:
        print("Yes")
        exit()
    if n[0] != n[2]:
        print("No")
        exit()
if n[0] == n[1]:
    if n[0] != n[2]:
        print("Yes")
        exit()
print("No")
Buggy python submission (verdict: Runtime Error):
rangeNum = int(input())
n = list(map(int, input().split()))

ans = True
for ni in range(rangeNum+1):
    if n[ni] % 2 == 0:
        if n[ni] % 3 == 0:
            break
        elif n[ni] % 5 == 0:
            break
        else:
            ans = False
    else:
        ans = False
if ans==True:
    print("APPROVED")
else:
    print("DENIED")

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

for ni in range(rangeNum):
    if n[ni]%2 == 0:
        if n[ni]%3 == 0:
            continue
        elif n[ni]%5 == 0:
            continue
        else:
            print("DENIED")
            exit()
    else:
        continue
print("APPROVED")
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
sa,tb = map(int,input())
u = input()
if u == s:
    sa -= 1
else:
    tb -= 1
print(sa,tb)



Fixed submission:
s,t = input().split()
sa,tb = map(int,input().split())
u = input()
if u == s:
    sa -= 1
else:
    tb -= 1
print(sa,tb)
Buggy python submission (verdict: Runtime Error):
a = int(input())
print(3a**2)

Fixed submission:
a = int(input())
print(3*a**2)
Buggy python submission (verdict: Runtime Error):
s = input().split()
if s[0]==s[1] or s[1]==s[2] or s[2] == s[3]:
    print("Bad")
else:
    print("Good")

Fixed submission:
s = input()
if s[0]==s[1] or s[1]==s[2] or s[2] == s[3]:
    print("Bad")
else:
    print("Good")
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
p=list(map(int,input().split()))
ans=0
c=0
for i in range(n-k+1):
    if sum(p[i:i+k])>=c:
        c=sum(p[i:i+k])
print(c/2+0.5*k)

Fixed submission:
n,k=map(int,input().split())
p=list(map(int,input().split()))
s=[p[0]]
for i in range(1,n):
    s.append(s[-1]+p[i])
ans=0
c=0
for i in range(n-k):
    if c<=s[i+k]-s[i]:
        c=s[i+k]-s[i]
#print(s)
if n!=k:
    print((c+k)/2)
else:
    print((s[-1])/2+0.5*k)

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

Fixed submission:
n,k=map(int,input().split())
p=list(map(int,input().split()))
s=[p[0]]
for i in range(1,n):
    s.append(s[-1]+p[i])
ans=0
c=0
for i in range(n-k):
    if c<=s[i+k]-s[i]:
        c=s[i+k]-s[i]
#print(s)
if n!=k:
    print((c+k)/2)
else:
    print((s[-1])/2+0.5*k)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce
m=int(input())
a=list(map(int,input().split()))
a.sort()
def lcm_base(x,y):
    return (x*y)//fractions.gcd(x,y)
def lcm_list(numbers):
    return reduce(lcm_base,numbers,1)
mod=10**9+7
n=lcm_list(a)
ans=0
for i in range(m):
    ans+=(n//a[i])
print(ans%mod)


Fixed submission:
import fractions
from functools import reduce
m=int(input())
a=list(map(int,input().split()))
def lcm_base(x,y):
    return (x*y)//fractions.gcd(x,y)
def lcm_list(numbers):
    return reduce(lcm_base,numbers,1)
mod=10**9+7
n=lcm_list(a)
ans=0
for i in range(m):
    ans+=(n//a[i])
print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce
m=int(input())
a=list(map(int,input().split()))
a.sort()
def lcm_base(x,y):
    return (x*y)//fractions.gcd(x,y)
def lcm_list(numbers):
    return reduce(lcm_base,numbers,1)
#print(lcm_list(a))
mod=10**9+7
n=lcm_list(a)
ans=0
for i in range(m):
    ans=ans%(mod)+(n//a[i])%mod
print(ans%mod)

Fixed submission:
import fractions
from functools import reduce
m=int(input())
a=list(map(int,input().split()))
def lcm_base(x,y):
    return (x*y)//fractions.gcd(x,y)
def lcm_list(numbers):
    return reduce(lcm_base,numbers,1)
mod=10**9+7
n=lcm_list(a)
ans=0
for i in range(m):
    ans+=(n//a[i])
print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce
m=int(input())
a=list(map(int,input().split()))
def lcm_base(x,y):
    return (x*y)//fractions.gcd(x,y)
def lcm_list(numbers):
    return reduce(lcm_base,numbers,1)
#print(lcm_list(a))
mod=10**9+7
n=lcm_list(a)

ans=0
for i in range(m):
    ans=ans%(mod)+(n//a[i])%mod
print(ans%mod)

Fixed submission:
import fractions
from functools import reduce
m=int(input())
a=list(map(int,input().split()))
def lcm_base(x,y):
    return (x*y)//fractions.gcd(x,y)
def lcm_list(numbers):
    return reduce(lcm_base,numbers,1)
mod=10**9+7
n=lcm_list(a)
ans=0
for i in range(m):
    ans+=(n//a[i])
print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce
m=int(input())
a=list(map(int,input().split()))
def lcm_base(x,y):
    return (x*y)//fractions.gcd(x,y)
def lcm_list(numbers):
    return reduce(lcm_base,numbers,1)
#print(lcm_list(a))

n=lcm_list(a)

mod=10**9+7
ans=0
for i in range(m):
    ans+=n//a[i]%mod
print(ans%mod)

Fixed submission:
import fractions
from functools import reduce
m=int(input())
a=list(map(int,input().split()))
def lcm_base(x,y):
    return (x*y)//fractions.gcd(x,y)
def lcm_list(numbers):
    return reduce(lcm_base,numbers,1)
mod=10**9+7
n=lcm_list(a)
ans=0
for i in range(m):
    ans+=(n//a[i])
print(ans%mod)
Buggy python submission (verdict: Time Limit Exceeded):
import copy
from collections import deque
h,w=map(int,input().split())
p=[list("#"*(w+2))]+[list("#"+input()+"#") for i in range(h)]+[list("#"*(w+2))]
b=copy.deepcopy(p)
ans=0
#s0,s1=map(lambda x:int(x)-1,input().split())
#g0,g1=map(lambda x:int(x)-1,input().split())
for i in range(1,h+1):
    for j in range(1,w+1):
        for k in range(1,h+1):
            for z in range(1,w+1):
                p=copy.deepcopy(b)
                if p[i][j]=='.' and p[k][z]=='.':
                    s0,s1=i,j
                    g0,g1=k,z
                    p[s0][s1]=0
                    d=[(1,0),(-1,0),(0,1),(0,-1)]
                    q=deque([[s0,s1]])
                    while q:
                        x,y=q.popleft()
                        for dx,dy in d:
                            if p[x+dx][y+dy]==".":
                                p[x+dx][y+dy]=p[x][y]+1
                                q.append([x+dx,y+dy])
                    if ans<=p[g0][g1]:
                        ans=p[g0][g1]
print(ans)


Fixed submission:
import _pickle as cPickle

from collections import deque
h,w=map(int,input().split())
p=[list("#"*(w+2))]+[list("#"+input()+"#") for i in range(h)]+[list("#"*(w+2))]
b=cPickle.loads(cPickle.dumps(p, -1))
ans=0
for i in range(1,h+1):
    for j in range(1,w+1):
        p=cPickle.loads(cPickle.dumps(b, -1))
        if p[i][j]=='.':
            s0=i
            s1=j
            p[s0][s1]=0
            d=[(1,0),(-1,0),(0,1),(0,-1)]
            q=deque([[s0,s1]])
            while q:
                x,y=q.popleft()
                for dx,dy in d:
                    if p[x+dx][y+dy]==".":
                        p[x+dx][y+dy]=p[x][y]+1
                        q.append([x+dx,y+dy])
                        if ans<p[x+dx][y+dy]:
                            ans=p[x+dx][y+dy]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import Fraction
n=int(input())
x=list(map(int,input().split()))
ans=0
for i in range(n):
    ans=(ans+(x[-1]-x[i])*(Fraction(1,i+1)))%(10**9+7)

for i in range(1,n):
    ans=ans*i%(10**9+7)
print(ans)


Fixed submission:
import math
n=int(input())
a=list(map(int,input().split()))
ans=math.factorial(n-1)%(10**9+7)

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

c=0
for i in range(1,n):
    c+=(a[-1]-a[i-1])*modinv(i, mod=10**9+7)
print(ans*c%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
import math
from fractions import Fraction
n=int(input())
x=list(map(int,input().split()))
ans=0
for i in range(n):
    ans=(ans+(x[-1]-x[i])*(Fraction(1,i+1)))%(10**9+7)

ans=ans*math.factorial(n-1)%(10**9+7)
print(ans)


Fixed submission:
import math
n=int(input())
a=list(map(int,input().split()))
ans=math.factorial(n-1)%(10**9+7)

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

c=0
for i in range(1,n):
    c+=(a[-1]-a[i-1])*modinv(i, mod=10**9+7)
print(ans*c%(10**9+7))

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

from fractions import Fraction
n=int(input())
x=list(map(int,input().split()))
l=[1]
for i in range(1,n-1):
    l.append(l[-1]+Fraction(1,i+1))
#print(l)

for i in range(n-1):
    l[i]=l[i]*(x[i+1]-x[i])%(10**9+7)

ans=sum(l)
ans=ans*math.factorial(n-1)%(10**9+7)
print(ans)


Fixed submission:
import math
n=int(input())
a=list(map(int,input().split()))
ans=math.factorial(n-1)%(10**9+7)

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

c=0
for i in range(1,n):
    c+=(a[-1]-a[i-1])*modinv(i, mod=10**9+7)
print(ans*c%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import Fraction
n=int(input())
x=list(map(int,input().split()))
l=[1]
for i in range(1,n-1):
    l.append(l[-1]+Fraction(1,i+1))
#print(l)

for i in range(n-1):
    l[i]=l[i]*(x[i+1]-x[i])%(10**9+7)

ans=sum(l)
for i in range(1,n):
    ans=ans*i%(10**9+7)
print(ans)

Fixed submission:
import math
n=int(input())
a=list(map(int,input().split()))
ans=math.factorial(n-1)%(10**9+7)

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

c=0
for i in range(1,n):
    c+=(a[-1]-a[i-1])*modinv(i, mod=10**9+7)
print(ans*c%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import Fraction
n=int(input())
x=list(map(int,input().split()))
l=[1]
for i in range(1,n-1):
    l.append(l[-1]+Fraction(1,i+1))
#print(l)

for i in range(n-1):
    l[i]*=x[i+1]-x[i]

ans=sum(l)
for i in range(1,n):
    ans=ans*i%(10**9+7)
print(ans)

Fixed submission:
import math
n=int(input())
a=list(map(int,input().split()))
ans=math.factorial(n-1)%(10**9+7)

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

c=0
for i in range(1,n):
    c+=(a[-1]-a[i-1])*modinv(i, mod=10**9+7)
print(ans*c%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
imput=sys.stdin.readline
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
l.sort()

dp=[[float('inf')]*(n+1) for i in range(m+1)]
for i in range(m+1):
    dp[i][0]=0;dp[i][1]=0
for i in range(1,m+1):
    dp[i]=dp[i-1]
    for j in range(l[i-1][0],l[i-1][1]+1):
        dp[i][j]=min(dp[i][j],dp[i-1][l[i-1][0]]+l[i-1][2])
if dp[-1][-1]==float('inf'):
    print(-1)
else:
    print(dp[-1][-1])


Fixed submission:
import heapq
import sys

input = sys.stdin.readline

def dijkstra_heap(s):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d



n,m=map(int,input().split())#n:頂点数　w:辺の数

edge = [[] for i in range(n)] #edge[i] : iから出る道の[重み,行先]の配列

l=[list(map(int,input().split())) for i in range(m)]
for i in range(m):
    x,y,z =l[i][0],l[i][1],l[i][2]
    x-=1
    y-=1
    edge[x].append([z,y])
    edge[y].append([z,x])
for i in range(1,n):
    edge[i].append([0,i-1])
#print(edge)
#print(dijkstra_heap(0))
a=dijkstra_heap(0)

if a[-1]==float('inf'):
    print(-1)
else:
    print(a[-1])
Buggy python submission (verdict: Time Limit Exceeded):
import collections
import bisect
n=int(input())
a=collections.Counter(map(int,input().split()))
a=list(a.values())
a.sort()
b=[0]*len(a)
b[0]=a[0]
for i in range(len(a)-1):
    b[i+1]=b[i]+a[i+1]
s=sum(a)
ans=[i for i in range(0,n+1)]
ans=ans[::-1]
for t in range(1,n+1):
    for A in ans:
        z=bisect.bisect_right(a,A)
        if A*t<=(b[z-1] if z>=1 else 0)+A*(len(b)-z):
            print(A)
            break

Fixed submission:
import collections
import bisect
n=int(input())
a=collections.Counter(map(int,input().split()))
a=list(a.values())
a.sort()
b=[0]*len(a)
b[0]=a[0]
for i in range(len(a)-1):
    b[i+1]=b[i]+a[i+1]
s=sum(a)
#print(a,b)
ans=[i for i in range(0,n+1)]
ans=ans[::-1]
for t in range(1,n+1):
    ANS=ans[n+(-n//t):]
    #print(ANS)
    for A in ANS:
        z=bisect.bisect_right(a,A)
        #print(z)
        if A*t<=(b[z-1] if z>=1 else 0)+A*(len(b)-z):
            print(A)
            break
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
import heapq

n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
    a[i]=-a[i]

for i in range(m):
    heapq.heapify(a)
    heapq.heappush(a,-(-heapq.heappop(a)//2))

print(-sum(a))


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

n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
    a[i]=-a[i]

heapq.heapify(a)
for i in range(m):
    c=-(-heapq.heappop(a)//2)
    heapq.heappush(a,c)
#print(a)
print(-sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
#print(a)

for _ in range(m):
    a[-1]=a[-1]//2
    a.sort()
print(sum(a))

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

n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
    a[i]=-a[i]

heapq.heapify(a)
for i in range(m):
    c=-(-heapq.heappop(a)//2)
    heapq.heappush(a,c)
#print(a)
print(-sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
a=[0]*(n-1)
b=[0]*(n-1)
for i in range(n-1):
    a[i],b[i]=map(int,input().split())
p=[0]*q
x=[0]*q
for k in range(q):
    p[k],x[k]=map(int,input().split())
t=[[i] for i in range(1,n+1)]
for i in range(n-1):
    if a[i] not in t[a[i]-1]:
        t[a[i]-1].append(a[i])
    if b[i] not in t[a[i]-1]:
        t[a[i]-1].append(b[i])
for i in range(n):
    for j in t[i]:
        for y in t[j-1]:
            if y not in t[i]:        
                t[i].append(y)
ans=[0 for _ in range(n)]
g=0
for k in p:
    for j in t[k-1]:
        ans[j-1]+=x[g]
    g+=1  
print(' '.join(map(str,ans)))


Fixed submission:
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
a=[[0,0] for _ in range(n-1)]
for i in range(n-1):
    a[i][0],a[i][1]=map(int,input().split())
a.sort()
p=[[0,0] for _ in range(q)]
for k in range(q):
    p[k][0],p[k][1]=map(int,input().split())
p.sort()
t=[[i] for i in range(1,n+1)]
ans=[0 for _ in range(n)]
for i in range(q):
    ans[p[i][0]-1]+=p[i][1]
for i in range(n-1):
    ans[a[i][1]-1]+=ans[a[i][0]-1]  
print(' '.join(map(str,ans)))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n=int(input())
a=[0]*n
for i in range(n):
    a[i]=int(input())

for i in range(n):
    print(max(a[:i]+a[i+1:]))

Fixed submission:
import sys
input = sys.stdin.readline
n=int(input())
a=[0]*n
for i in range(n):
    a[i]=int(input())
b=sorted(a)

for i in range(n):
    if a[i]!=b[-1]:
        print(b[-1])
    else:
        print(b[-2])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n=int(input())
a=[]
for _ in range(n):
    a.append(int(input()))

for i in range(n):
    l=a[:i]+a[i+1:]
    print(max(l))

Fixed submission:
import sys
input = sys.stdin.readline
n=int(input())
a=[0]*n
for i in range(n):
    a[i]=int(input())
b=sorted(a)

for i in range(n):
    if a[i]!=b[-1]:
        print(b[-1])
    else:
        print(b[-2])
Buggy python submission (verdict: Runtime Error):
n,d=map(int,input().split())
a=0
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
    for j in range(i+1,n):
     b=0
     for k in range(d):
        b+=(l[i][k]-l[j][k])**2
        c=b**(1/2)
        if c%1 == 0:
            a+=1
print(a)


Fixed submission:
n,d=map(int,input().split())
l=[list(map(int,input().split())) for i in range (n)]

ans=0
for i in range(n):
    for k in range(i+1,n):
        t=0
        for j in range(d):
            t=t+(l[i][j]-l[k][j])**(2)
        t=t**(1/2)
        if t==int(t):
            ans=ans+1          
print(ans)