Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
import bisect

n, c = [int(item) for item in input().split()]

xs, vs, xrs = [], [], []
for i in range(n):
  x, v = [int(item) for item in input().split()]
  xs.append(x)
  xrs.append(c-x)
  vs.append(v)
xrs = xrs[::-1]

lft_v = list(accumulate(vs))
rgt_v = list(accumulate(vs[::-1]))

ans = 0
# No return
for i in range(n):
  ans = max(ans, lft_v[i]-xs[i], rgt_v[i]-xrs[i])
  
# Includes return
for i in range(n-1):
  for j in range(n-1-i):
    ans = max(ans, lft_v[i] - xs[i]*2 + rgt_v[j] - xrs[j])
    ans = max(ans, rgt_v[j] - xrs[j]*2 + lft_v[i] - xs[i])
    
print(ans)

Fixed submission:
from itertools import accumulate
import bisect

n, c = [int(item) for item in input().split()]

xs, vs, xrs = [], [], []
for i in range(n):
  x, v = [int(item) for item in input().split()]
  xs.append(x)
  xrs.append(c-x)
  vs.append(v)
xrs = xrs[::-1]

lft_v = list(accumulate(vs))
rgt_v = list(accumulate(vs[::-1]))

lft_c = []
rgt_c = []
for i in range(n):
  lft_c.append(lft_v[i]-xs[i])
  rgt_c.append(rgt_v[i]-xrs[i])
  
lft_max = [0] * n
rgt_max = [0] * n
lm, rm = 0,0
for i in range(n):
  if lm < lft_c[i]:
    lm = lft_c[i]
  lft_max[i] = lm
  if rm < rgt_c[i]:
    rm = rgt_c[i]
  rgt_max[i] = rm

ans = 0
# No return
for i in range(n):
  ans = max(ans, lft_c[i], rgt_c[i])
  
# Includes return
for i in range(n-1):
  ans = max(ans, lft_c[i] - xs[i] + rgt_max[n-2-i])
  ans = max(ans, rgt_c[i] - xrs[i] + lft_max[n-2-i])
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(item) for item in input().split()]
a.sort()

ai = a[-1]
aj = 1
for item in a[:-1]:
  diff = 1
  for i in range(item - aj):
    diff *= ai - aj - i
    diff /= item - i
  if diff < 1:
    break
  aj = item

print(ai, aj)
  

Fixed submission:
import bisect
import math

n = int(input())
a = [int(item) for item in input().split()]
a.sort()
ai = a[-1]

left = bisect.bisect(a, ai/2) - 1
right = left + 1

if a[right] - ai/2 >= ai/2 - a[left]:
  print(ai, a[left])
else:
  print(ai, a[right])
Buggy python submission (verdict: Time Limit Exceeded):
h, w, d = [int(item) for item in input().split()]
a = [[int(item) for item in input().split()] for _ in range(h)]
q = int(input())
lr = [[int(item) for item in input().split()] for _ in range(q)]

size = h * w
dist = [[0] * ((size)//d + 1) for _ in range(d)]

def get_dist(x, y):
  for i, line in enumerate(a):
    if x in line:
      xid = [i, line.index(x)]
    if y in line:
      yid = [i, line.index(y)]
  distance = abs(xid[0] - yid[0]) + abs(xid[1] - yid[1])
  return distance

for i in range(d):
  for j in range((size)//d + 1):
    if (j-1)*d+i <= 0:
      continue
    if j*d + i > size:
      continue
    dist[i][j] = dist[i][j-1] + get_dist(j*d+i, (j-1)*d+i)

for l, r in lr:
  print(dist[r%d][r//d] - dist[l%d][l//d])
    

Fixed submission:
h, w, d = [int(item) for item in input().split()]
a = [[int(item) for item in input().split()] for _ in range(h)]
q = int(input())
lr = [[int(item) for item in input().split()] for _ in range(q)]

size = h * w
dist = [[0] * ((size)//d + 1) for _ in range(d)]
ilist = [0] * (size+1)
jlist = [0] * (size+1)

for i in range(h):
  for j in range(w):
    ilist[a[i][j]] = i
    jlist[a[i][j]] = j

def get_dist(x, y):
  distance = abs(ilist[x] - ilist[y]) + abs(jlist[x] - jlist[y])
  return distance

for i in range(d):
  for j in range((size)//d + 1):
    if (j-1)*d+i <= 0 or j*d + i > size:
      continue
    dist[i][j] = dist[i][j-1] + get_dist(j*d+i, (j-1)*d+i)

for l, r in lr:
  print(dist[r%d][r//d] - dist[l%d][l//d])
Buggy python submission (verdict: Runtime Error):
2
5 1 1
100 1 1

Fixed submission:
n = int(input())
txy = [[0,0,0]] + [[int(item) for item in input().split()] for _ in range(n)]

for i in range(n+1):
    if i == 0:
        continue
    t, x, y = txy[i-1]
    nt, nx, ny = txy[i]
    if abs(nx - x) + abs(ny - y) > nt - t:
        print("No")
        exit()
    if (abs(nx - x) + abs(ny - y)) % 2 != (nt - t) % 2:
        print("No")
        exit()
print("Yes")
Buggy python submission (verdict: Runtime Error):
n = int(input())
csf = [[int(item) for item in input().split()] for _ in range(n-1)]

for i in range(n):
    total_time = 0
    for c, s, f in csf[i:]:
        time = 0
        # wait for start
        if total_time < s:
            time += s - total_time
        # wait for next train
        else:
            time += total_time % f
        # take train
        time += c
        total_time += time
    print(total_time

Fixed submission:
n = int(input())
csf = [[int(item) for item in input().split()] for _ in range(n-1)]

for i in range(n):
    total_time = 0
    for c, s, f in csf[i:]:
        time = 0
        # wait for start
        if total_time < s:
            time += s - total_time
        # wait for next train
        else:
            time += (f - total_time % f) % f
        # take train
        time += c
        total_time += time
    print(total_time)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(item) for item in input().split()]

count = Counter(a)
ans = 0
for i in count.keys():
    if count[i] < i:
        ans += count[i]
    else:
        ans += count[i] - i

print(ans)

Fixed submission:
from collections import Counter

n = int(input())
a = [int(item) for item in input().split()]

count = Counter(a)
ans = 0
for i in count.keys():
    if count[i] < i:
        ans += count[i]
    else:
        ans += count[i] - i

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

n, k = [int(item) for item in input().split()]
wd = []
for i in range(n):
    w, d = [int(item) for item in input().split()]
    wd.append((w, d))

l = -1; r = 10**20
while r - l > 1:
    mid = (l + r) // 2
    flower = 0
    for w, d in wd:
        if mid - w >= 0:
            flower += (mid - w) // d + 1
        if flower >= k:
            break
    if flower >= k:
        r = mid
    else:
        l = mid
print(r)


Fixed submission:
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

n, k = [int(item) for item in input().split()]
wd = []
for i in range(n):
    w, d = [int(item) for item in input().split()]
    wd.append((w, d))

l = -1; r = 10**20
while r - l > 1:
    mid = (l + r) // 2
    flower = 0
    for w, d in wd:
        if mid - w >= 0:
            flower += (mid - w) // d + 1
        if flower >= k:
            break
    if flower >= k:
        r = mid
    else:
        l = mid
print(r)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
s = input().rstrip()
cnt = Counter(s)
a = list(cnt.values())
a.sort()
if (a[2] - a[0]) > 1:
    print("NO")
else:
    print("YES")

Fixed submission:
from collections import Counter
s = input().rstrip()
n = len(s)
cnt = Counter(s)
a = list(cnt.values())
while len(a) < 3:
    a.append(0)
a.sort()
if a[2] - a[0] < 2:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
import bisect
a, b, c, d, e, f = [int(item) for item in input().split()]

water = set()
for i in range(31):
    for j in range(31):
        w = i*a + j*b 
        if w <= f // 100:
            water.add(w)
sugar = set()
for i in range(1501):
    j = 0
    while i*c + j*d <= 1500:
        sugar.add(i*c + j*d)
        j += 1
sugar = sorted(sugar)
ans = []
for w in water:
    sid = bisect.bisect_left(sugar, w*e)
    while sugar[sid] + w*100 > f:
        sid -= 1
    if w != 0:
        total = w*100 + sugar[sid]
        ans.append([sugar[sid]/total, total, sugar[sid]])
ans.sort(key=lambda x:x[0])
print(ans[-1][1], ans[-1][2])

Fixed submission:
import bisect
a, b, c, d, e, f = [int(item) for item in input().split()]

water = set()
for i in range(31):
    for j in range(31):
        w = i*a + j*b 
        if w <= f // 100:
            water.add(w)
water = sorted(water)
sugar = set()
for i in range(1501):
    j = 0
    while i*c + j*d <= 1500:
        sugar.add(i*c + j*d)
        j += 1
sugar = sorted(sugar)
ans = []
for w in water:
    sid = bisect.bisect_right(sugar, w*e) - 1
    while sugar[sid] + w*100 > f and sid > 0:
        sid -= 1
    if w != 0:
        total = w*100 + sugar[sid]
        ans.append([sugar[sid]/total, total, sugar[sid]])
ans.sort(key=lambda x:x[0])
print(ans[-1][1], ans[-1][2])
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
INF = 10**10
n = int(input())
a = [[int(item) for item in input().split()] for _ in range(n)]
b = [[INF for _ in range(n)] for _ in range(n)]

ans = sum(map(sum, a)) // 2
for k in range(n):
    for i in range(n):
        for j in range(i, n):
            b[i][j] = min(b[i][j], a[i][k] + a[k][j])
            b[j][i] = b[i][j]
            if a[i][j] == a[i][k] + a[k][j] and j != k and i != k:
                ans -= a[i][j]

if a == b:
    print(ans)
else:
    print(-1)

Fixed submission:
import heapq
INF = 10**10
n = int(input())
a = [[int(item) for item in input().split()] for _ in range(n)]
b = [[INF for _ in range(n)] for _ in range(n)]

ans = 0
for i in range(n):
    ans += sum(a[i])
    a[i][i] = INF
ans //= 2

for i in range(n):
    for j in range(i):
        bipas = min(map(sum, zip(a[i], a[j])))
        if a[i][j] > bipas:
            print(-1)
            exit()
        if a[i][j] == bipas:
            ans -= a[i][j]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
INF = 10**10
n = int(input())
a = [[int(item) for item in input().split()] for _ in range(n)]
b = [[INF for _ in range(n)] for _ in range(n)]

for k in range(n):
    for i in range(n):
        for j in range(n):
            b[i][j] = min(b[i][j], a[i][k] + a[k][j])

ans = sum(map(sum, a)) // 2
for k in range(n):
    for i in range(n):
        for j in range(i+1, n):
            if b[i][j] == a[i][k] + a[k][j] and j != k and i != k:
                ans -= b[i][j]
if a == b:
    print(ans)
else:
    print(-1)

Fixed submission:
import heapq
INF = 10**10
n = int(input())
a = [[int(item) for item in input().split()] for _ in range(n)]
b = [[INF for _ in range(n)] for _ in range(n)]

ans = 0
for i in range(n):
    ans += sum(a[i])
    a[i][i] = INF
ans //= 2

for i in range(n):
    for j in range(i):
        bipas = min(map(sum, zip(a[i], a[j])))
        if a[i][j] > bipas:
            print(-1)
            exit()
        if a[i][j] == bipas:
            ans -= a[i][j]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations
n, m, r = [int(item) for item in input().split()]
rs = [int(item) for item in input().split()]
abc = [[int(item) for item in input().split()] for _ in range(m)]

INF = 10**6
path = [[INF] * n for _ in range(n)]
short_path = [[INF] * n for _ in range(n)]
for i in range(n):
    path[i][i] = 0
for a, b, c in abc:
    path[a-1][b-1] = path[b-1][a-1] = c

for k in range(n):
    for i in range(n):
        for j in range(n):
            short_path[i][j] = min(short_path[i][j], path[i][k] + path[k][j])

ans = INF
for pattern in permutations(rs):
    distance = 0
    for i in range(1,r):
        distance += short_path[pattern[i-1]-1][pattern[i]-1]
    ans = min(ans, distance)
print(ans)

Fixed submission:
import heapq
from itertools import permutations
n, m, r = [int(item) for item in input().split()]
rs = [int(item) for item in input().split()]
abc = [[int(item) for item in input().split()] for _ in range(m)]
INF = 10**9

class Dijkstra:
    def __init__(self, adj):
        self.adj = adj
        self.num = len(adj)
        self.dist = [INF] * self.num
        self.prev = [INF] * self.num
        self.q = []

    def reset(self):
        self.dist = [INF] * self.num
        self.prev = [INF] * self.num
        self.q = []

    def calc(self, start, goal=None):
        self.dist[start] = 0
        heapq.heappush(self.q, (0, start))
        while len(self.q) != 0:
            prov_cost, src = heapq.heappop(self.q)
            if self.dist[src] < prov_cost:
                continue
            for dest in range(self.num):
                cost = self.adj[src][dest]
                if cost != INF and self.dist[dest] > self.dist[src] + cost:
                    self.dist[dest] = self.dist[src] + cost
                    heapq.heappush(self.q, (self.dist[dest], dest))
                    self.prev[dest] = src
        if goal is not None:
            return self.get_path(goal)
        else:
            return self.dist

    def get_path(self, goal):
        path = [goal]
        dest = goal

        while self.prev[dest] != INF:
            path.append(self.prev[dest])
            dest = self.prev[dest]
        return list(reversed(path))

path = [[INF] * n for _ in range(n)]
short_path = [[INF] * n for _ in range(n)]
for i in range(n):
    path[i][i] = 0
for a, b, c in abc:
    path[a-1][b-1] = path[b-1][a-1] = c

dij = Dijkstra(path)
for item in rs:
    for i in range(n):
        short_path[item-1][i] = dij.calc(item-1)[i]
    dij.reset()

ans = INF
for pattern in permutations(rs):
    distance = 0
    for i in range(1,r):
        distance += short_path[pattern[i-1]-1][pattern[i]-1]
    ans = min(ans, distance)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
t = []
for i in range(n):
    t.append(int(input()))

ans = t[0]
for i in range(1,n):
    ans = ans * t[i] // math.gcd(ans, t[i])
print(ans)

Fixed submission:
import fractions
n = int(input())
t = []
for i in range(n):
    t.append(int(input()))

ans = t[0]
for i in range(1,n):
    ans = ans * t[i] // fractions.gcd(ans, t[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
abc = [[int(item) for item in input().split()] for _ in range(n-1)]
q, k = [int(item) for item in input().split()]
xy = [[int(item) for item in input().split()] for _ in range(q)]

distance = [0] * n
e = [[] for _ in range(n)]
w = [[] for _ in range(n)]
for a, b, c in abc:
    e[a-1].append(b-1)
    e[b-1].append(a-1)
    w[a-1].append(c)
    w[b-1].append(c)

def dfs(v, par, dist):
    distance[v] = dist
    if len(e[v]) == 0:
        return True
    for i in range(len(e[v])):
        if e[v][i] == par:
            continue
        dfs(e[v][i], v, dist + w[v][i])

dfs(k-1, -1, 0)
for x, y in xy:
    print(distance[x-1] + distance[y-1])

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

n = int(input())
abc = [[int(item) for item in input().split()] for _ in range(n-1)]
q, k = [int(item) for item in input().split()]
xy = [[int(item) for item in input().split()] for _ in range(q)]

distance = [0] * n
e = [[] for _ in range(n)]
w = [[] for _ in range(n)]
for a, b, c in abc:
    e[a-1].append(b-1)
    e[b-1].append(a-1)
    w[a-1].append(c)
    w[b-1].append(c)

def dfs(v, par, dist):
    distance[v] = dist
    if len(e[v]) == 0:
        return True
    for i in range(len(e[v])):
        if e[v][i] == par:
            continue
        dfs(e[v][i], v, dist + w[v][i])

dfs(k-1, -1, 0)
for x, y in xy:
    print(distance[x-1] + distance[y-1])
Buggy python submission (verdict: Runtime Error):
ab_a = sorted(ab)
ab_b = sorted(ab, key= lambda x:x[1])

way = [0] * (n + 1)
for a, b in ab:
    if a == 1:
        way[b] += 1
    if b == 1:
        way[a] += 1
    if a == n:
        way[b] += 1
    if b == n:
        way[a] += 1
if 2 in way:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Fixed submission:
n, m = [int(item) for item in input().split()]
ab = [[int(item) for item in input().split()] for _ in range(m)]

way = [0] * (n + 1)
for a, b in ab:
    if a == 1:
        way[b] += 1
    if b == 1:
        way[a] += 1
    if a == n:
        way[b] += 1
    if b == n:
        way[a] += 1
if 2 in way:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
n, m = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]

def calc(l, m1, m2, r):
    val = [0] * 4
    for a1, a2 in zip(a, a[1:]):
        diff = (a2 - a1 + m) % m
        val[0] += min(diff, (a2 - l + m) % m + 1)
        val[1] += min(diff, (a2 - m1 + m) % m + 1)
        val[2] += min(diff, (a2 - m2 + m) % m + 1)
        val[3] += min(diff, (a2 - r + m) % m + 1)
    return val.index(min(val)), min(val)

l = 1; r = m
while r - l > 2:
    m1 = (l * 2 + r) // 3
    m2 = (l + r * 2) // 3
    ret, _ = calc(l, m1, m2, r)
    if ret == 0:
        r = m1
    elif ret == 1:
        r = m2
    elif ret == 2:
        l = m1
    else:
        l = m2
_, ans = calc(l, m1, m2, r)
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
from collections import Counter

n, m = [int(item) for item in input().split()]
a = [int(item) - 1 for item in input().split()]
cnt_t = [0] * m

ans = [0] * m
cnt_r = [0] * (m + 1)
for a1, a2 in zip(a, a[1:]):
    ans[0] += min((m + a2 - a1) % m, (m + a2 - 0) % m + 1)
    cnt_t[a2] += (m + a2 - a1) % m - 1
    if (m + a2 - a1) % m <= 1:
        continue
    add = (a1 + 2) % m
    sub = a2 + 1
    if add < sub:
        cnt_r[add] += 1
        cnt_r[sub] -= 1
    else:
        cnt_r[add] += 1
        cnt_r[sub] -= 1
        cnt_r[0] += 1
        cnt_r[m] -=1
for i in range(m):
    cnt_r[i+1] += cnt_r[i]

for i in range(1, m):
    ans[i] = ans[i - 1] - cnt_r[i] + cnt_t[i - 1]
print(min(ans))
Buggy python submission (verdict: Runtime Error):
n, m = [int(item) for item in input().split()]
count = [0] * n
for i in range(n):
    a, b = [int(item) for item in input().split()]
    count[a-1] += 1
    count[b-1] += 1
for item in count:
    print(item)

Fixed submission:
n, m = [int(item) for item in input().split()]
count = [0] * n
for i in range(m):
    a, b = [int(item) for item in input().split()]
    count[a-1] += 1
    count[b-1] += 1
for item in count:
    print(item)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

n, m = [int(item) for item in input().split()]
edge = [[] for _ in range(n+1)]
INF =  2000 * 10**10
for i in range(m):
    a, b, c = [int(item) for item in input().split()]
    edge[a-1].append([b-1,c])
edge[n-1].append([n, 0])

def dfs(prev, prev_c, v):
    if v == n:
        return 0
    max_cost = -INF
    for e in edge[v]:
        if e[0] == prev:
            if prev_c + e[1] > 0:
                max_cost = INF
            continue
        max_cost = max(max_cost, e[1] + dfs(v, e[1], e[0]))
    return max_cost

cost = dfs(-1, 0, 0)
if cost > INF // 2:
    print("inf")
else:
    print(cost)

Fixed submission:
n, m = [int(item) for item in input().split()]
edge = []
inf =  2000 * 10**10
for i in range(m):
    a, b, c = [int(item) for item in input().split()]
    edge.append([a-1, b-1, -c])

def BellmanFord(start):
    dist = [inf for i in range(n)]
    dist[0] = 0
    for i in range(n):
        for u, v, c in edge:
            if dist[u] != inf and (dist[u] + c) < dist[v]:
                dist[v] = dist[u] + c
                if i == n-1 and v == n-1:
                    return "inf"
    return -dist[-1]

ret = BellmanFord(0)
print(ret)

Buggy python submission (verdict: Runtime Error):
n, m = [int(item) for item in input().split()]
edge = [[] for _ in range(n+1)]
INF =  2000 * 10**9
for i in range(m):
    a, b, c = [int(item) for item in input().split()]
    edge[a-1].append([b-1,c])
edge[n-1].append([n, 0])

def dfs(prev, prev_c, v):
    if v == n:
        return 0
    max_cost = -INF
    for e in edge[v]:
        if e[0] == prev:
            if prev_c + e[1] > 0:
                max_cost = INF
            continue
        max_cost = max(max_cost, e[1] + dfs(v, e[1], e[0]))
    return max_cost

cost = dfs(-1, 0, 0)
if cost > INF // 2:
    print("inf")
else:
    print(cost)

Fixed submission:
n, m = [int(item) for item in input().split()]
edge = []
inf =  2000 * 10**10
for i in range(m):
    a, b, c = [int(item) for item in input().split()]
    edge.append([a-1, b-1, -c])

def BellmanFord(start):
    dist = [inf for i in range(n)]
    dist[0] = 0
    for i in range(n):
        for u, v, c in edge:
            if dist[u] != inf and (dist[u] + c) < dist[v]:
                dist[v] = dist[u] + c
                if i == n-1 and v == n-1:
                    return "inf"
    return -dist[-1]

ret = BellmanFord(0)
print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(item) for item in input().split()]
a = sorted([int(item) for item in input().split()], reverse=True)
max_k = min(sum(a), 5000)

def check_needed(index):
    memo = [[0] * (max_k + 1) for _ in range(n+1)]
    memo[0][0] = 1
    for i in range(n):
        for j in range(max_k + 1):
            if memo[i][j] == 1: 
                memo[i+1][j] = 1 
                if i != index and j+a[i] <= max_k:
                    memo[i+1][j+a[i]] = 1 
    return (1 in memo[n][max(k-a[index], 0):k])

l = -1
r = n
while r-l > 1:
    mid = (l+r) // 2
    if not check_needed(mid):
        r = mid
    else:
        l = mid
if sum(a) < k:
    print(n)
else:
    print(n - r)

Fixed submission:
n, k = [int(item) for item in input().split()]
a = sorted([int(item) for item in input().split()], reverse=True)

count = 0
asum = 0
for item in a:
    if asum + item < k:
        asum += item
        count += 1
    else:
        count = 0

print(count)

Buggy python submission (verdict: Runtime Error):
n, k = [int(item) for item in input().split()]
a = sorted([int(item) for item in input().split()], reverse=True)
max_k = min(sum(a), 5000)

def check_needed(index):
    memo = [[0] * (max_k + 1) for _ in range(n+1)]
    memo[0][0] = 1
    for i in range(n):
        for j in range(max_k + 1):
            if memo[i][j] == 1: 
                memo[i+1][j] = 1 
                if i != index:
                    memo[i+1][j+a[i]] = 1 
    return (1 in memo[n][max(k-a[index], 0):k])

l = -1
r = n
while r-l > 1:
    mid = (l+r) // 2
    if not check_needed(mid):
        r = mid
    else:
        l = mid
if sum(a) < k:
    print(n)
else:
    print(n - r)

Fixed submission:
n, k = [int(item) for item in input().split()]
a = sorted([int(item) for item in input().split()], reverse=True)

count = 0
asum = 0
for item in a:
    if asum + item < k:
        asum += item
        count += 1
    else:
        count = 0

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(item) for item in input().split()]
a = sorted([int(item) for item in input().split()], reverse=True)

sum_possibility = [0] * 10001
sum_possibility[0] = 1

for i in range(n+1):
    if sum(sum_possibility[max(0, k-sum(a[i:])):k]) == 0:
        break
    for j in range(10000, -1, -1):
        if sum_possibility[j] is not 0 and j + a[i] < 10001:
            sum_possibility[j + a[i]] = 1
print(n-i)

Fixed submission:
n, k = [int(item) for item in input().split()]
a = sorted([int(item) for item in input().split()], reverse=True)

count = 0
asum = 0
for item in a:
    if asum + item < k:
        asum += item
        count += 1
    else:
        count = 0

print(count)
Buggy python submission (verdict: Runtime Error):
a, b = [int(item) for item in input().split()]
if a > b:
  print("Alice")
eiif a == b:
  print("Draw")
else:
  print("Bob")

Fixed submission:
a, b = [int(item) for item in input().split()]
if a == 1:
  a += 100
if b == 1:
  b += 100
  
if a > b:
  print("Alice")
elif a == b:
  print("Draw")
else:
  print("Bob")