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

n = int(input())
x = [int(i) for i in input().split()]
sortedx = copy.copy(x)
sortedx.sort()

m = {}

for i in x:
    if i in m:
        print(m[i])
    else:
        cnt = 0
        flag = False
        for j in range(n):
            if i == sortedx[j] and not flag:
                flag = True
            elif cnt == (n/2)-1:
                print(sortedx[j])
                m[i] = sortedx[j]
                break
            else:
                cnt += 1      


Fixed submission:
import copy

n = int(input())
x = [int(i) for i in input().split()]
sortedx = copy.copy(x)
sortedx.sort()

m = sortedx[int((n+1)/2)]

for i in x:
    if i < m:
        print(sortedx[int(n/2)])
    else:
        print(sortedx[int(n/2-1)])

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

n = int(input())
x = [int(i) for i in input().split()]
sortedx = copy.copy(x)
sortedx.sort()

m = {}
mid = int(n/2)-1

for i in x:
    if i in m:
        print(m[i])
    else:
        temp = copy.copy(sortedx)
        temp.remove(i)
        print(temp[mid])
        m[i] = temp[mid] 


Fixed submission:
import copy

n = int(input())
x = [int(i) for i in input().split()]
sortedx = copy.copy(x)
sortedx.sort()

m = sortedx[int((n+1)/2)]

for i in x:
    if i < m:
        print(sortedx[int(n/2)])
    else:
        print(sortedx[int(n/2-1)])
Buggy python submission (verdict: Runtime Error):
N = [int(x) for x in input()]
print(max(sum(N), N[0]-1+9*len(N))

Fixed submission:
N_list = [int (i) for i in list(input())]
digit = 0
dflag = False
max = 0
for i in N_list:
    max += i

for i in N_list:
    if i == 9:
        dflag = True
    else:
        break

    digit += 1

if dflag:
    N_list[digit-1] -=1
    for i in range(digit, len(N_list)):
        N_list[i] = 9

else:
    N_list[digit] -=1
    for i in range(digit+1, len(N_list)):
        N_list[i] = 9

sum = 0

for i in N_list:
    sum += i

if sum > max:
    max = sum
print (max)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
max = 0
for j in range(N+1):
    sum = 0
    N_list = list(str(j))
    for i in N_list:
        sum += int(i)
    if max < sum:
        max = sum

print (max)

Fixed submission:
N_list = [int (i) for i in list(input())]
digit = 0
dflag = False
max = 0
for i in N_list:
    max += i

for i in N_list:
    if i == 9:
        dflag = True
    else:
        break

    digit += 1

if dflag:
    N_list[digit-1] -=1
    for i in range(digit, len(N_list)):
        N_list[i] = 9

else:
    N_list[digit] -=1
    for i in range(digit+1, len(N_list)):
        N_list[i] = 9

sum = 0

for i in N_list:
    sum += i

if sum > max:
    max = sum
print (max)
Buggy python submission (verdict: Time Limit Exceeded):
from queue import Queue

H, W = [int(i) for i in input().split()]
C = [list(input()) for i in range(H)]

dcount = -1
for h in range(H):
    for w in range(W):
        if C[h][w] == '.':
            dcount += 1

INF = 10 ** 6
D = [[INF] * W for i in range(H)]
D[0][0] = 0
q = Queue()
q.put((0, 0))

while q.qsize() > 0:
    h, w = q.get()
    if (h, w) == (H-1, W-1):
        break
    C[h][w] = '#'
    for dh, dw in zip((-1, 1, 0, 0), (0, 0, -1, 1)):
        if 0 <= h+dh < H and 0 <= w+dw < W and C[h+dh][w+dw] == '.':
            D[h+dh][w+dw] = D[h][w] + 1
            q.put((h+dh, w+dw))

print(dcount - D[H-1][W-1] if D[H-1][W-1] != INF else -1)

Fixed submission:
from queue import Queue

H, W = [int(i) for i in input().split()]
C = [list(input()) for i in range(H)]

dcount = -1
for h in range(H):
    for w in range(W):
        if C[h][w] == '.':
            dcount += 1

INF = 10 ** 6
D = [[INF] * W for i in range(H)]
D[0][0] = 0
q = Queue()
q.put((0, 0))

while q.qsize() > 0:
    h, w = q.get()
    if (h, w) == (H-1, W-1):
        break
    for dh, dw in zip((-1, 1, 0, 0), (0, 0, -1, 1)):
        if 0 <= h+dh < H and 0 <= w+dw < W and C[h+dh][w+dw] == '.' and D[h+dh][w+dw] == INF:
            D[h+dh][w+dw] = D[h][w] + 1
            q.put((h+dh, w+dw))

print(dcount - D[H-1][W-1] if D[H-1][W-1] != INF else -1)
Buggy python submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]
Y = [int(i) for i in input().split()]

p = 10 ** 9 + 7

ans = 0
xc = n // 2
yc = m // 2
n -= 1
m -= 1
h = Y[-1] - Y[0]
w = X[-1] - X[0]

if n % 2 == 0 and m % 2 == 0:
    ans = n * m * h * w

elif n % 2 == 1 and m % 2 == 1:
    xd = X[xc] - X[xc-1]
    yd = Y[yc] - Y[yc-1]
    ans = n * (m+1) * d * (h - yd) + (n+1) * m * d * (w - xd) + (n+1) * (m+1) * yd * xd + n * m * (w - xd) * (h - yd)

elif n % 2 == 1:
    d = X[xc] - X[xc-1]
    ans = (n * (m+1) * d + (w - d)) * h

elif n % 2 == 1:
    d = Y[yc] - Y[yc-1]
    ans = ((n+1) * m * d + (h - d)) * w

print(ans % p)

Fixed submission:
n, m = [int(i) for i in input().split()]
X = [0] + [int(i) for i in input().split()]
Y = [0] + [int(i) for i in input().split()]

p = 10 ** 9 + 7

xsum = 0
ysum = 0

for i in range(1, n+1):
  xsum += (2*i-n-1) * X[i] 
  
for i in range(1, m+1):
  ysum += (2*i-m-1) * Y[i] 

print(xsum * ysum % p)
Buggy python submission (verdict: Runtime Error):
n, a, b = [int(i) for i in input().split()]
X = [int(i) for i in input.split()]

ans = 0
for i in range(n-1):
  ans += min(a * (X[i+1] - X[i]), b)

print(ans)

Fixed submission:
n, a, b = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]

ans = 0
for i in range(n-1):
  ans += min(a * (X[i+1] - X[i]), b)

print(ans)

Buggy python submission (verdict: Runtime Error):
n, a, b = [int(i) for i in input().split()]
X = [int(i) for i in input.split()]

ans = 0
for i in range(n-1):
  ans += min(a * (X[i+1] - X[i]), b)

print(ans)

Fixed submission:
n, a, b = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]

ans = 0
for i in range(n-1):
  ans += min(a * (X[i+1] - X[i]), b)

print(ans)

Buggy python submission (verdict: Runtime Error):
n, a, b = [int(i) for i in input().split()]
X = [int(i) for i in input.split()]

ans = 0
for i in range(n-1):
  ans += min(a * X[i+1] - X[i], b)

print(ans)

Fixed submission:
n, a, b = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]

ans = 0
for i in range(n-1):
  ans += min(a * (X[i+1] - X[i]), b)

print(ans)

Buggy python submission (verdict: Runtime Error):
n, a, b = [int(i) for i in input().split()]
X = [int(i) for i in input.split()]

ans = 0
for i in range(n-1):
  ans += min(a * X[i+1] - b)

print(ans)

Fixed submission:
n, a, b = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]

ans = 0
for i in range(n-1):
  ans += min(a * (X[i+1] - X[i]), b)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
T = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
p = 10 ** 9 + 7

B = [10**9] * n

if max(T) != max(A):
    print(0)
    exit()

h = 0

for i, t in enumerate(T):
    if h < t:
        B[i] = 1
        h = t
    else:
        B[i] = h

h = 0

for i, a in zip(range(n-1, -1, -1), A[::-1]):
    if h < a:
        B[i] = 1
        h = a
    elif B[i] == 1 and T[i] > A[i]:
        print(0)
        exit(0)
    elif B[i] > h:
        B[i] = h

ans = 1

for b in B:
    ans *= b

print(ans%p)

Fixed submission:
n = int(input())
T = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
p = 10 ** 9 + 7

B = [10**9] * n

if max(T) != max(A):
    print(0)
    exit()

h = 0

for i, t in enumerate(T):
    if h < t:
        B[i] = 1
        h = t
    else:
        B[i] = h

h = 0

for i, a in zip(range(n-1, -1, -1), A[::-1]):
    if h < a:
        B[i] = 1
        h = a
    elif B[i] == 1 and T[i] > A[i]:
        print(0)
        exit(0)
    elif B[i] > h:
        B[i] = h

ans = 1

for b in B:
    ans *= b
    ans %= p

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x, y = [int(i) for i in input().split()]

for i in range(n-1):
  t, a = [int(i) for i in input().split()]
  
  if t >= x and a >= y:
    x = t
    y = a

  else:
    c = 2
    while True:
      x_ = t * c
      y_ = a * c
      if x_ >= x and y_ >= y:
        break
      c += 1
      
    x, y = x_, y_
    
print(x+y)

Fixed submission:
n = int(input())
x, y = [int(i) for i in input().split()]

for i in range(n-1):
  t, a = [int(i) for i in input().split()]
  
  if t >= x and a >= y:
    x = t
    y = a



  else:
    c = max(-(-x//t), -(-y//a))

    x = t * c
    y = a * c
    
print(x+y)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect

n = int(input())
A = [int(i) for i in input().split()]

ans = 0

B = [(0, 0)]

for i, a in zip(range(1, n+1), A):
    B.append((a, i))

B.sort()

sortedlist = []
    
for i in range(1, n+1):
    j = bisect(sortedlist, B[i][1])
    left = B[i][1] - (sortedlist[j-1] if j-1 >= 0 else 0) - 1
    right = (sortedlist[j] - 1 if j < i-1 else n) - B[i][1]
    sortedlist.insert(j, B[i][1])

    ans += (left + 1) * (right + 1) * B[i][0]
    
print(ans)

Fixed submission:
from bisect import bisect

n = int(input())
A = [int(i) for i in input().split()]

class UnionFind():
  def __init__(self, elements):
    self.elements = elements
    self._root = {}
    self.size = [1] * (len(self.elements)+1)
    for e in self.elements:
      self._root[e] = e
    
  def unite(self, x, y):
    x = self.root(x)
    y = self.root(y)
    res = self.size[x] * self.size[y]
    self.size[x] += self.size[y]
    
    if x != y:
      self._root[y] = x

    return res
    
  def root(self, x):
    if self._root[x] != x:
      self._root[x] = self.root(self._root[x])
    return self._root[x]

B = [0] * (n+1)

for i, a in zip(range(1, n+1), A):
    B[a] = i

uf = UnionFind(range(1, n+1))
ans = 0
A.insert(0, 0)

for j in range(n, 0, -1):
    i = B[j]
    ans += A[i]

    if i - 1 >= 1 and A[i-1] > A[i]:
        ans += uf.unite(i-1, i) * A[i]

    if i + 1 <= n and A[i+1] > A[i]:
        ans += uf.unite(i+1, i) * A[i]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect

n = int(input())
A = [int(i) for i in input().split()]

ans = 0

B = [(0, 0)]

for i, a in zip(range(1, n+1), A):
    B.append((a, i))

B.sort()

sortedlist = []
    
for i in range(1, n+1):
    j = bisect(sortedlist, B[i][1])
    left = B[i][1] - (sortedlist[j-1] if j-1 >= 0 else 0) - 1
    right = (sortedlist[j] - 1 if j < i-1 else n) - B[i][1]
    sortedlist.insert(j, B[i][1])

    ans += (left + 1) * (right + 1) * B[i][0]
    
print(ans)

Fixed submission:
from bisect import bisect

n = int(input())
A = [int(i) for i in input().split()]

class UnionFind():
  def __init__(self, elements):
    self.elements = elements
    self._root = {}
    self.size = [1] * (len(self.elements)+1)
    for e in self.elements:
      self._root[e] = e
    
  def unite(self, x, y):
    x = self.root(x)
    y = self.root(y)
    res = self.size[x] * self.size[y]
    self.size[x] += self.size[y]
    
    if x != y:
      self._root[y] = x

    return res
    
  def root(self, x):
    if self._root[x] != x:
      self._root[x] = self.root(self._root[x])
    return self._root[x]

B = [0] * (n+1)

for i, a in zip(range(1, n+1), A):
    B[a] = i

uf = UnionFind(range(1, n+1))
ans = 0
A.insert(0, 0)

for j in range(n, 0, -1):
    i = B[j]
    ans += A[i]

    if i - 1 >= 1 and A[i-1] > A[i]:
        ans += uf.unite(i-1, i) * A[i]

    if i + 1 <= n and A[i+1] > A[i]:
        ans += uf.unite(i+1, i) * A[i]

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

n = int(input())
s = int(input())

ans = []

def f(b, n):
  if n < b:
    return n
  else:
    return f(b, n//b) + n % b

if n == s:
  ans.append(n+1)

elif s == 1:
  ans.append(n)
  
else:
  rootn = int(math.sqrt(n))
  for b in range(2, rootn):
    if s == f(b, n):
      ans.append(b)
      break
      
  for p in range(1, rootn):
    b = (n-s)//p + 1
    if s == p*b + n%b:
      ans.append(b)
      
if not ans:
  ans.append(-1)

print(min(ans))

Fixed submission:
import math

n = int(input())
s = int(input())

ans = []

def f(b, n):
  if n < b:
    return n
  else:
    return f(b, n//b) + n % b

if n == s:
  ans.append(n+1) 
  
elif n < s:
  ans.append(-1)
  
else:
  rootn = int(math.sqrt(n))
  for b in range(2, rootn+2):
    if s == f(b, n):
      ans.append(b)
      break
      
  for p in range(1, rootn):
    b = (n-s)//p + 1
    if s == p + n%b:
      ans.append(b)
      
if not ans:
  ans.append(-1)

print(min(ans))

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

n = int(input())
s = int(input())

ans = -1

def f(b, n):
  if n < b:
    return n
  else:
    return f(b, n//b) + n % b

if n == s:
  ans = n+1

elif s == 1:
  ans = n
  
else:
  rootn = int(math.sqrt(n))
  for b in range(2, rootn):
    if s == f(b, n):
      ans = b
      break
  else:
    for p in range(1, rootn):
      b = (n-s)//p + 1
      if s == p*b + n%b:
        ans = b
        break

print(ans)

Fixed submission:
import math

n = int(input())
s = int(input())

ans = []

def f(b, n):
  if n < b:
    return n
  else:
    return f(b, n//b) + n % b

if n == s:
  ans.append(n+1) 
  
elif n < s:
  ans.append(-1)
  
else:
  rootn = int(math.sqrt(n))
  for b in range(2, rootn+2):
    if s == f(b, n):
      ans.append(b)
      break
      
  for p in range(1, rootn):
    b = (n-s)//p + 1
    if s == p + n%b:
      ans.append(b)
      
if not ans:
  ans.append(-1)

print(min(ans))

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

n = int(input())
s = int(input())

ans = -1

def f(b, n):
  if n < b:
    return n
  else:
    return f(b, n//b) + n % b
    
  

if n == s:
  ans = n+1
  
else:
  rootn = int(math.sqrt(n))
  for b in range(2, rootn):
    if s == f(b, n):
      ans = b
      break
  else:
    for p in range(1, rootn):
      b = (n-s)//p + 1
      if s == p*b + n%b:
        ans = b
        break

print(ans)

Fixed submission:
import math

n = int(input())
s = int(input())

ans = []

def f(b, n):
  if n < b:
    return n
  else:
    return f(b, n//b) + n % b

if n == s:
  ans.append(n+1) 
  
elif n < s:
  ans.append(-1)
  
else:
  rootn = int(math.sqrt(n))
  for b in range(2, rootn+2):
    if s == f(b, n):
      ans.append(b)
      break
      
  for p in range(1, rootn):
    b = (n-s)//p + 1
    if s == p + n%b:
      ans.append(b)
      
if not ans:
  ans.append(-1)

print(min(ans))
Buggy python submission (verdict: Runtime Error):
h, w, a, b = [int(i) for i in input().split()]

p = 10 ** 9 + 7
s = 0

fact = [1]

for i in range(1, h+w-2):
    fact.append(fact[i-1] * i % p)

rfact = [(h+w-2) % p]

for i in range(h+w-1, 0, -1):
    rfact.append(rfact[-1] * i % p)

rfact.reverse()

def comb(n, r):
    return fact[n]//fact[n-r]//%pfact[r]%p

for i in range(w-b):
    s += comb(h+w-a-2-i, w-1-i) * comb(a-1+i, a-1)%p

print(s%p)

Fixed submission:
import scipy.misc as scm

h, w, a, b = [int(i) for i in input().split()]

p = 10**9 + 7
ans = 0

def fact(n, p=10**9 + 7):
    f = [1]
    for i in range(1, n+1):
        f.append(f[-1]*i%p)
    return f

def invfact(n, f, p=10**9 + 7):
    inv = [pow(f[n], p-2, p)]
    for i in range(n, 0, -1):
        inv.append(inv[-1]*i%p)
    return inv[::-1]

f = fact(h+w)
rf = invfact(h+w, f)

for i in range(w-b):
    wi = b + i
    ans += (f[h-a+wi-1] * rf[h-a-1] % p * rf[wi] % p) * (f[a+w-wi-2] * rf[a-1] % p * rf[w-wi-1] % p) % p
    ans %= p 

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import scipy.misc as scm

h, w, a, b = [int(i) for i in input().split()]

p = 10 ** 9 + 7
s = 0

for i in range(w-b):
    s += scm.comb(h+w-a-2-i, w-1-i, 1) * scm.comb(a-1+i, a-1, 1)

print(s%p)

Fixed submission:
import scipy.misc as scm

h, w, a, b = [int(i) for i in input().split()]

p = 10**9 + 7
ans = 0

def fact(n, p=10**9 + 7):
    f = [1]
    for i in range(1, n+1):
        f.append(f[-1]*i%p)
    return f

def invfact(n, f, p=10**9 + 7):
    inv = [pow(f[n], p-2, p)]
    for i in range(n, 0, -1):
        inv.append(inv[-1]*i%p)
    return inv[::-1]

f = fact(h+w)
rf = invfact(h+w, f)

for i in range(w-b):
    wi = b + i
    ans += (f[h-a+wi-1] * rf[h-a-1] % p * rf[wi] % p) * (f[a+w-wi-2] * rf[a-1] % p * rf[w-wi-1] % p) % p
    ans %= p 

print(ans)

Buggy python submission (verdict: Runtime Error):
import scipy.misc as scm

h, w, a, b = [int(i) for i in input().split()]

p = 10 * * 9 + 7
s = 0

for i in range(w-b):
    s += scm.comb(h+w-a-2-i, w-1-i, 1) * scm.comb(a-1+i, a-1, 1)

print(s%p)


Fixed submission:
import scipy.misc as scm

h, w, a, b = [int(i) for i in input().split()]

p = 10**9 + 7
ans = 0

def fact(n, p=10**9 + 7):
    f = [1]
    for i in range(1, n+1):
        f.append(f[-1]*i%p)
    return f

def invfact(n, f, p=10**9 + 7):
    inv = [pow(f[n], p-2, p)]
    for i in range(n, 0, -1):
        inv.append(inv[-1]*i%p)
    return inv[::-1]

f = fact(h+w)
rf = invfact(h+w, f)

for i in range(w-b):
    wi = b + i
    ans += (f[h-a+wi-1] * rf[h-a-1] % p * rf[wi] % p) * (f[a+w-wi-2] * rf[a-1] % p * rf[w-wi-1] % p) % p
    ans %= p 

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
q=int(input())
ans=0
for i in range(q):
    query=input().split()
    if query==['1']:
        ans+=1
    else:
        if query[1]=='1' and ans%2==0:
            s.insert(0,query[2])
        elif query[1]=='1' and ans%2==1:
            s.append(query[2])
        elif query[1]=='2' and ans%2==0:
            s.append(query[2])
        else:
            s.insert(0,query[2])
if ans%2==1:
    s.reverse()
print(''.join(s))



Fixed submission:
s=list(input())
q=int(input())
ans=0
mae=[]
ato=[]
for i in range(q):
    query=input().split()
    if query==['1']:
        ans+=1
    else:
        if query[1]=='1' and ans%2==0:
            mae.append(query[2])
        elif query[1]=='1' and ans%2==1:
            ato.append(query[2])
        elif query[1]=='2' and ans%2==0:
            ato.append(query[2])
        else:
            mae.append(query[2])
if ans%2==1:
    s.reverse()
    ato.reverse()
    s=ato+s+mae
else:
    mae.reverse()
    s=mae+s+ato
print(''.join(s))
Buggy python submission (verdict: Runtime Error):
import sys
n,m=map(int,input().split())
l=[]
for i in range(m):
    l.append(list(map(int,input().split())))
sortfirst=lambda val:val[0]
l.sort(key=sortfirst)
for i in range(m-1):
    if l[i][0]==l[i+1][0] and l[i][1]!=l[i+1][1]:
        print(-1)
        sys.exit()
if l[0]==[1,0] and n>=2:
    print(-1)
    sys.exit()
ans=[0]*n
for i in range(m):
    ans[l[i][0]-1]=l[i][1]
print("".join(map(str,ans)))


Fixed submission:
import sys
n,m=map(int,input().split())
l=[]
if m==0:
    if n==1:
        print(0)
        sys.exit()
    else:
        print(10**(n-1))
        sys.exit()
for i in range(m):
    l.append(list(map(int,input().split())))
sortfirst=lambda val:val[0]
l.sort()
l.sort(key=sortfirst)
for i in range(m-1):
    if l[i][0]==l[i+1][0] and l[i][1]!=l[i+1][1]:
        print(-1)
        sys.exit()
if l[0]==[1,0] and n>=2:
    print(-1)
    sys.exit()
ans=[1]+[0]*(n-1)
for i in range(m):
    ans[l[i][0]-1]=l[i][1]
print("".join(map(str,ans)))
Buggy python submission (verdict: Runtime Error):
h,n=map(int,input().split())
INF=10**12
a=[]
b=[]
for i in range(n):
    A,B=map(int,input().split())
    a.append(A)
    b.append(B)
dp=[INF]*20010
dp[0]=0
for i in range(20010):
    for j in range(n):
        if i>=a[j]:
            dp[i]=min(dp[i],dp[i-a[j]]+b[j])
ans=min(dp[h:])
print(ans)


Fixed submission:
h,a=map(int,input().split())
if h%a!=0:
    print(h//a+1)
else:
    print(h//a)
Buggy python submission (verdict: Time Limit Exceeded):
h,n=map(int,input().split())
INF=10**12
a=[]
b=[]
for i in range(n):
    A,B=map(int,input().split())
    a.append(A)
    b.append(B)
dp=[INF]*20010
dp[0]=0
for i in range(20010):
    for j in range(n):
        if i>=a[j]:
            dp[i]=min(dp[i],dp[i-a[j]]+b[j])
ans=min(dp[h:])
print(ans)


Fixed submission:
h,n=map(int,input().split())
INF=10**12
a=[]
b=[]
for i in range(n):
    A,B=map(int,input().split())
    a.append(A)
    b.append(B)
dp=[INF]*20010
dp[0]=0
for i in range(20010):
    for j in range(n):
        if i>=a[j]:
            dp[i]=min(dp[i],dp[i-a[j]]+b[j])
ans=min(dp[h:])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,n=map(int,input().split())
INF=10**15
a=[]
b=[]
for i in range(n):
    A,B=map(int,input().split())
    a.append(A)
    b.append(B)
dp=[INF]*20010
dp[0]=0
for i in range(20010):
    for j in range(n):
        if i>=a[j]:
            dp[i]=min(dp[i],dp[i-a[j]]+b[j])
ans=min(dp[h:])
print(ans)


Fixed submission:
h,n=map(int,input().split())
INF=10**12
a=[]
b=[]
for i in range(n):
    A,B=map(int,input().split())
    a.append(A)
    b.append(B)
dp=[INF]*20010
dp[0]=0
for i in range(20010):
    for j in range(n):
        if i>=a[j]:
            dp[i]=min(dp[i],dp[i-a[j]]+b[j])
ans=min(dp[h:])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
x,y=map(int,input().split())
if (x+y)%3!=0 or 2*x<y or 2*y<x:
    print(0)
else:
    a=(2*y-x)//3
    b=(2*x-y)//3
    print(math.factorial(a+b)//(math.factorial(a)*math.factorial(b))%(10**9+7))


Fixed submission:
def ncr(n, r):
    r = min(r, n - r)
    if r == 0: return 1;
    if r == 1: return n;
    numerator = [n - r + i + 1 for i in range(r)]
    denominator  = [i + 1 for i in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= numerator[k]
            if result >10**9+7:
                result = result%(10**9+7)
    return result
x,y=map(int,input().split())
if (x+y)%3!=0 or 2*x<y or 2*y<x:
    print(0)
else:
    a=(2*y-x)//3
    b=(2*x-y)//3
    print(int(ncr(a+b,a)%(10**9+7)))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
ans = []
for i in range(n):
  ans.append(a.index(i+1)+1)
print(*ans)


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans = []
A = []
for i in range(n):
  ans.append((a[i],i+1))
ans.sort()
for i in range(n):
  A.append(ans[i][1])
print(*A)

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

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans = []
A = []
for i in range(n):
  ans.append((a[i],i+1))
ans.sort()
for i in range(n):
  A.append(ans[i][1])
print(*A)
Buggy python submission (verdict: Time Limit Exceeded):
n,k,q = map(int,input().split())
a = [int(input()) for i in range(q)]
for i in range(1,n+1):
    if a.count(i) <= q-k:
        print('No')
    else:
        print('Yes')


Fixed submission:
import collections
n,k,q = map(int,input().split())
a = [int(input()) for i in range(q)]
c = collections.Counter(a)
for i in range(1,n+1):
    if c[i] <= q-k:
        print('No')
    else:
        print('Yes')
Buggy python submission (verdict: Runtime Error):
N = int(input())
v = sorted(list(map(int,input().split())))
c = v[0]
for i in range(1,len(v)+1):
  c = (v[i]+c)/2
print(int(c))

Fixed submission:
N = int(input())
v = sorted(list(map(int,input().split())))
c = v[0]
for i in range(1,len(v)):
  c = (v[i]+c)/2
print(c)
Buggy python submission (verdict: Runtime Error):
k,x=map(int,input().split())
for i in range(x-k+1,x+k):
  if i<x+k-1:
    print(i,end' ')
  else:
    print(i)


Fixed submission:
k,x=map(int,input().split())
for i in range(x-k+1,x+k):
  if i<x+k-1:
    print(i,end=' ')
  else:
    print(i)

Buggy python submission (verdict: Runtime Error):
k,x=map(int,input().split())
for i in range(x-k+1,x+k):
  if i<x+k-1:
    print(i,end'')
  else:
    print(i)

Fixed submission:
k,x=map(int,input().split())
for i in range(x-k+1,x+k):
  if i<x+k-1:
    print(i,end=' ')
  else:
    print(i)