Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [''.join(sorted(input())) for i in range(n)]


cnt = 0
set_list = set(s)
for i in set_list:
    num = s.count(i)
    tmp = num * (num - 1) / 2
    cnt += tmp

print(int(cnt))


Fixed submission:
n = int(input())
s = [''.join(sorted(input())) for i in range(n)]

cnt = 0
dic = {}
for i in s:
    dic.setdefault(i, 0)
    cnt += dic[i]
    dic[i] += 1

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [''.join(sorted(input())) for i in range(n)]


cnt = 0
for i in range(len(s)):
    tmp = s[i+1:].count(s[i])
    cnt += tmp

print(cnt)

Fixed submission:
n = int(input())
s = [''.join(sorted(input())) for i in range(n)]

cnt = 0
dic = {}
for i in s:
    dic.setdefault(i, 0)
    cnt += dic[i]
    dic[i] += 1

print(cnt)

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

n = int(input())
s = [''.join(sorted(list(input()))) for i in range(n)]


cnt = 0
for i in range(len(s)):
    d = collections.Counter()
    d.update(s[i+1:])
    cnt += d[s[i]]

print(cnt)

Fixed submission:
n = int(input())
s = [''.join(sorted(input())) for i in range(n)]

cnt = 0
dic = {}
for i in s:
    dic.setdefault(i, 0)
    cnt += dic[i]
    dic[i] += 1

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [''.join(sorted(list(input()))) for i in range(n)]


cnt = 0
for i in range(len(s)):
    tmp = s[i+1:].count(s[i])
    cnt += tmp

print(cnt)


Fixed submission:
n = int(input())
s = [''.join(sorted(input())) for i in range(n)]

cnt = 0
dic = {}
for i in s:
    dic.setdefault(i, 0)
    cnt += dic[i]
    dic[i] += 1

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
h = list(map(int, input().split()))

answer = 'Yes'

for i in range(n):
    if i == (n - 1):
        break
    index = n - (i + 1)
    for j in range(index):
        if (h[j] - h[index]) >= 2:
            answer = 'No'
            break

print(answer)




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

answer = 'Yes'

pre = 0
for i in range(n):
    if pre <= h[i]-1:
        pre = h[i]-1
    elif pre <= h[i]:
        pre = h[i]
    else:
        answer = 'No'
        break

print(answer)
Buggy python submission (verdict: Runtime Error):
a,b,c = input()
print("Yes" if a == c else: "No")

Fixed submission:
a,b,c=input()
print("Yes" if a==c else "No")

Buggy python submission (verdict: Runtime Error):
a,b,c = input()
print("Yes" if a == c else: "No")

Fixed submission:
a,b,c=input()
print("Yes" if a==c else "No")

Buggy python submission (verdict: Runtime Error):
a,b,c = input()
print('Yes' if a == c else: 'No')

Fixed submission:
a,b,c=input()
print("Yes" if a==c else "No")

Buggy python submission (verdict: Runtime Error):
a,b,c = input()
print('Yes' if a == c:else: 'No')

Fixed submission:
a,b,c=input()
print("Yes" if a==c else "No")
Buggy python submission (verdict: Runtime Error):
a,b = input().spilt()

if a==b:
  print('H')
else:
  print('D')

Fixed submission:
a,b = input().split()
 
if a==b:
  print('H')
else:
  print('D')

Buggy python submission (verdict: Runtime Error):
a,b = input().spilt()

if (a==b):
  print('H')
else:
  print('D')
    

Fixed submission:
a,b = input().split()
 
if a==b:
  print('H')
else:
  print('D')
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import count

N, K = map(int, input().split())
As = [int(n) for n in input().split()]

visited = []
now = 0
num = 0
idx = 0
for i in count():
    if now in visited:
        idx = visited.index(now)
        num = len(visited) - idx
        break
    visited.append(now)
    now = As[now] - 1

if K <= idx:
    print(visited[K] + 1)
else:
    print(visited[idx + (K - idx) % num] + 1)

Fixed submission:
from itertools import count

N, K = map(int, input().split())
As = [int(n) for n in input().split()]

visited = []
visited_set = set()
now = 0
num = 0
idx = 0
for i in count():
    if now in visited_set:
        idx = visited.index(now)
        num = len(visited) - idx
        break
    visited_set.add(now)
    visited.append(now)
    now = As[now] - 1

if K <= idx:
    print(visited[K] + 1)
else:
    print(visited[idx + (K - idx) % num] + 1)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

X, Y, A, B, C = map(int, input().split())
P = [int(n) for n in input().split()]
Q = [int(n) for n in input().split()]
R = [int(n) for n in input().split()]

P.sort()
Q.sort()
R.sort(reverse=True)

PQ = deque(sorted(P[-X:] + Q[-Y:]))
R = deque(R)

while True:
    if not R or R[0] <= PQ[0]:
        break
    if P[0] > PQ[0]:
        PQ.append(R.popleft())
        PQ.popleft()

print(sum(PQ))

Fixed submission:
from collections import deque
from itertools import count

X, Y, A, B, C = map(int, input().split())
P = [int(n) for n in input().split()]
Q = [int(n) for n in input().split()]
R = [int(n) for n in input().split()]


P.sort()
Q.sort()
R.sort(reverse=True)

P = deque(P[-X:])
Q = deque(Q[-Y:])
R = deque(R)

for i in count():
    if not R or P[0] >= R[0] <= Q[0]:
        break
    if R[0] >= P[0] <= Q[0]:
        P.append(R.popleft())
        P.popleft()
    elif R[0] >= Q[0] <= P[0]:
        Q.append(R.popleft())
        Q.popleft()

print(sum(P) + sum(Q))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
 
N = int(input())
As = [int(n) for n in input().split()]
 
C = Counter(As)
 
L = [(v * (v - 1) // 2, (v - 1) * (v - 2) // 2, k) for k, v in C.items()]
 
for i in range(N):
    print(sum([y if z == As[i] else x for x, y, z in L]))

Fixed submission:
from collections import Counter

N = int(input())
As = [int(n) for n in input().split()]

C = Counter(As)

ans = sum(v * (v - 1) // 2 for k, v in C.items())
M = [C[a] - 1 for a in As]

for m in M:
    print(ans - m)

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

N = int(input())
As = [int(n) for n in input().split()]

C = Counter(As)

L = [(v * (v - 1) // 2, (v - 1) * (v - 2) // 2, k) for k, v in C.items()]

for i in range(N):
    print(sum([y if z == As[i] else x for x, y, z in L]))

Fixed submission:
from collections import Counter

N = int(input())
As = [int(n) for n in input().split()]

C = Counter(As)

ans = sum(v * (v - 1) // 2 for k, v in C.items())
M = [C[a] - 1 for a in As]

for m in M:
    print(ans - m)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import count
 
H, N = map(int, input().split())
ABs = [tuple(map(int, input().split())) for _ in range(N)]
 
dp = [10 ** 9 for _ in range(H + 1)]
dp[0] = 0
for hp in range(1, H + 1):
    for A, B in ABs:
        if A <= hp:
            dp[hp] = min(dp[hp], dp[hp - A] + B)
        else:
            dp[hp] = min(dp[hp], B)
print(dp[-1])

Fixed submission:
from itertools import count
 
H, N = map(int, input().split())
ABs = [tuple(map(int, input().split())) for _ in range(N)]
 
dp = [10 ** 9 for _ in range(H + 1)]
dp[0] = 0
for hp in range(1, H + 1):
    # print(dp)
    for A, B in ABs:
        if A <= hp:
            dp[hp] = min(dp[hp], dp[hp - A] + B)
        else:
            dp[hp] = min(dp[hp], B)
print(dp[-1])

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

H, N = map(int, input().split())
ABs = [tuple(map(int, input().split())) for _ in range(N)]

dp = [10 ** 9 for _ in range(H + 1)]
dp[0] = 0
for hp in range(1, H + 1):
    # print(dp)
    for A, B in ABs:
        if A <= hp:
            dp[hp] = min(dp[hp], dp[hp - A] + B)
        else:
            dp[hp] = min(dp[hp], B)

print(dp[-1])


Fixed submission:
from itertools import count
 
H, N = map(int, input().split())
ABs = [tuple(map(int, input().split())) for _ in range(N)]
 
dp = [10 ** 9 for _ in range(H + 1)]
dp[0] = 0
for hp in range(1, H + 1):
    # print(dp)
    for A, B in ABs:
        if A <= hp:
            dp[hp] = min(dp[hp], dp[hp - A] + B)
        else:
            dp[hp] = min(dp[hp], B)
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import count

X = int(input())

pn = []
for L in count(2):
    chk = True
    for L2 in pn:
        if L % L2 == 0:
            break
    else:
        pn.append(L)
        if L >= X:
            print(L)
            break

Fixed submission:
from itertools import count

X = int(input())

pn = []
for L in count(2):
    chk = True
    for L2 in pn:
        if L % L2 == 0:
            break
    else:
        pn.append(L)
        if L >= X:
            print(L)
            break
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = 0
for i in range(60 + 1):
    cnt = 0
    for a in A:
        if a >> i & 1:
            cnt += 1
    ans = (ans + 2 ** i * cnt * (N - cnt)) % (10 ** 9 + 7)
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

ans = 0
for i in range(60 + 1):
    cnt = 0
    for a in A:
        if a >> i & 1:
            cnt += 1
    ans = (ans + 2 ** i * cnt * (N - cnt)) % (10 ** 9 + 7)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ss = [''.join(sorted(input())) for _ in range(N)]
ssset = set(ss)

ans = 0
for s in ssset:
    n = ss.count(s)
    if n > 1:
        ans += n * (n - 1) // 2

print(ans)

Fixed submission:
from collections import Counter
N = int(input())
ss = [''.join(sorted(input())) for _ in range(N)]

sscounts = Counter(ss)

ans = 0
for s, n in sscounts.items():
    if n > 1:
        ans += n * (n - 1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

N = int(input())
ss = [''.join(sorted(input())) for _ in range(N)]
ssset = set(ss)

def cmb(n,r):
    r = min(n-r,r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

ans = 0
for s in ssset:
    n = ss.count(s)
    if n > 1:
        ans += cmb(n, 2)

print(ans)

Fixed submission:
from collections import Counter
N = int(input())
ss = [''.join(sorted(input())) for _ in range(N)]

sscounts = Counter(ss)

ans = 0
for s, n in sscounts.items():
    if n > 1:
        ans += n * (n - 1) // 2

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

N = int(input())
As = [int(input()) for _ in range(N)]

list_ = [As[0]]
for a in As[1:]:
    i = bisect_left(list_, a) - 1
    if i < 0:
        list_.insert(0, a)
    else:
        list_[i] = a
print(len(list_))

Fixed submission:
from bisect import bisect_left
from collections import deque

N = int(input())
As = [int(input()) for _ in range(N)]

list_ = deque([As[0]])
for a in As[1:]:
    i = bisect_left(list_, a) - 1
    if i < 0:
        list_.appendleft(a)
    else:
        list_[i] = a
print(len(list_))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
As = [int(input()) for _ in range(N)]

list_ = [As[0]]
for a in As[1:]:
    if a > list_[0]:
        list_[0] = a
    elif a <= list_[-1]:
        list_.append(a)
    else:
        for i, l in enumerate(list_):
            if a > l:
                list_[i] = a
                break
print(len(list_))

Fixed submission:
from bisect import bisect_left
from collections import deque

N = int(input())
As = [int(input()) for _ in range(N)]

list_ = deque([As[0]])
for a in As[1:]:
    i = bisect_left(list_, a) - 1
    if i < 0:
        list_.appendleft(a)
    else:
        list_[i] = a
print(len(list_))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
As = [[int(input()), False] for _ in range(N)]

flag = True
count = 0
while flag:
    flag = False
    prev = -1
    count += 1
    for i, (a, visited) in enumerate(As):
        if visited:
            continue
        if prev < a:
            prev = a
            As[i][1] = True
        else:
            flag = True

print(count)

Fixed submission:
from bisect import bisect_left
from collections import deque

N = int(input())
As = [int(input()) for _ in range(N)]

list_ = deque([As[0]])
for a in As[1:]:
    i = bisect_left(list_, a) - 1
    if i < 0:
        list_.appendleft(a)
    else:
        list_[i] = a
print(len(list_))
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N, K = map(int, input().split())
a_bs = [tuple(map(int, input().split())) for _ in range(N - 1)]

def culc_tree(t, used_num):
    tree[t][1] = False
    global answer
    k = K - used_num
    print(t, k)
    answer = (answer * k) % (10 ** 9 + 7)
    childs = [next_ for next_ in tree[t][0] if tree[next_][1]]
    for i, child in enumerate(childs, 2):
        culc_tree(child, i)


tree = defaultdict(lambda: [[], True])
for a, b in a_bs:
    tree[a][0].append(b)
    tree[b][0].append(a)

answer = K
tree[1][1] = False
for i, child in enumerate(tree[1][0], 1):
    culc_tree(child, i)
print(answer)

Fixed submission:
import sys
from collections import defaultdict

sys.setrecursionlimit(10**5)

N, K = map(int, input().split())
a_bs = [tuple(map(int, input().split())) for _ in range(N - 1)]

def culc_tree(t, used_num):
    tree[t][1] = False
    global answer
    k = K - used_num
    answer = (answer * k) % (10 ** 9 + 7)
    childs = [next_ for next_ in tree[t][0] if tree[next_][1]]
    for i, child in enumerate(childs, 2):
        culc_tree(child, i)


tree = defaultdict(lambda: [[], True])
for a, b in a_bs:
    tree[a][0].append(b)
    tree[b][0].append(a)

answer = K
tree[1][1] = False
for i, child in enumerate(tree[1][0], 1):
    culc_tree(child, i)
print(answer)

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N, K = map(int, input().split())
a_bs = [tuple(map(int, input().split())) for _ in range(N - 1)]

def search_tree(t, queue):
    if tree[t][1]:
        return -1
    tree[t][1] = True
    global sum_
    k = K - sum(queue)
    sum_ = (sum_ * k) % (10**9 + 7)
    queue[0] = queue[1]
    queue[1] = 1
    for next_ in tree[t][0]:
        queue[0] += search_tree(next_, queue[:])
        queue[0] += 1
    return 0


tree = defaultdict(lambda: [[], False])
for a, b in a_bs:
    tree[a][0].append(b)
    tree[b][0].append(a)

sum_ = 1
search_tree(1, [0, 0])
print(sum_)

Fixed submission:
import sys
from collections import defaultdict

sys.setrecursionlimit(10**5)

N, K = map(int, input().split())
a_bs = [tuple(map(int, input().split())) for _ in range(N - 1)]

def culc_tree(t, used_num):
    tree[t][1] = False
    global answer
    k = K - used_num
    answer = (answer * k) % (10 ** 9 + 7)
    childs = [next_ for next_ in tree[t][0] if tree[next_][1]]
    for i, child in enumerate(childs, 2):
        culc_tree(child, i)


tree = defaultdict(lambda: [[], True])
for a, b in a_bs:
    tree[a][0].append(b)
    tree[b][0].append(a)

answer = K
tree[1][1] = False
for i, child in enumerate(tree[1][0], 1):
    culc_tree(child, i)
print(answer)
Buggy python submission (verdict: Runtime Error):
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


N, K = map(int, input().split())
R = N - K

print(R + 1)
for i in range(2, K + 1):
    tmp = cmb(R + 1, i)
    tmp2 = cmb(K - 1, K - i)
    print((tmp % (10**9 + 7) * tmp2 % (10**9 + 7)) % (10**9 + 7))

Fixed submission:
from operator import mul
from functools import reduce
from functools import lru_cache

@lru_cache(maxsize=1000)
def cmb(n,r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N, K = map(int, input().split())
R = N - K

print(R + 1)
for i in range(2, K + 1):
    if R + 1 < i:
        print(0)
        continue
    tmp = cmb(R + 1, i)
    tmp2 = cmb(K - 1, K - i)
    print((tmp % (10**9 + 7) * tmp2 % (10**9 + 7)) % (10**9 + 7))
Buggy python submission (verdict: Runtime Error):
from operator import mul
from functools import reduce

def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

def main():
    N, K = map(int, input().split())
    max_ = cmb(N - 1, 2)
    if N <= 2 or K > max_:
        print(-1)
        return
    M = N - 1 + max_ - K
    print(M)
    for i in range(2, N + 1):
        print(1, i)
    for i in range(2, 2 + max_ - K):
        print(i, i + 1)


main()

Fixed submission:
import itertools

def main():
    N, K = map(int, input().split())
    max_ = int((N - 1) * (N - 2) / 2)
    if K > max_:
        print(-1)
        return
    M = N - 1 + max_ - K
    print(M)
    for i in range(2, N + 1):
        print(1, i)
    for u, v in [(x[0], x[1]) for x in itertools.combinations(range(2, N + 1), 2)][:max_ - K]:
        print(u, v)

main()
Buggy python submission (verdict: Time Limit Exceeded):
import re
s = input()

count = 0
while 'ABC' in s:
    s = s.replace('ABC', 'BCA', 1)
    count += 1
print(count)

Fixed submission:
s = input()

s = s.replace('BC', 'D')
a_count = 0
count = 0
for c in s:
    if c == 'A':
        a_count += 1
    elif c == 'D':
        count += a_count
    else:
        a_count = 0

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce

n = int(input())
as_ = list(map(int, input().split()))

gcds = []

for i in range(n):
    as2 = as_[:]
    del as2[i]
    gcds.append(reduce(fractions.gcd, as2))

print(max(gcds))


Fixed submission:
from fractions import gcd

n = int(input())
as_ = list(map(int, input().split()))

gcd_all = as_.pop()
set_ = {as_[0]}
for a in as_:
    set_ = set(gcd(s, a) for s in set_)
    set_.add(gcd_all)
    gcd_all = gcd(gcd_all, a)

print(max(set_))
Buggy python submission (verdict: Runtime Error):
N, K = [int(n) for n in input().split()]
S = input()

sentous = []
sentou = 0
counts = [0]
count = 0
prev = 0
for s in S:
    count += 1
    if s == prev and count > 0:
        sentou += 1
    elif s != prev and s == '1':
        sentou += 1
    elif s != prev and s == '0':
        sentous.append(sentou + 1)
        sentou = 0
        if K > 0:
            K -= 1
        else:
            count -= sentous.pop(0)
        counts.append(count)
    prev = s

print(max(*counts, count))


Fixed submission:
N, K = [int(n) for n in input().split()]
S = input()

sentous = []
sentou = 0
counts = [0]
count = 0
prev = 0
for s in S:
    count += 1
    sentou += 1
    if s != prev and s == '1':
        if count > 1:
            sentous.append(sentou - 1)
        sentou = 1
    elif s != prev and s == '0':
        # sentou = 0
        if K > 0:
            K -= 1
        else:
            counts.append(count - 1)
            count -= sentous.pop(0)
    prev = s

print(max(max(counts), count))
Buggy python submission (verdict: Runtime Error):
import collections

N = int(input())
SSS = []

for i in range(N):
  SSS.append(input())
#print(N, SSS)

#print(collections.Counter(SSS).most_common())
hindo_ck = collections.Counter(SSS).most_common()

i = 1
hindo_max = list(hindo_ck[0])

if len(hindo_ck) > 1:
  del hindo_max[-1]
  while hindo_ck[i-1][1] == hindo_ck[i][1] and i < N:
    hindo_max.append(hindo_ck[i][0])
    i += 1
  hindo_max.sort()
  
  for h in hindo_max:
    print(h)
  
else:
  hindo_max = hindo_ck[0][0]
  print(hindo_max)
#print(result)



Fixed submission:
import collections

N = int(input())
SSS = []

for i in range(N):
  SSS.append(input())
#print(N, SSS)

#print(collections.Counter(SSS).most_common())
hindo_ck = collections.Counter(SSS).most_common()

i = 1
hindo_max = list(hindo_ck[0])

if len(hindo_ck) > 1:
  del hindo_max[-1]
  while i < N and hindo_ck[i-1][1] == hindo_ck[i][1]:
    hindo_max.append(hindo_ck[i][0])
    i += 1
  hindo_max.sort()
  
  for h in hindo_max:
    print(h)
  
else:
  hindo_max = hindo_ck[0][0]
  print(hindo_max)
#print(result)
Buggy python submission (verdict: Runtime Error):
i = input().split()
a = int(i[0])
b = int(i[1])
k = int(i[2])

if k >= a+b:
  c = d = 0

elif k == a:
  c = 0

elif k > a:
  c = 0
  d = b - (k - a)

else:
  c = a - k
  
print(c,d)

Fixed submission:
i = input().split()
a = int(i[0])
b = int(i[1])
k = int(i[2])
c = a 
d = b

if k >= a+b:
  c = d = 0

elif k == a:
  c = 0

elif k > a:
  c = 0
  d = b - (k - a)

else:
  c = a - k
  
print(c,d)

Buggy python submission (verdict: Time Limit Exceeded):
i = input().split()
a = int(i[0])
b = int(i[1])
k = int(i[2])

for n in range(k):
  if a >= 1:
    a -= 1
  elif b >= 1:
    b -= 1
  else:
    break
print(a,b)

Fixed submission:
i = input().split()
a = int(i[0])
b = int(i[1])
k = int(i[2])
c = a 
d = b

if k >= a+b:
  c = d = 0

elif k == a:
  c = 0

elif k > a:
  c = 0
  d = b - (k - a)

else:
  c = a - k
  
print(c,d)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, c, k = map(int, input().split())

sums = 0

for i in range(a):
    sums += 1
    k -= 1
    if k == 0:
        print(sums)

for i in range(b):
    sums += 0
    k -= 1
    if k == 0:
        print(sums)

for i in range(c):
    sums += -1
    k -= 1
    if k == 0:
        print(sums)


Fixed submission:
import sys

a, b, c, k = map(int, input().split())

sums = 0

if (k <= a):
    print(k)
    sys.exit()
else:
    sums += a
    k -= a

if (k <= b):
    print(sums)
    sys.exit()
else:
    k -= b

sums += -1 * k
print(sums)

Buggy python submission (verdict: Runtime Error):
a, b, c, k = map(int, input().split())

sums = 0

alist = [1] * a
blist = [0] * b
clist = [-1] * c

ll = alist + blist + clist

print(sum(ll[0:k]))

Fixed submission:
import sys

a, b, c, k = map(int, input().split())

sums = 0

if (k <= a):
    print(k)
    sys.exit()
else:
    sums += a
    k -= a

if (k <= b):
    print(sums)
    sys.exit()
else:
    k -= b

sums += -1 * k
print(sums)
Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
A = [0] + list(map(int,input().split()))
T = [1]
current_town = 1
for i in range(2,K+1):
    current_town = A[current_town]
    K -= 1
    if current_town in T:
        loop_towns = T[T[current_town]-1:]
        print(loop_towns[K%len(loop_towns)])
        break
    else:
        T.append(current_town)
else:
    print(A[current_town])

Fixed submission:
N,K=map(int,input().split())
A=[0]+list(map(int,input().split()))
T={}
T[1]=1
t=1
for i in range(2,K+1):
    a=A[t]
    t=a
    K-=1
    if a in T:
        l=list(T.keys())[T[a]-1:]
        print(l[K%len(l)])
        break
    else:
        T[a]=i
else:
    print(A[t])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(input()) for i in range(n)]
for i in range(n):
    _a=a[:]
    _a.pop(i)
    print(max(_a))


Fixed submission:
n=int(input())
t,s=0,0
a=[]
for i in range(n):
    _a=int(input())
    a.append(_a)
    if _a>t:
        t=_a
    elif _a==t or _a>s:
        s=_a
for _a in a:
    if _a==t:
        print(s)
    else:
        print(t)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
d = list(map(int, input().split()))
way = 0
for k in range(1,max(d)+1):
    arc = 0
    abc = 0
    for di in d:
        if di >= k:
            arc += 1
        else:
            abc += 1
    if arc == abc:
        way += 1
print(way)


Fixed submission:
n = int(input())
d = list(map(int, input().split()))
d.sort()
print(d[int(n/2)] - d[int(n/2)-1])
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,k=(int(n) for n in input().split())
count = 0
sum = 0
for i in range(a):
    if count == k:
        break
    else:
        count += 1
        sum += 1
for i in range(b):
    if count == k:
        break
    else:
        count += 1
for i in range(c):
    if count == k:
        break
    else:
        count += 1
        sum -= 1
print(sum)

Fixed submission:
a,b,c,k=(int(x) for x in input().split())
if a+b >= k:
  print(min(k,a))
else:
  print(a-k+a+b)
Buggy python submission (verdict: Runtime Error):
n,m=(int(x) for x in input().split())
a,A = (int(x) for x in input().split())
ans = max(n - (a+A), -1)
print(ans)

Fixed submission:
n,m=(int(x) for x in input().split())
a = [int(x) for x in input().split()]
ans = max(n - sum(a), -1)
print(ans)