Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())



def calc(i,j):
    return i*w+j
def calc_inv(x):
    return x//w, x%w
def judge(x,y):
    i0,j0 = calc_inv(x)
    i1,j1 = calc_inv(y)
    if s[i0][j0] != s[i1][j1]:
        return True
    return False


h,w = map(int,input().split())
s = [[(i == "#")*1 for i in list(input())] for _ in range(h)]
uf = UnionFind(h*w)

for i in range(h):
    for j in range(w):
        now = calc(i,j)
        nxt = calc(i+1,j)
        if i+1 < h:
            if judge(now,nxt):
                uf.union(now,nxt)
        nxt = calc(i,j+1)
        if j+1 < w:
            if judge(now,nxt):
                uf.union(now,nxt)


cnt = [[0,0] for _ in range(h*w)]
ind = 0
for l in uf.all_group_members().values():
    for x in l:
        i,j = calc_inv(x)
        if s[i][j]:
            cnt[ind][0] += 1
        else:
            cnt[ind][1] += 1
    ind += 1
ans = 0
for i in range(ind):
    ans += cnt[i][0]*cnt[i][1]
print(ans)

Fixed submission:
n = int(input())
h = int(input())
w = int(input())
print(max(0,n-w+1)*max(0,n-h+1))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
dp = [[[0]*(n+1) for _ in range(n+1)] for _ in range(n+1)]
I,J,K = 0,0,0
for i in a:
  if i == 1:
    I += 1
  elif i == 2:
    J += 1
  else:
    K += 1 
for k in range(n+1):
  for j in range(n+1):
    for i in range(n+1):
      if (i+j+k) <= n:
        if (i+j+k) != 0:
          dp[i][j][k] = n/(i+j+k)
        if i > 0:
          dp[i][j][k] += dp[i-1][j][k]*i / (i+j+k)
        if j > 0:
          dp[i][j][k] += dp[i+1][j-1][k]*j / (i+j+k)
        if k > 0:
          dp[i][j][k] += dp[i][j+1][k-1]*k / (i+j+k)
print(dp[I][J][K])

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
dp = [[[float(0)]*(n+1) for _ in range(n+1)] for _ in range(n+1)]
I,J,K = 0,0,0
for i in a:
  if i == 1:
    I += 1
  elif i == 2:
    J += 1
  else:
    K += 1
for k in range(n+1):
  for j in range(n+1):
    for i in range(n+1):
      if (i+j+k) <= n:
        if (i+j+k) != 0:
          dp[i][j][k] = float(n)/float(i+j+k)
        if i > 0:
          dp[i][j][k] += dp[i-1][j][k]*float(i) / float(i+j+k)
        if j > 0:
          dp[i][j][k] += dp[i+1][j-1][k]*float(j) / float(i+j+k)
        if k > 0:
          dp[i][j][k] += dp[i][j+1][k-1]*float(k) / float(i+j+k)
print(dp[I][J][K])
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c = map(int,input().split())
ans = 0
while True:
  if c > 0 and b > 0:
    ans += 2
    c -= 1
    b -= 1
  elif c > 0 and a > 0:
    ans += 1
    c -= 1
    a -= 1
  elif c > 0:
    print(ans+1)
    quit()
  elif c == 0:
    print(ans + b)
    quit()

Fixed submission:
a,b,c = map(int,input().split())
ans = 0
if a+b > c-2:
  print(b+c)
else:
  print(a+2*b+1)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
from math import log2

def find(x):
    return 2**(int(log2(x))+1)-x

n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
c = Counter(a)
ans = 0

for i in range(n):
    f = find(a[i])
    if f == a[i]:
        if c[f] > 1:
            c[f] -= 2
            ans += 1
    elif c[f] > 0:
        c[f] -= 1
        c[a[i]] -= 1
        ans += 1
print(ans)

Fixed submission:
from collections import Counter
from math import log2

def find(x):
    f = 2**(int(log2(x))+1)-x
    if f <= x:
        return f
    return 0

n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
c = Counter(a)
ans = 0

for i in range(n):
    f = find(a[i])
    if f == a[i]:
        m = c[a[i]]//2
    else:
        m = min(c[a[i]],c[f])
    c[a[i]] -= m
    c[f] -= m
    ans += m
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
lst = [[] for _ in range(m+1)]
lst2 = []
for i in range(m):
  p,y = map(int,input().split())
  lst[p].append(y)
  lst2.append([p,y])
for i in range(1,m+1):
  lst[i].sort()
for l in lst2:
  num = lst[l[0]].index(l[1])+1
  print("0"*(6-len(str(l[0])))+str(l[0])+"0"*(6-len(str(num)))+str(num))

Fixed submission:
n,m = map(int,input().split())
py = [list(map(int,input().split()))+[i] for i in range(m)]
py.sort(key=lambda x:(x[0],x[1]))
cnt = 1
ans = [""]*m
for i in range(m-1):
  ans[py[i][2]] = "0"*(6-len(str(py[i][0])))+str(py[i][0]) + "0"*(6-len(str(cnt)))+str(cnt)
  if py[i][0] == py[i+1][0]:
    cnt += 1
  else:
    cnt = 1
ans[py[m-1][2]]="0"*(6-len(str(py[m-1][0])))+str(py[m-1][0]) + "0"*(6-len(str(cnt)))+str(cnt)
for i in range(m):
  print(ans[i])
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())
if s[0] != "1":
  print(s[0])
  quit()
c = 0
while s[c] == "1":
  c += 1
if c < k:
  print(s[c])
else:
  print(s[k-1])

Fixed submission:
s = input()
k = int(input())
if s[0] != "1":
  print(s[0])
  quit()
c = 0
while s[c] == "1":
  c += 1
  if c == len(s):
    print(1)
    quit()
if c < k:
  print(s[c])
else:
  print(s[k-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,m,q = map(int,input().split())
lst = [list(map(int,input().split())) for _ in range(m)]
query = [list(map(int,input().split())) for _ in range(q)]
s = [[0]*(n+1) for _ in range(n+1)]

for i in range(m):
    l,r = lst[i]
    s[l][r] += 1

for i in range(1,n+1):
    for j in range(1,n+1):
        s[i][j] += s[i][j-1]

for i in range(q):
    l,r = query[i]
    ans = 0
    for j in range(l,r+1):
        ans += s[j][r] - s[j][l-1]
    print(ans)

Fixed submission:
n,m,Q = map(int,input().split())
lr = [list(map(int,input().split())) for _ in range(m)]
lr.sort(key=lambda x:(x[0],x[1]))
ans = [[0]*(n+1) for _ in range(n+1)]
now = 0
for i in range(1,n+1):
  j = 1
  while True:
    if now < m:
      if lr[now][1] == j and lr[now][0] == i:
        ans[i][j] += (ans[i][j]==0)*(ans[i][j-1]) + 1
        now += 1
      else:
        j += 1
        if j <= n:
          ans[i][j] = ans[i][j-1]
        else:
          break
    else:
      j += 1
      if j <= n:
        ans[i][j] = ans[i][j-1]
      else:
        break
ans2 = [[0]*(n+1) for _ in range(n+1)]
for i in range(1,n+1):
  for j in range(1,n+1):
    if i == 1:
      ans2[i][j] = ans[i][j]
    else:
      ans2[i][j] = ans2[i-1][j] + ans[i][j]
for i in range(Q):
  p,q = map(int,input().split())
  print(ans2[q][q]-ans2[p-1][q])
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
p = list(map(int,input().split()))
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uf = UnionFind(n)
for i in range(m):
    x,y = map(int,input().split())
    uf.union(x-1,y-1)
ans = 0
for i in range(n):
    if uf.find(i) == uf.find(p[i]-1):
        ans += 1
print(ans)

Fixed submission:
a,b,c,d = map(int,input().split())
if abs(a-c) <= d or (abs(b-a)<=d and abs(b-c)<=d):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
n,k = map(int,input().split())
a = list(map(int,input().split()))
g = a[0]
for i in range(n):
  g = gcd(g,a[1])
if k%g == 0 and k <= max(a):
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Fixed submission:
from fractions import gcd
n,k = map(int,input().split())
a = list(map(int,input().split()))
g = a[0]
for i in range(n):
  g = gcd(g,a[i])
if k%g == 0 and k <= max(a):
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
A,B = (int(i) for i in input().split)
a = max(A,B)
b = min(A,B)
t = a - b
if t <= 1:
  print(a + a - 1)
else:
  print(a + b)



Fixed submission:
A,B = map(int,input().split())
a = max(A,B)
b = min(A,B)
t = a - b
if t <= 1:
  print(a + b)
else:
  print(a + a - 1)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
list1 = [a,b,c,d,e]
list2 = ["a","b","c","d","e"]
list3 = {}
 
for i,j in zip(list1,list2):
  i = i - 1
  sum = 1
  if i % 10 == 0:
    i = sum
  else:
    pass
  sum += 1
  list3[j] = sum
list3.sort()
list3.values()
    
  
def pri(kan):
  if kan <= 10:
    return 10
  if kan > 10 and kan <=20:
    return 20
  if kan > 20 and kan <=30:
    return 30
  if kan > 30 and kan <=40:
    return 40
  if kan > 40 and kan <=50:
    return 50
  if kan > 50 and kan <=60:
    return 60
  if kan > 60 and kan <=70:
    return 70
  if kan > 70 and kan <=80:
    return 80
  if kan > 80 and kan <=90:
    return 90
  if kan > 90 and kan <=100:
    return 100
  if kan > 100 and kan <=110:
    return 110
  if kan > 110 and kan <=120:
    return 120
  if kan > 120 and kan <=130:
    return 130
  if kan > 130 and kan <=140:
    return 140
A = pri(list3[4])
B = pri(list3[3])
C = pri(list3[2])
D = pri(list3[1])
E = list3[0]
print(A+B+C+D+E)

Fixed submission:
# B
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
 
a = (10 - A) % 10
b = (10 - B) % 10
c = (10 - C) % 10
d = (10 - D) % 10
e = (10 - E) % 10
 
print(A+B+C+D+E+a+b+c+d+e-max([a,b,c,d,e]))

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
list1 = [a,b,c,d,e]
list2 = ["a","b","c","d","e"]
list3 = {}

for i,j in zip(list1,list2):
  i = i - 1
  sum = 1
  if i % 10 = 0:
    i = sum
  else:
    pass
  sum += 1
  list3[j] = sum
list3.sort()
list3.values()
    
  
def pri(kan):
  if kan <= 10:
    return 10
  if kan > 10 and kan <=20:
    return 20
  if kan > 20 and kan <=30:
    return 30
  if kan > 30 and kan <=40:
    return 40
  if kan > 40 and kan <=50:
    return 50
  if kan > 50 and kan <=60:
    return 60
  if kan > 60 and kan <=70:
    return 70
  if kan > 70 and kan <=80:
    return 80
  if kan > 80 and kan <=90:
    return 90
  if kan > 90 and kan <=100:
    return 100
  if kan > 100 and kan <=110:
    return 110
  if kan > 110 and kan <=120:
    return 120
  if kan > 120 and kan <=130:
    return 130
  if kan > 130 and kan <=140:
    return 140
A = pri(list3[4])
B = pri(list3[3])
C = pri(list3[2])
D = pri(list3[1])
E = list3[0]
print(A+B+C+D+E)




Fixed submission:
# B
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
 
a = (10 - A) % 10
b = (10 - B) % 10
c = (10 - C) % 10
d = (10 - D) % 10
e = (10 - E) % 10
 
print(A+B+C+D+E+a+b+c+d+e-max([a,b,c,d,e]))
Buggy python submission (verdict: Runtime Error):
A,B,C = (int(i) for i in input().split())
 
if A = B and B = C:
  print("Yes")
else:
  print("No")

Fixed submission:
A,B,C = (int(i) for i in input().split())
 
if A == B == C:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
A,B,C = (int(i) for i in input().split())

if A = B = C:
  print("Yes")
else:
  print("No")

Fixed submission:
A,B,C = (int(i) for i in input().split())
 
if A == B == C:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
s = list(s)

cou = s.count("R")
if cou > N / 2:
  print("Yes")
else:
  print("No")


Fixed submission:
N = int(input())
S = input()
s = list(S)
 
cou = s.count("R")
if cou > N / 2:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
number = input().split(" ")
N = int(number[0])
K = int(number[1])

numbers = input().split(" ")
numbers.sotr()

a = 0

for i in range(K):
	a += numbers[i]
print(a)

Fixed submission:
number = input().split(" ")
N = int(number[0])
K = int(number[1])
 
list = []
numbers = input().split(" ")
for i in numbers:
    list.append(int(i))
list.sort()
 
a = 0
 
for i in range(K):
	a += int(list[i])
print(a)
Buggy python submission (verdict: Runtime Error):
K = int(input())
S = input()

for i in range(K):
    print(S[i],end="")
print("...")

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

if len(S) > K:
    for i in range(K):
        print(S[i],end="")
    print("...")
else:
    print(S)
Buggy python submission (verdict: Runtime Error):
N = input()
n = 0
if N[0] =="7":
	n += 1
if N[1] == "7":
	n +=1
if N[2} == "7":
	n += 1
 
if n > 0:
	print("Yes")
else:
	print("No")

Fixed submission:
N = input()
n = 0
if N[0] =="7":
	n += 1
if N[1] == "7":
	n +=1
if N[2] == "7":
	n += 1
 
if n > 0:
	print("Yes")
else:
	print("No")
Buggy python submission (verdict: Runtime Error):
N = int(input())
words = input()
ans = 0
for i, word in enumerate(words):
	if word == "A":
		if words[i+1] == "B":
			if words[i+2] == "C":
				ans += 1
print(ans)

Fixed submission:
N = int(input())
words = input()
ans = 0
for i in range(N-2):
    if words[i] == "A":
        if words[i+1] == "B":
            if words[i+2] == "C":
                ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

number = input().split(" ")
A = int(number[0])
B = int(number[1])

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

print(lcm(A, B))

Fixed submission:
import fractions

number = input().split(" ")
A = int(number[0])
B = int(number[1])

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

print(lcm(A, B))

Buggy python submission (verdict: Runtime Error):
import math

number = input().split(" ")
A = int(number[0])
B = int(number[1])

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

print(lcm(A, B))

Fixed submission:
import fractions

number = input().split(" ")
A = int(number[0])
B = int(number[1])

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

print(lcm(A, B))
Buggy python submission (verdict: Runtime Error):
number = input().split(" ")
A = int(number[0])
P = int(number[1])
apple = (A * 3) + P
print(math.floor(apple / 2))

Fixed submission:
import math

number = input().split(" ")
A = int(number[0])
P = int(number[1])
apple = (A * 3) + P
print(math.floor(apple / 2))
Buggy python submission (verdict: Runtime Error):
number = input().split(" ")
A = int(number[0])
B = int(number[1])
if A >= 13:
	print(B)
elif 6 =< A < 13:
	print(B/2)
else:
	print(0)

Fixed submission:
number = input().split(" ")
A = int(number[0])
B = int(number[1])
if A >= 13:
	print(B)
elif 6 <= A < 13:
	print(int(B/2))
else:
	print(0)
Buggy python submission (verdict: Runtime Error):
n , m = map(int, input().split())
a = list(map(int, input().split()))
print(max(n - sum(a)), -1)

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

print(max(n - sum(a), - 1))
Buggy python submission (verdict: Runtime Error):
a,b =map(int, input().split())
m = a % k
print(min(m, k - m))

Fixed submission:
n,k =map(int, input().split())
m = n % k
print(min(m, k - m))

Buggy python submission (verdict: Runtime Error):
a,b =map(int, input().split())
m = a % k
print(min(m, k - m))

Fixed submission:
n,k =map(int, input().split())
m = n % k
print(min(m, k - m))

Buggy python submission (verdict: Runtime Error):
a,b =map(int, input().split())
m = a % k
print(min(m, k - m))

Fixed submission:
n,k =map(int, input().split())
m = n % k
print(min(m, k - m))
Buggy python submission (verdict: Runtime Error):
x = int(input()) if x==0:     print("1") else:     print("0")

Fixed submission:
x= int(input())
if x==0:
  print("1")
else: 
  print("0")
Buggy python submission (verdict: Runtime Error):
def lineFromPoints(P,Q): 
  
    a = Q[1] - P[1] 
    b = P[0] - Q[0]  
    c = a*(P[0]) + b*(P[1])  
  
    if(b<0):  
        print("The line passing through points P and Q is:", 
              a ,"x ",b ,"y = ",c ,"\n")  
    else: 
        print("The line passing through points P and Q is: ", 
              a ,"x + " ,b ,"y = ",c ,"\n")  
  
if __name__=='__main__': 
    n = int(input("Enter size of array:")) 
    P=[]
    Q=[]
    for i in range(n): 
        temp = int(input('Enter number to add to P:\n')) 
        P.append(temp)
    for i in range(n): 
        temp = int(input('Enter number to add to Q:\n')) 
        Q.append(temp)
     
    lineFromPoints(P,Q)  

Fixed submission:
import math
N,D= map(int, input().split(" "))
count = 0
for i in range(0,N):
    X,Y= map(int, input().split(" "))
    d= math.sqrt(pow(X,2)+pow(Y,2))
    if d<= D:
        count = count+1
print(count)
Buggy python submission (verdict: Runtime Error):
x = input()

if x:
    print 0
else:
    print 1

Fixed submission:
x = int(input())
 
if x:
    print(0)
else:
    print(1)

Buggy python submission (verdict: Runtime Error):
if x:
    print 0
else:
    print 1

Fixed submission:
x = int(input())
 
if x:
    print(0)
else:
    print(1)

Buggy python submission (verdict: Runtime Error):
if x:
    return 0
else:
    return 1

Fixed submission:
x = int(input())
 
if x:
    print(0)
else:
    print(1)
Buggy python submission (verdict: Runtime Error):
X, K, D = map(int, input().split())

ans = 0
count = X // D
if X >= 0:
    if K <= count:
        ans = X - D * K
    else:
        ans = X - D * count
        if ((K - count) % 2 == 1):
            ans = ans - D
else:
    if K <= -1 * count:
        ans = X + D * K
    else:
        ans = X + D * xount
        if ((K - count) % 2 == 1):
            ans = ans + D

if ans < 0:
    ans = ans * (-1)

print(ans)

Fixed submission:
X, K, D = map(int, input().split())

ans = 0
count = X // D



if X >= 0:
    if K <= count:
        ans = X - D * K
    else:
        ans = X - D * count
        if ((K - count) % 2 == 1):
            ans = ans - D
else:
    if K <= (-1) * count:
        ans = X + D * K
    elif X % D == 0:
        ans = X - D * count 
        if ((K + count) % 2 == 1):
            ans = ans + D
    else:
        ans = X - D * (count + 1) 
        if ((K + count + 1) % 2 == 1):
            ans = ans + D

if ans < 0:
    ans = ans * (-1)

print(ans)
Buggy python submission (verdict: Runtime Error):
A,B,C,D = map(int,input().split())
while A>0 && C>0:
    C=C-B
    A=A-D

if C<0:
    print("Yes")
else:
    print("No")


Fixed submission:
A,B,C,D = map(int,input().split())
while True:
    C=C-B
    if C<=0:
        print("Yes")
        break

    A=A-D
    if A<=0:
        print("No")
        break
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=[]
for i in range(N):
    S.append(input())

for i in range(N):
    for j in range(N):
        if S[i] == S[j]:
            pair += 1

pair=(pair-N)/2
print(pair)


Fixed submission:
N=int(input())
S=[]
for i in range(N):
    S.append(input())

S=set(S)
print(len(S))
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d = map(int,input().split())

maxxy=a*c

for x in range(a,b+1):
    for y in range(c,d+1):
        if maxxy < x*y :
            maxxy=x*y
        
print(maxxy)

Fixed submission:
a,b,c,d = map(int,input().split())

maxxy=max(a*c,a*d,b*c,b*d)

print(maxxy)

Buggy python submission (verdict: Runtime Error):
def resolve():
    a, b, c, d = map(int, input().split()
    w = a*c
    x = a*d
    y = b*c
    z = b*d
    ans = max(w, x, y, z)
    print(ans)
    
    
resolve()


Fixed submission:
def resolve():
    a, b, c, d = map(int, input().split())
    w = a*c
    x = a*d
    y = b*c
    z = b*d
    ans = max(w, x, y, z)
    print(ans)

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

def resolve():
    _,k = list(map(int, input().split()))
    A = list(map(int, input().split()))
    heap = []
    for a in A:
        heapq.heappush(heap, (-a, -a, 1))
    
    while k > 0:
        a = heapq.heappop(heap)
        origin = a[1]
        denom = a[2]
        denom += 1
        new = (origin/denom, origin, denom)
        heapq.heappush(heap, new)
        k -= 1

    a = heapq.heappop(heap)
    ans = a[0]*-1
    print(math.ceil(ans))
    
resolve()

Fixed submission:
import math

def resolve():
    _,K = list(map(int, input().split()))
    A = list(map(int, input().split()))

    start = 0
    end = 10**9

    while end - start > 1:
        cnt = 0
        mid = (start + end) // 2
        for a in A:
            cnt += math.ceil(a/mid) - 1
        if cnt <= K:
            end = mid
        else:
            start = mid

    print(end)
    
resolve()
Buggy python submission (verdict: Runtime Error):

    n = int(input())
    A = list(map(int, input().split()))
    funds = 1000
    stock = 0

    for i in range(n):
        if i > 0 and A[i] > A[i-1]:
            # sell
            funds += A[i] * stock
            stock = 0
        if i < n-1 and A[i] < A[i+1]:
            # buy
            stock += funds // A[i]
            funds -= A[i] * stock

    print(funds)

resolve()

Fixed submission:
def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    funds = 1000
    stock = 0

    for i in range(n):
        if i > 0 and A[i] > A[i-1]:
            # sell
            funds += A[i] * stock
            stock = 0
        if i < n-1 and A[i] < A[i+1]:
            # buy
            stock += funds // A[i]
            funds -= A[i] * stock

    print(funds)

resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    t = input()
    ans = ''
    for c in t:
        if c == '?':
            ans += 'D'
        else:
            ans += c

    print(ans)

resolve()

Fixed submission:
def resolve():
    t = input()
    ans = []
    is_pre_p = False
    for c in t:
        if c == '?':
            ans.append('D')
        else:
            ans.append(c)

    print("".join(ans))

resolve()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
sum = 0
l = []
for _ in range(0,n):
    s = input()
    if s in l:
        continue
    else:
        l.append(s)
        sum += 1

print(sum)

Fixed submission:
n = int(input())
sum = 0
l = set()
for _ in range(0,n):
    s = input()
    if s in l:
        continue
    else:
        l.add(s)
        sum += 1

print(sum)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
 
r = int(stdin.readline().rstrip())
print(r*2*3.1415)

Fixed submission:
from sys import stdin

holiday_count, task_count = stdin.readline().rstrip().split()
holiday_count = int(holiday_count)
tasks_days = sum([int(x) for x in stdin.readline().rstrip().split()])

remain = holiday_count - tasks_days
if remain < 0:
  print(-1)
else:
  print(remain)
Buggy python submission (verdict: Runtime Error):
n = int(stdin.readline().rstrip())
ans = 1000 - n % 1000
if ans == 1000:
    ans = 0
print(ans)


Fixed submission:
n = int(input())
ans = 1000 - n % 1000
if ans == 1000:
    ans = 0
print(ans)