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

def main():
	N, M = map(int, input().split())

	base = math.floor(M / N)
	while (M - (base * N)) % base != 0:
		base -= 1
	print(base)

main()


Fixed submission:
import math

def get_divs(a):
	divs = [1, a]
	for n in range(2, int(a ** 0.5)):
		if a % n == 0:
			divs.append(n)
			divs.append(a // n)
	return divs

def main():
	N, M = map(int, input().split())

	divs = get_divs(M)
	divs.sort()
	divs.reverse()
	divs = filter(lambda x:x <= M // N, divs)

	for div in divs:
		if (M - N * div) % div == 0:
			print(div)
			break

main()

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

base = M // N
while (M - (base * N)) % base != 0:
	base -= 1
print(base)


Fixed submission:
import math

def get_divs(a):
	divs = [1, a]
	for n in range(2, int(a ** 0.5)):
		if a % n == 0:
			divs.append(n)
			divs.append(a // n)
	return divs

def main():
	N, M = map(int, input().split())

	divs = get_divs(M)
	divs.sort()
	divs.reverse()
	divs = filter(lambda x:x <= M // N, divs)

	for div in divs:
		if (M - N * div) % div == 0:
			print(div)
			break

main()
Buggy python submission (verdict: Runtime Error):
import re

S = input()
K = int(input()[:4])

n1i = re.search("[2-9]", S).start()

print(S[min(n1i, K - 1)])


Fixed submission:
import re

S = input()
K = int(input())

n1 = re.search("[2-9]", S)
if not n1:
	print("1")
	exit()

n1i = n1.start()
print(S[min(n1i, K - 1)])

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

S = input()
K = int(input())

n1i = re.search("[2-9]", S).start()

print(S[min(n1i, K)])


Fixed submission:
import re

S = input()
K = int(input())

n1 = re.search("[2-9]", S)
if not n1:
	print("1")
	exit()

n1i = n1.start()
print(S[min(n1i, K - 1)])

Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())

c = 0
for s in S:
	if "1" == s:
		c += 1
	else:
		break

print(["1", S[c]][not((K - 1) < c)])


Fixed submission:
import re

S = input()
K = int(input())

n1 = re.search("[2-9]", S)
if not n1:
	print("1")
	exit()

n1i = n1.start()
print(S[min(n1i, K - 1)])
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
print([0, 1][N % K])


Fixed submission:
N, K = map(int, input().split())
print([0, 1][0<N % K])
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
K = int(input())

a = []
for l in range(1, len(S) + 1):
	for i in range(len(S) - l + 1):
		a += [S[i:i + l]]

print(sorted(set(a))[K - 1])


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

a = []
for i in range(len(S)):
	for l in range(1, len(S) - i + 1):
		s = S[i:i + l]
		#print(s, a)
		if s in a:
			continue
		if len(a) < 5:
			a += [s]
			a = sorted(a)
		else:
			if a[-1] < s:
				break
			else:
				a[-1] = s
				a = sorted(a)
print(a[K - 1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = list(map(int, input().split()))

c = N // 2
x = sorted(X)
for v in X:
	if x.index(v) < c:
		print(x[c])
	else:
		print(x[c - 1])


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

c = N // 2
x = sorted(X)
for v in X:
	if v < x[c]:
		print(x[c])
	else:
		print(x[c - 1])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = list(map(int, input().split()))

x = sorted(X)
for v in X:
	i = x.index(v)
	x.pop(i)
	print(x[(N - 1) // 2])
	x.insert(i, v)


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

c = N // 2
x = sorted(X)
for v in X:
	if v < x[c]:
		print(x[c])
	else:
		print(x[c - 1])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = list(map(int, input().split()))

for n in range(N):
	x = X.copy()
	x.pop(n)
	#print(sorted(x))
	print(sorted(x)[(N - 1) // 2])


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

c = N // 2
x = sorted(X)
for v in X:
	if v < x[c]:
		print(x[c])
	else:
		print(x[c - 1])
Buggy python submission (verdict: Time Limit Exceeded):
H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for _ in range(Q)]

numbers = {}
for y in range(H):
	for x in range(W):
		numbers[A[y][x]] = (y, x)

for l, r in LR:
	cost = 0
	while l != r:
		f, t = numbers[l], numbers[l + D]
		cost += abs(f[0] - t[0]) + abs(f[1] - t[1])
		l += D
	print(cost)


Fixed submission:
H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for _ in range(Q)]

numbers = {}
for y in range(H):
	for x in range(W):
		numbers[A[y][x]] = (y, x)

numbers_sum = [0] * (H * W + 1)
for n in range(D + 1, H * W + 1):
	f, t = numbers[n], numbers[n - D]
	cost = abs(f[0] - t[0]) + abs(f[1] - t[1])
	numbers_sum[n] = numbers_sum[n - D] + cost

for l, r in LR:
	print(numbers_sum[r] - numbers_sum[l])

Buggy python submission (verdict: Time Limit Exceeded):
H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for _ in range(Q)]

numbers = {}
for y in range(H):
	for x in range(W):
		numbers[A[y][x]] = (y, x)

for l, r in LR:
	cost = 0
	while l != r:
		f, t = numbers[l], numbers[l + D]
		cost += abs(f[0] - t[0]) + abs(f[1] - t[1])
		l += D
	print(cost)


Fixed submission:
H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for _ in range(Q)]

numbers = {}
for y in range(H):
	for x in range(W):
		numbers[A[y][x]] = (y, x)

numbers_sum = [0] * (H * W + 1)
for n in range(D + 1, H * W + 1):
	f, t = numbers[n], numbers[n - D]
	cost = abs(f[0] - t[0]) + abs(f[1] - t[1])
	numbers_sum[n] = numbers_sum[n - D] + cost

for l, r in LR:
	print(numbers_sum[r] - numbers_sum[l])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100000)

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

graph = [{} for _ in range(N)]
for l, r, d in LRD:
	l, r = l - 1, r - 1
	graph[l][r] = d
	graph[r][l] = -d

visited = [False] * N
def dfs(v, p, d, depths):
	if visited[v]:
		return True
	visited[v] = True

	if depths[v] != -1:
		return True
	depths[v] = d

	for n in graph[v]:
		if n == p:
			continue
		n_depth = d + graph[v][n]
		if depths[n] != -1 and depths[n] != n_depth:
			return False
		result = dfs(n, v, n_depth, depths)
		if not result:
			return False
	return True

for n in range(N):
	if not dfs(n, -1, 0, [-1] * N):
		print("No")
		break
else:
	print("Yes")


Fixed submission:
import sys
sys.setrecursionlimit(100000)

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

graph = [{} for _ in range(N)]
for l, r, d in LRD:
	l, r = l - 1, r - 1
	graph[l][r] = d
	graph[r][l] = -d

visited = [False] * N
depths = [-1] * N
def dfs(v, p, d):
	if visited[v]:
		return True
	visited[v] = True
	depths[v] = d

	for n in graph[v]:
		if n == p:
			continue
		n_depth = d + graph[v][n]
		if depths[n] != -1 and depths[n] != n_depth:
			return False
		result = dfs(n, v, n_depth)
		if not result:
			return False
	return True

for n in range(N):
	if not dfs(n, -1, 0):
		print("No")
		break
else:
	print("Yes")

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

graph = [{} for _ in range(N)]
for l, r, d in LRD:
	l, r = l - 1, r - 1
	graph[l][r] = d
	graph[r][l] = -d

def dfs(v, p, d, depths):
	if depths[v] != -1:
		return True
	depths[v] = d

	for n in graph[v]:
		if n == p:
			continue
		n_depth = d + graph[v][n]
		if depths[n] != -1 and depths[n] != n_depth:
			return False
		result = dfs(n, v, n_depth, depths)
		if not result:
			return False
	return True

for n in range(N):
	if not dfs(n, -1, 0, [-1] * N):
		print("No")
		break
else:
	print("Yes")


Fixed submission:
import sys
sys.setrecursionlimit(100000)

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

graph = [{} for _ in range(N)]
for l, r, d in LRD:
	l, r = l - 1, r - 1
	graph[l][r] = d
	graph[r][l] = -d

visited = [False] * N
depths = [-1] * N
def dfs(v, p, d):
	if visited[v]:
		return True
	visited[v] = True
	depths[v] = d

	for n in graph[v]:
		if n == p:
			continue
		n_depth = d + graph[v][n]
		if depths[n] != -1 and depths[n] != n_depth:
			return False
		result = dfs(n, v, n_depth)
		if not result:
			return False
	return True

for n in range(N):
	if not dfs(n, -1, 0):
		print("No")
		break
else:
	print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A, B, C = [list(map(int, input().split())) for _ in range(3)]

for x in [A, B, C]:
	x.sort()

def bsr(a, v, lo=0, hi=None):
	if hi == None:
		hi = len(a) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		if v < a[mid]:
			hi = mid - 1
		else:
			lo = mid + 1
	return lo

bt = []
for b in B:
	bt += [max(0, (N - bsr(C, b)))]

r = 0
for ai, a in enumerate(A):
	bif = bsr(B, a)
	if bif < N:
		r += sum(bt[bif:])

print(r)


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

for x in [A, B, C]:
	x.sort()

def bsr(a, v, lo=0, hi=None):
	if hi == None:
		hi = len(a) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		if v < a[mid]:
			hi = mid - 1
		else:
			lo = mid + 1
	return lo

bt = []
for b in B:
	bt += [max(0, (N - bsr(C, b)))]

for i in range(len(B) - 2, -1, -1):
	bt[i] += bt[i + 1]

r = 0
for ai, a in enumerate(A):
	bif = bsr(B, a)
	if bif < N:
		r += bt[bif]

print(r)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A, B, C = [list(map(int, input().split())) for _ in range(3)]

for x in [A, B, C]:
	x.sort()

def bsr(a, v, lo=0, hi=None):
	if hi == None:
		hi = len(a) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		if v < a[mid]:
			hi = mid - 1
		else:
			lo = mid + 1
	return lo

r = 0
for ai, a in enumerate(A):
	bif = bsr(B, a)
	if bif < N:
		for b in B[bif:]:
			ci = bsr(C, b)
			if ci < N:
				r += (N - ci)
			else:
				break
	else:
		break
print(r)


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

for x in [A, B, C]:
	x.sort()

def bsr(a, v, lo=0, hi=None):
	if hi == None:
		hi = len(a) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		if v < a[mid]:
			hi = mid - 1
		else:
			lo = mid + 1
	return lo

bt = []
for b in B:
	bt += [max(0, (N - bsr(C, b)))]

for i in range(len(B) - 2, -1, -1):
	bt[i] += bt[i + 1]

r = 0
for ai, a in enumerate(A):
	bif = bsr(B, a)
	if bif < N:
		r += bt[bif]

print(r)
Buggy python submission (verdict: Runtime Error):
S = list(input())[::-1]
T = list(input())[::-1]

i, c = 0, False

while True:
	f = False
	for j, t in enumerate(T):
		if t == S[i + j]:
			f = True
			continue
		if "?" == S[i + j]:
			continue
		break
	else:
		if f:
			S[i:i + len(T)] = T
			i += len(T) - 1
			c = True
			#print(S)
	i += 1
	if (len(S) - len(T)) <= i:
		break

if c:
	print("".join(S[::-1]).replace("?", "a"))
else:
	print("UNRESTORABLE")


Fixed submission:
S = list(input())[::-1]
T = list(input())[::-1]

for n in range(0, len(S) - len(T) + 1):
	for i, t in enumerate(T):
		if "?" == S[n + i]:
			continue
		if t != S[n + i]:
			break
	else:
		S[n:n + len(T)] = T
		print("".join(S[::-1]).replace("?", "a"))
		break
else:
	print("UNRESTORABLE")
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

N, M, R = map(int, input().split())
r = list(map(int, input().split()))
ABC = [list(map(int, input().split())) for _ in range(M)]

# 距離表の初期化
INF = 100# ** 12
dist = [[INF] * N for _ in range(N)]
for i in range(N):
	dist[i][i] = 0

# グラフを読み込みつつ距離表の更新
for a, b, c in ABC:
	a, b = a - 1, b - 1
	dist[a][b] = c
	dist[b][a] = c

# ワーシャル–フロイド法の前処理
for k in range(N):
	for i in range(N):
		for j in range(N):
			dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

#print(dist)

# 全探索(*^_^*)つ[rCr]
min_dist = INF
for p in itertools.permutations(r):
	d = 0
	for n in range(1, R):
		d += dist[p[n] - 1][p[n - 1] - 1]
	if d < min_dist:
		min_dist = d
		#print(d, p)
print(min_dist)


Fixed submission:
import itertools

N, M, R = map(int, input().split())
r = list(map(int, input().split()))
ABC = [list(map(int, input().split())) for _ in range(M)]

# 距離表の初期化
INF = 10 ** 12
dist = [[INF] * N for _ in range(N)]
for i in range(N):
	dist[i][i] = 0

# グラフを読み込みつつ距離表の更新
for a, b, c in ABC:
	a, b = a - 1, b - 1
	dist[a][b] = c
	dist[b][a] = c

# ワーシャル–フロイド法の前処理
for k in range(N):
	for i in range(N):
		for j in range(N):
			dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

#print(dist)

# 全探索(*^_^*)つ[rCr]
min_dist = INF
for p in itertools.permutations(r):
	d = 0
	for n in range(1, R):
		d += dist[p[n] - 1][p[n - 1] - 1]
	if d < min_dist:
		min_dist = d
		#print(d, p)
print(min_dist)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

m = {}
for a in sorted(set(A)):
	m[a] = A.count(a)

r = 0
for n in m:
	t = m[n]
	if n + 1 in m:
		t += m[n + 1]
	if n + 2 in m:
		t += m[n + 2]
	r = max(r, t)

print(r)


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

m = {}
for a in A:
	if a not in m:
		m[a] = 1
	else:
		m[a] += 1

r = 0
for n in m:
	t = m[n]
	if n + 1 in m:
		t += m[n + 1]
	if n + 2 in m:
		t += m[n + 2]
	r = max(r, t)

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

pnmax = {}

def pn(A):
	a = A
	for n in range(2, A + 1):
		if a == 1:
			return
		c = 0
		while not a % n:
			c += 1
			a //= n
		if 0 < c:
			if not n in pnmax:
				pnmax[n] = c
			else:
				pnmax[n] = max(pnmax[n], c)

for t in T:
	pn(t)

r = 1
for k, v in pnmax.items():
	r *= k ** v

#print(pnmax)
print(r)


Fixed submission:
N = int(input())
T = [int(input()) for _ in range(N)]

def gcd(a, b):
	if not a % b:
		return b
	else:
		return gcd(b, a % b)

l = T[0]
for n in range(1, N):
	l = l * T[n] // gcd(l, T[n])

print(l)

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

ssum = {}
def func(a):
	global ssum
	s = {}
	for i in range(2, a + 1):
		while not a % i:
			if i not in s:
				s[i] = 1
			else:
				s[i] += 1
			a //= i
		if 1 == a:
			break
	for t in s:
		if t not in ssum:
			ssum[t] = s[t]
		else:
			ssum[t] = max(ssum[t], s[t])

for t in T:
	func(t)

r = 1
for t in ssum:
	r *= t ** ssum[t]

print(r)


Fixed submission:
N = int(input())
T = [int(input()) for _ in range(N)]

def gcd(a, b):
	if not a % b:
		return b
	else:
		return gcd(b, a % b)

l = T[0]
for n in range(1, N):
	l = l * T[n] // gcd(l, T[n])

print(l)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

b = []
for i, a in enumerate(A):
	if not i % 2:
		b.append(a)
	else:
		b.insert(0, a)

if not len(A) % 2:
	print(*b)
else:
	print(*b[::-1])


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
"""
b = []
for i, a in enumerate(A):
	if not i % 2:
		b.append(a)
	else:	
		b.insert(0, a)

if not len(A) % 2:
	print(*b)
else:
	print(*b[::-1])
"""
print(*(A[::-2] + A[len(A) % 2::2]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]

pnext = 1
pvisited = []
while True:
	pvisited.append(pnext)
	pnext = A[pnext - 1]
	if pnext == 2:
		print(len(pvisited))
		exit()
	if pnext in pvisited:
		print(-1)
		exit()


Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]

count = 0
pnext = 1
while count < N:
	count += 1
	pnext = A[pnext - 1]
	if pnext == 2:
		print(count)
		break
else:
	print(-1)

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

pnext = 0
pvisited = []
while True:
	pvisited.append(pnext)
	pnext = A[pnext] - 1
	if pnext == 1:
		print(len(pvisited))
		exit()
	if pnext in pvisited:
		print(-1)
		exit()


Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]

count = 0
pnext = 1
while count < N:
	count += 1
	pnext = A[pnext - 1]
	if pnext == 2:
		print(count)
		break
else:
	print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
def func(a, b):
	return max(map(len, map(str, [a, b])))

N = int(input())

min_dig = 10 ** 18
for i in range(1, N + 1):
	if not N % i:
		j = N // i
		if j < i:
			break
		min_dig = min(min_dig, func(i, j))

print(min_dig)


Fixed submission:
def func(a, b):
	return max(map(len, map(str, [a, b])))

N = int(input())

min_dig = 10 ** 18
for i in range(1, int(N ** 0.5) + 1):
	if not N % i:
		j = N // i
		min_dig = min(min_dig, func(i, j))

print(min_dig)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1_000_000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]

# データ構造：ヒープ
import heapq
class heapque:
    def __init__(self, *args):
        self.que = []
        for arg in args:
            self.push(arg)
    def push(self, v):
        heapq.heappush(self.que, v)
    def pop(self):
        return heapq.heappop(self.que)

from collections import Counter

# エントリーポイント
def main():
    N = input(int)
    A = input([int, N])

    cnt = Counter(A).values()
    # 3以上の奇数を相殺させ1へ
    cnt = [1 if c % 2 else c for c in cnt]
    # 偶数を相殺させ2へ
    cnt = [2 if c % 2 == 0 else c for c in cnt]

    print(len(cnt) - cnt.count(2) % 2)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Fixed submission:
import sys
sys.setrecursionlimit(1000000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]

# データ構造：ヒープ
import heapq
class heapque:
    def __init__(self, *args):
        self.que = []
        for arg in args:
            self.push(arg)
    def push(self, v):
        heapq.heappush(self.que, v)
    def pop(self):
        return heapq.heappop(self.que)

from collections import Counter

# エントリーポイント
def main():
    N = input(int)
    A = input([int, N])

    cnt = Counter(A).values()
    # 3以上の奇数を相殺させ1へ
    cnt = [1 if c % 2 else c for c in cnt]
    # 偶数を相殺させ2へ
    cnt = [2 if c % 2 == 0 else c for c in cnt]

    print(len(cnt) - cnt.count(2) % 2)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
def main():
	c = 0
	k, s = map(int, input().split())
	#k, s = map(int, "2 2".split())
	for x in range(k + 1):
		for y in range(k + 1):
			for z in range(k + 1):
				if s == x + y + z:
					c += 1
	print(c)
	return

if __name__ == '__main__':
	main()


Fixed submission:
K, S = map(int, input().split())
c = 0
for X in range(K + 1):
	for Y in range(K + 1):
		if S - K <= X + Y <= S:
			c += 1
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
def main():
	c = 0
	k, s = map(int, input().split())
	#k, s = map(int, "2 2".split())
	for x in range(k + 1):
		for y in range(k + 1):
			for z in range(k + 1):
				if s == x + y + z:
					c += 1
	print(c)
	return

if __name__ == '__main__':
	main()


Fixed submission:
K, S = map(int, input().split())
c = 0
for X in range(K + 1):
	for Y in range(K + 1):
		if S - K <= X + Y <= S:
			c += 1
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
*A, = map(int, input().split())

if not(N % 2):
	for i in range(1, N, 2):
		if A.count(i) != 2:
			print(0)
			exit()
else:
	if A.count(0) != 1:
		print(0)
		exit()
	for i in range(2, N, 2):
		if A.count(i) != 2:
			print(0)
			exit()

mod = 10**9+7
print(2**(N//2) % mod)


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

count = dict()
if N % 2:
	for a in A:
		if a % 2:
			print(0)
			exit()
		if a in count:
			count[a] += 1
		else:
			count[a] = 1
	if count[0] != 1:
		print(0)
		exit()
	del count[0]
	for c in count.values():
		if c != 2:
			print(0)
			exit()
else:
	for a in A:
		if not(a % 2):
			print(0)
			exit()
		if a in count:
			count[a] += 1
		else:
			count[a] = 1
	for c in count.values():
		if c != 2:
			print(0)
			exit()

mod = 10**9+7
print(2**(N//2) % mod)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

sum = 0
for i in range(N):
    for j in range(i + 1, N):
        sum += A[i] * A[j]

print(sum % 1000000007)

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

mod = 1000000007

S = [0]
for i in range(N):
    S.append((S[-1] + A[i]))

ans = 0
for i in range(N):
    sum = (S[N] - S[i + 1]) % mod
    ans += (A[i] * sum)
    ans %= mod

print(ans % mod)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)

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

# 足場 i から 足場 N - 1 まで移動するときのコストの最小値
def rec(i):
    if i == N - 1:
        return 0
    elif i == N - 2:
        return rec(i + 1) + abs(h[i + 1] - h[i])
    else:
        return min(rec(i + 1) + abs(h[i + 1] - h[i]), rec(i + 2) + abs(h[i + 2] - h[i]))

print(rec(0))

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

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

dp = [-1] * N # dp[i] := i から N-1 までの移動にかかる最小コスト
dp[N-1] = 0

def rec_memo(i):
    if dp[i] >= 0:
        return dp[i]
    
    if i == N-2:
        dp[i] = rec_memo(i+1) + abs(h[i+1] - h[i])
        return dp[i]
    else:
        dp[i] = min(rec_memo(i+1) + abs(h[i+1] - h[i]), rec_memo(i+2) + abs(h[i+2] - h[i]))
        return dp[i]

print(rec_memo(0))

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

dp = [-1] * N  # dp[i] := i+1 から N までの移動にかかる最小コスト
dp[N-1] = 0

def rec_memo(i):
    if dp[i] >= 0:
        return dp[i]
    
    if i == N-2:
        dp[i] = rec_memo(i+1) + abs(h[i+1] - h[i])
        return dp[i]
    else:
        dp[i] = min(rec_memo(i+1) + abs(h[i+1] - h[i]), rec_memo(i+2) + abs(h[i+2] - h[i]))
        return dp[i]

print(rec_memo(0))

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

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

dp = [-1] * N # dp[i] := i から N-1 までの移動にかかる最小コスト
dp[N-1] = 0

def rec_memo(i):
    if dp[i] >= 0:
        return dp[i]
    
    if i == N-2:
        dp[i] = rec_memo(i+1) + abs(h[i+1] - h[i])
        return dp[i]
    else:
        dp[i] = min(rec_memo(i+1) + abs(h[i+1] - h[i]), rec_memo(i+2) + abs(h[i+2] - h[i]))
        return dp[i]

print(rec_memo(0))
Buggy python submission (verdict: Runtime Error):
val = input()
valf=val[-1]
if(valf==s):
    print(val+"es")
else
    print(val+"s")

Fixed submission:
val = input()
valf=val[-1]
if(valf=="s"):
    print(val+"es")
else:
    print(val+"s")
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())

a = int(A)
b = B

print(int(a * b))

Fixed submission:
A, B = map(float, input().split())

a = int(A)
b = round(B * 100)

print(a * b // 100)