Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02990 (python)

Fixed submission:
from operator import mul
from functools import reduce


def cmb(n, r):
	r = min(n - r, r)
	if r == 0:
		return 1
	numer = reduce(mul, range(n, n - r, -1))
	denom = reduce(mul, range(1, r + 1))
	return numer // denom % INF


N, K = map(int, input().split())
INF = 10 ** 9 + 7

for i in range(1, K + 1):
	if N - K + 1 >= i:
		print(cmb(K - 1, i - 1) * cmb(N - K + 1, i) % INF)
	else:
		print(0)

Buggy 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
	numer = reduce(mul, range(n, n - r, -1))
	denom = reduce(mul, range(1, r + 1))
	return numer // denom % INF


N, K = map(int, input().split())
INF = 10 ** 9 + 7

for i in range(1, K + 1):
	print(cmb(K - 1, i - 1) * cmb(N - K + 1, i) % INF)
Problem p03013 (python)

Fixed submission:
from itertools import product

INF = 1000000007

def mat2_mul(X, Y):
	z = [[0, 0], [0, 0]]
	for (i, j, k) in product(range(2), range(2), range(2)):
		z[i][j] += X[i][k] * Y[k][j]
	return z

def mat2_pow(X, n):
	if n == 0:
		return [[1, 0], [0, 1]]
	elif n % 2:
		return mat2_mul(X, mat2_pow(X, n - 1))
	else:
		half_pow = mat2_pow(X, n / 2)
		return mat2_mul(half_pow, half_pow)

def fib(n):
	if n == 0:
		return 0
	else:
		f = [[0, 1], [1, 1]]
	return mat2_pow(f, n - 1)[1][1]


N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
ans, start = 1, 0
tmp = []

for i in range(len(a)):
	if a[i] - a[i - 1] == 1:
		print(0)
		exit()

for k in a:
	tmp.append(fib(k - start) % INF)
	start = k + 1

for j in tmp:
	ans *= j
	ans %= INF

ans *= fib(N - start + 1)
print(ans % INF)

Buggy submission (verdict: Runtime Error):
MAX_N = 10**5+1
DP = [None] * (MAX_N + 1)  # 計算結果を保存する配列
DP[0] = 0  # 定義より
DP[1] = 1  # 定義より

def fib(n):
    # フィボナッチ数を2からnまで順に求めていく
    for i in range(2, n + 1):
        DP[i] = DP[i-1] + DP[i-2]
    return DP[n]

MOD = 10**9 + 7

N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]

ans = fib(a[0])
for i in range(M-1):
    ans *= fib(a[i+1] - a[i] - 1)
    ans %= MOD
ans *= fib(N - a[M-1])
ans %= MOD

print(ans)

Buggy submission (verdict: Runtime Error):
MAX_N = 10**5
DP = [None] * (MAX_N + 1)  # 計算結果を保存する配列
DP[0] = 0  # 定義より
DP[1] = 1  # 定義より

def fib(n):
    # フィボナッチ数を2からnまで順に求めていく
    for i in range(2, n + 1):
        DP[i] = DP[i-1] + DP[i-2]
    return DP[n]

MOD = 10**9 + 7

N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]

ans = fib(a[0])
for i in range(M-1):
    ans *= fib(a[i+1] - a[i] - 1)
    ans %= MOD
ans *= fib(N - a[M-1])
ans %= MOD

print(ans)
Problem p03207 (python)

Fixed submission:
N = int(input())
p = [int(input()) for _ in range(N)]
print(sum(p) - max(p) // 2)

Buggy submission (verdict: Runtime Error):
N = int(input())
p = [int(input()) for _ in N]
print(sum(p) - max(p) // 2)
Problem p03315 (python)

Fixed submission:
S = input()
ans = 0
for i in range(len(S)):
	if S[i] == "+":
		ans += 1
	else:
		ans -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
ans = 0
for i in range(len(S)):
	if S[i] == "+":
        ans += 1
    else:
      	ans -= 1
print(ans)
Problem p03631 (python)

Fixed submission:
n = list(map(str, input()))
if n[0] == n[2]:
	print("Yes")
else:
	print("No")

Buggy submission (verdict: Runtime Error):
n = list(map(str, input()))
if n[0] = n[2]:
	print("Yes")
else:
	print("No")
Problem p03745 (python)

Fixed submission:
def upper_or_lower(i):
    if A[i] < A[i + 1]:
        return "upper"
    elif A[i] > A[i + 1]:
        return "lower"
    else:
        return upper_or_lower(i + 1)


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

state = "upper"  # state が upper か lower で判定
ans = 1

# i = 0 の処理
if (len(A) > 2) and (A[0] > A[1]):
    state = "lower"

for i in range(2, N):
    if (state == "upper") and (A[i - 1] > A[i]):
        ans += 1
        if i < N - 1:
            state = upper_or_lower(i)
    elif (state == "lower") and (A[i - 1] < A[i]):
        ans += 1
        if i < N - 1:
            state = upper_or_lower(i)
    else:
        continue

print(ans)

Buggy submission (verdict: Runtime Error):
def upper_or_lower(i):
    if A[i] < A[i + 1]:
        return "upper"
    elif A[i] > A[i + 1]:
        return "lower"
    else:
        return upper_or_lower(i + 1)


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

state = "upper"  # state が upper か lower で判定
ans = 1

# i = 0 の処理
if A[0] > A[1]:
    state = "lower"

for i in range(2, N):
    if (state == "upper") and (A[i - 1] > A[i]):
        ans += 1
        if i < N - 1:
            state = upper_or_lower(i)
    elif (state == "lower") and (A[i - 1] < A[i]):
        ans += 1
        if i < N - 1:
            state = upper_or_lower(i)
    else:
        continue

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [0] * N
for i in range(N):
	A[i] = int(input())

for j in range(1, N):
	if A[j] in A[: j]:
		A[A[: j].index(A[j])] = -1
		A[j] = -1


print(len([k for k in A if k != -1]))
Problem p03804 (python)

Fixed submission:
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

for i in range(min(N - M + 2, N)):
	for j in range(min(N - M + 2, N)):
		# print("i=", i, "j=", j)
		if A[i][j: j + M] == B[0]:
			tmp = True
			for k in range(1, M):
				if A[i + k][j: j + M] == B[k]:
					pass
				else:
					tmp = False
					break
			if tmp:
				print("Yes")
				exit()
print("No")

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

for i in range(min(N - M + 2, N)):
	for j in range(min(N - M + 2, N)):
		# print("i=", i, "j=", j)
		if A[i][j: j + M] == B[0]:
			for k in range(1, M):
				tmp = True
				if A[i + k][j: j + M] == B[k]:
					pass
				else:
					tmp = False
					break
			if tmp:
				print("Yes")
				exit()
print("No")
Problem p02793 (python)

Fixed submission:
from fractions import gcd
N = int(input())
A = [int(i) for i in input().split()]
lcm = A[0]
MOD = 10**9 + 7
for a in A:
    lcm = (lcm // gcd(lcm,a) * a)
res = 0
for a in A:
    res += lcm //a
print(res % MOD)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
N = int(input())
A = [int(i) for i in input().split()]
lcm = A[0]
MOD = 10**9 + 7
for a in A:
    lcm = (lcm // gcd(lcm,a) * a)
res = 0
for a in A:
    res += lcm /a
print(res % MOD)
Problem p03137 (python)

Fixed submission:
def main():
    N, M = [int(n) for n in input().split()]
    X = [int(n) for n in input().split()]
    X.sort()
    diffs = [X[i+1]-X[i] for i in range(M-1)] # diffs[i]:=X[i+1]-X[i]
    diffs.sort(reverse=True)
    # print(diffs)
    cut = sum(diffs[:N-1])
    # print(cut)
    print(X[-1] - X[0] - cut)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#数直線を切り分ける
#
# 1 2 3  7 20   2




def f(start, cuts):
    if cuts == 0:
        if start > M - 1:
            return 0
        else:
            return X[M - 1] - X[start]
        # 一回も切れないなら全長を返す
    else:
        minscr = 10e6
        for s in range(start, M):
            scr = X[s] - X[start] + f(s + 1, cuts - 1)
            if scr < minscr:
                minscr = scr
        if(minscr == 10e6):
            return 0
        return minscr

N, M = input().split()
N, M = int(N), int(M)
X = input().split()
X = [int(n) for n in X]
X = sorted(X)

best_cut = []
best_hands = 10e6


print(f(0, N - 1))
Problem p02570 (python)

Fixed submission:
D, T, S = map(int, input().split())

if D <= T * S:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
A = list(map(int, input().split()))

def calc_primes(n):
    data = [i for i in range(2, n + 1)]
    for d in data:
        data = [x for x in data if (x == d or x % d != 0)]
    return data

# primes = calc_primes(int(math.sqrt(10**6)))                                                                                                                                                               

is_pairwise = False
prod = 1
all_gcd = A[0]
for a in A:
    all_gcd = math.gcd(all_gcd, a)
    if is_pairwise:
        g = math.gcd(prod, a)
        if g > 1:
            is_pairwise = False
        prod *= a

if is_pairwise:
    print('pairwise coprime')
elif all_gcd == 1:
    print('setwise coprime')
else:
    print('not coprime')
Problem p02598 (python)

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

def test(m):
    if m <= 0:
        return False
    needed = 0
    for a in A:
        needed += (a-1)//m
        if needed > K:
            return False
    return True

lb = 1
ub = max(A)

while True:
    m = (lb + ub) // 2
    if test(m):
        if test(m-1):
            ub = m - 1
        else:
            print(m)
            exit()
    else:
        lb = m + 1

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

def test(m):
    needed = 0
    for a in A:
        needed += (a-1)//m
        if needed > K:
            return False
    return True

lb = 1
ub = max(A)

while True:
    m = (lb + ub) // 2
    if test(m):
        if test(m-1):
            ub = m - 1
        else:
            print(m)
            exit()
    else:
        lb = m + 1
Problem p02623 (python)

Fixed submission:
import sys

def read_int():
    l = sys.stdin.readline().rstrip('\n').split(' ')
    return int(l[0])

def read_int_list():
    l = sys.stdin.readline().rstrip('\n').split(' ')
    return [int(i) for i in l]

N, M, K = tuple(read_int_list())
A = read_int_list()
B = read_int_list()

ans = 0
sum_k =  0

ai = 0
bi = 0

for i in range(len(A)):
    if sum_k + A[i] > K:
        break
    sum_k += A[i]
    ai = i + 1

for i in range(len(B)):
    if sum_k + B[i] > K:
        break
    sum_k += B[i]
    bi = i + 1

ans = ai + bi

for i in range(ai - 1, -1, -1):
    sum_k -= A[i]
    ai = i
    while bi < len(B) and sum_k + B[bi] <= K:
        sum_k += B[bi]
        bi += 1
    ans = max(ans, ai+bi)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys

def read_int():
    l = sys.stdin.readline().rstrip('\n').split(' ')
    return int(l[0])

def read_int_list():
    l = sys.stdin.readline().rstrip('\n').split(' ')                                                  
    return [int(i) for i in l]

N, M, K = tuple(read_int_list())                                                                      
A = read_int_list()                                                                                   
B = read_int_list()                                                                                   

def can_read(A, B, i, j, memo, k):                                                                    
    key = (i, j, k)                                                                                   
    if key in memo:                                                                                   
        return memo[key]                                                                              
    ans = 0
    if i < len(A) and A[i] <= k:                                                                      
        ans = max(ans, can_read(A, B, i+1, j, memo, k - A[i]) + 1)                                    
    if j < len(B) and B[j] <= k:                                                                      
        ans = max(ans, can_read(A, B, i, j+1, memo, k - B[j]) + 1)                                    
    memo[key] = ans                                                                                   
    return ans                                                                                        

memo = {}                                                                                             
print(can_read(A, B, 0, 0, memo, K))
Problem p02627 (python)

Fixed submission:
import sys

c = sys.stdin.readline().rstrip('\n')

if ord(c) >= ord('a') and ord(c) <= ord('z'):
  print('a')
else:
  print('A')

Buggy submission (verdict: Runtime Error):
imports sys

c = sys.stdin.readline()

if ord(c) >= 'a' and ord(c) <= 'z':
  print('a')
else:
  print('A')
Problem p02679 (python)

Fixed submission:
from collections import defaultdict, deque
import math

kMod = 1000000007

N = int(input())
key2count = defaultdict(lambda: [0, 0])

for _ in range(N):
    a, b = map(int, input().split())
    g = math.gcd(a, b)
    if a < 0 or a == 0 and b < 0:
        a, b = -a, -b
    if g > 0:
        a, b = a//g, b//g
    idx = 0
    if b <= 0:
        idx = 1
        a, b = -b, a
    key2count[(a, b)][idx] += 1

ans = 1
for key, val in key2count.items():
    if key == (0, 0):
        continue
    plus, minus = val
    ans *= (pow(2, plus, kMod) + pow(2, minus, kMod)-1)
    ans %= kMod

ans += sum(key2count[(0, 0)])

print((ans + kMod-1) % kMod)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict, deque
import math

kMod = 10**9 + 7

N = int(input())
key2count = defaultdict(lambda: [0, 0])

for _ in range(N):
    a, b = map(int, input().split())
    if abs(a * b) > 0:
        g = math.gcd(abs(a), abs(b))
    else:
        g = max(abs(a), abs(b))
    a, b = a//g, b//g
    if a < 0:
        a, b = -a, -b
    idx = 0
    if b < 0:
        idx = 1
        a, b = -b, a
    key2count[(a, b)][idx] += 1

ans = 1
for key, val in key2count.items():
    plus, minus = val
    ans *= (pow(2, plus, kMod) + pow(2, minus, kMod)-1)
    ans %= kMod

print((ans + kMod-1) % kMod)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict, deque
import math

kMod = 10**9 + 7

N = int(input())
key2count = defaultdict(lambda: [0, 0])

for _ in range(N):
    a, b = map(int, input().split())
    g = math.gcd(a, b)
    a, b = a//g, b//g
    if a < 0:
        a, b = -a, -b
    idx = 0
    if b < 0:
        idx = 1
        a, b = -b, a
    key2count[(a, b)][idx] += 1

ans = 1
for key, val in key2count.items():
    plus, minus = val
    ans *= (pow(2, plus, kMod) + pow(2, minus, kMod)-1)
    ans %= kMod

print((ans + kMod-1) % kMod)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict, deque
import math

kMod = 10**9 + 7

N = int(input())
key2count = defaultdict(lambda: [0, 0])

for _ in range(N):
    a, b = map(int, input().split())
    g = math.gcd(a, b)
    a, b = a//g, b//g
    if a < 0:
        a, b = -a, -b
    idx = 0
    if b < 0:
        idx = 1
        a, b = -b, a
    key2count[(a, b)][idx] += 1

print(key2count)
ans = 1
for key, val in key2count.items():
    plus, minus = val
    ans *= (pow(2, plus, kMod) + pow(2, minus, kMod)-1)
    ans %= kMod

print((ans + kMod-1) % kMod)
Problem p02792 (python)

Fixed submission:
import sys
from collections import defaultdict
N = int(sys.stdin.readline())
cnt = defaultdict(int)
for i in range(1, N+1):
  str_i = str(i)
  cnt[(str_i[0], str_i[-1])] += 1
 
ans = 0
for d1 in range(1, 10):
  for d2 in range(1, 10):
    d1, d2 = str(d1), str(d2)
    ans += cnt[(d1, d2)] * cnt[(d2, d1)]
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import defaultdict
N = int(sys.stdin.readline())
cnt = defaultdict(int)
for i in range(1, N+1):
  str_i = str(i)
  cnt[(str_i[0], str_i[-1])] += 1

ans = 0
for d1 in range(9):
  for d2 in range(9):
    ans += cnt[(d1, d2)] * cnt[(d2, d1)]
return ans
Problem p02580 (python)

Fixed submission:
from collections import defaultdict

h, w, m = map(int, input().split())

cnt_h = [0] * h
cnt_w = [0] * w
dic = defaultdict(int)

for _ in range(m):
    h_m, w_m = map(int, input().split())
    cnt_h[h_m - 1] += 1
    cnt_w[w_m - 1] += 1
    dic[(h_m - 1, w_m - 1)] += 1

max_h = max(cnt_h)
max_w = max(cnt_w)

mh = []
mw = []

for i in range(h):
    if max_h == cnt_h[i]:
        mh.append(i)

for i in range(w):
    if max_w == cnt_w[i]:
        mw.append(i)

for i in mh:
    for j in mw:
        if dic[(i, j)] == 0:
            print(max_h + max_w)
            quit()

print(max_h + max_w - 1)

Buggy submission (verdict: Runtime Error):
from collections import Counter
import numpy as np
from pprint import pprint

h, w, m = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]

grid = [[0] * h for _ in range(w)]

for i in range(m):
    grid[hw[i][1]-1][hw[i][0]-1] = 1


cnt_grid = []
for i in range(w):
    cnt_grid.append(Counter(grid[i]))


cnt_grid_h = 0
max_h = 0
for i in range(w):
    if cnt_grid_h < cnt_grid[i][1]:
        cnt_grid_h = cnt_grid[i][1]
        max_h = i
grid = np.rot90(grid)
grid = grid.tolist()
cnt_grid = []
for i in range(h):
    cnt_grid.append(Counter(grid[i]))

cnt_grid_w = 0
max_w = 0
for i in range(h):
    if cnt_grid_w < cnt_grid[i][1]:
        cnt_grid_w = cnt_grid[i][1]
        max_w = i
max_w = h - max_w - 1

if grid[max_h][max_w] == 1:
    print(cnt_grid_h + cnt_grid_w - 1)
else:
    print(cnt_grid_h + cnt_grid_w)
Problem p02753 (python)

Fixed submission:
s = str(input())
station_a = s.count('A')
station_b = s.count('B')
if station_a != 3 and station_b != 3:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s = input()
q = int(input())
query = [list(input().replace(' ','')) for _ in range(q)]

r = False
for i in range(q):
    if r:
        if len(query[i]) == 1:
            r = False
        elif query[i][1] == '1':
            s = s + query[i][2]
        else:
            s = query[i][2] + s
    else:
        if len(query[i]) == 1:
            r = True
        elif query[i][1] == '1':
            s = query[i][2] + s
        else:
            s = s + query[i][2]

if r:
    print(s[::-1])
else:
    print(s)
Problem p02777 (python)

Fixed submission:
s, t = map(str,input().split())
a, b = map(int,input().split())
u = str(input())

if u == s:
    print(a-1,b)
else:
    print(a,b-1)

Buggy submission (verdict: Runtime Error):
n, k = map(int,input().split())
p = list(map(int,input().split()))

ans = 0
for i in range(n-k+1):
    e = 0
    for j in range(0,k):
        e += (0.5*(p[i+j]+1))
    ans = max(ans,e)
print(ans)
Problem p02831 (python)

Fixed submission:
import math
a ,b = map(int,input().split())

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
ans = a * b / gcd(a,b)
print(int(ans))

Buggy submission (verdict: Runtime Error):
import math
a ,b = map(int,input().split())

ans = a * b / math.gcd(a,b)
print(int(ans))
Problem p02847 (python)

Fixed submission:
s = str(input())

if s == 'SUN':
    print(7)
elif s == 'MON':
    print(6)
elif s == 'TUE':
    print(5)
elif s == 'WED':
    print(4)
elif s == 'THU':
    print(3)
elif s == 'FRI':
    print(2)
elif s == 'SAT':
    print(1)

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

if x >= 1000000000:
    print(10**9)
else:
    for n in range(1,10**9):
        l = len(str(n))
        if x <= a * n + b * l:
            ans = n - 1
            break
    print(ans)
Problem p03127 (python)

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

ans = fractions.gcd(a[0],a[1])
for i in range(2,n):
    ans = fractions.gcd(ans,a[i])
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int,input().split()))

ans = math.gcd(a[0],a[1])
for i in range(2,n):
    ans = math.gcd(ans,a[i])
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int,input().split()))

ans = math.gcd(a[0],a[1])
for i in range(2,n):
    ans = math.gcd(ans,a[i])
print(ans)
Problem p03307 (python)

Fixed submission:
n = int(input())
if n % 2 != 0:
    print(n*2)
else:
    print(n)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))

d = 0
c = []
for b in range(0,max(a)+1):
    for i in range(0,len(a)):
        d += abs(a[i]-(b+i+1))
    c.append(d)
    d = 0
print(min(c))
Problem p03775 (python)

Fixed submission:
n = int(input())
ele = []
i = 1
while i * i <= n:
    if n % i == 0:
        ele.append([len(str(i)),len(str(n // i))])
    i += 1

k = max(ele[0][1],ele[0][0])
for i in range(len(ele)):
    k = min(max(ele[i][0],ele[i][1]),k)
print(k)

Buggy submission (verdict: Runtime Error):
 n = int(input())
ele = []
i = 1
while i * i <= n:
    if n % i == 0:
        ele.append([len(str(i)),len(str(n // i))])
    i += 1

k = max(ele[0][1],ele[0][0])
for i in range(len(ele)):
    k = min(max(ele[i][0],ele[i][1]),k)
print(k)

Buggy submission (verdict: Runtime Error):
n = int(input())
ele = []
i = 1
while i * i < n:
    if n % i == 0:
        ele.append([len(str(i)),len(str(n // i))])
    i += 1

k = min(ele[0][1],ele[0][0])
for i in range(len(ele)):
    k = min(max(ele[i][0],ele[i][1]),k)
print(k)

Buggy submission (verdict: Runtime Error):
n = int(input())
ele = []
ans = []
i = 1
while i * i < n:
    if n % i == 0:
        ele.append([len(str(i)),len(str(n // i))])
        ans.append([i,n//i])
    i += 1

k = max(ele[0][1],ele[0][0])
for i in range(len(ele)):
    k = min(max(ele[i][0],ele[i][1]),k)
print(k)
Problem p02571 (python)

Fixed submission:
S = input()
T = input()

num = 10**10

for i in range(len(S)-len(T)+1):
    U = S[i:(i+len(T))]
    tmp = 0
    for j in range(len(T)):
        if(T[j] != U[j]):
            tmp += 1
    num = min(num, tmp)
    
print(num)

Buggy submission (verdict: Runtime Error):
S = input()
T = input()

num = 10**10

for i in range(len(S)-len(T)+1):
    U = S[i:(i+len(T))]
    for j in range(len(T)):
        if(T[j] != S[j]):
            tmp += 1
    num = min(num, tmp)
    
print(num)
Problem p02623 (python)

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

a = [0]
b = [0]
aa = 0
bb = 0
for i in A:
    aa += i
    a.append(aa)
for j in B:
    bb += j
    b.append(bb)

ans = 0
lb = len(b)
j = len(b)-1
for i in range(len(a)):
    if(a[i] > K):
        break
    while(a[i]+b[j] > K):
        j -= 1
    ans = max(ans, i+j)

print(ans)

Buggy submission (verdict: Runtime Error):
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0]
b = [0]
aa = 0
bb = 0
for i in A:
    aa += i
    a.append(aa)
for j in B:
    bb += j
    b.append(bb)

ans = 0
cnt = 0
lb = len(b)-1
for i in range(len(a)):
    cnt = a[i]
    if(cnt > K):
        break
    for j in reversed(range(lb)):
        tmp = cnt + b[j]
        if(tmp > K):
            lb = j
        else:
            ans = max(i+j, ans)
            break

print(ans)
Problem p02629 (python)

Fixed submission:
from collections import defaultdict

d = {1:"a", 2:"b", 3:"c", 4:"d", 5:"e", 6:"f", 7:"g", 8:"h", \
     9:"i", 10:"j", 11:"k", 12:"l", 13:"m", 14:"n", 15:"o", 16:"p", 17:"q", \
      18:"r", 19:"s", 20:"t", 21:"u", 22:"v", 23:"w", 24:"x", 25:"y", 0:"z"}

N = int(input())
n = N
ans = ""

while n > 0:
    x = n%26
    ans += d[x]
    if(x == 0):
        n = n//26-1
    else:
        n //= 26

print(ans[::-1])

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

N = int(input())
d = {1:"a", 2:"b", 3:"c", 4:"d", 5:"e", 6:"f", 7:"g", 8:"h", \
     9:"i", 10:"j", 11:"k", 12:"l", 13:"m", 14:"n", 15:"o", 16:"p", 17:"q", \
      18:"r", 19:"s", 20:"t", 21:"u", 22:"v", 23:"w", 24:"x", 25:"y", 26:"z"}

def Base_10_to_n(X, n):
    if(int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)+","
    return str(X%n)+","

a = Base_10_to_n(N, 26)
a = list(a.split(","))
ans = ""

for i in a:
    if(i == ""):
        continue
    ans += d[int(i)]        
print(ans)
Problem p03208 (python)

Fixed submission:
def main():
    N, K = map(int, input().split())
    h = [0]*N
    for i in range(N):
        h[i] = int(input())
    h.sort()
    
    ans = 10**10
    for i in range(N-K+1):
        ans = min(ans, h[i+K-1]-h[i])
    print(ans)
main()

Buggy submission (verdict: Runtime Error):
def main():
    N, K = map(int, input().split())
    h = [0]*N
    for i in range(N):
        h[i] = int(input())
    hh = sorted(h)

    for i in range(1, N-K+1):
        ans = min(ans, max(hh[i:i+K])-min(hh[i:i+K]))
    print(ans)
    
main()