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

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


def dfs(v, p, dist):
    for u, w in tree[v]:
        if u == p:
            continue
        else:
            dist[u] = dist[v] + w
            dfs(u, v, dist)


n = int(input())
tree = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    tree[u - 1].append((v - 1, w))
    tree[v - 1].append((u - 1, w))

dist = [0 for _ in range(n)]
dfs(0, -1, dist)

for i in dist:
    if i % 2 == 0:
        print(0)
    else:
        print(1)

Buggy submission (verdict: Runtime Error):
def dfs(v, p, c):
    for u, w in tree[v]:
        res[v] = c
        if u == p:
            continue
        else:
            if w % 2 == 0:
                dfs(u, v, c)
            else:
                dfs(u, v, c + 1)


n = int(input())
tree = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    tree[u - 1].append([v - 1, w])
    tree[v - 1].append([u - 1, w])

res = [0 for _ in range(n)]
dfs(0, -1, 0)

for i in res:
    print(i)

Buggy submission (verdict: Runtime Error):
def dfs(v, p, dist):
    for u, w in tree[v]:
        if u == p:
            continue
        else:
            dist[u] = dist[v] + w
            dfs(u, v, dist)


n = int(input())
tree = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    tree[u - 1].append((v - 1, w))
    tree[v - 1].append((u - 1, w))

dist = [0 for _ in range(n)]
dfs(0, 0, dist)

for i in dist:
    if i % 2 == 0:
        print(0)
    else:
        print(1)
Problem p03089 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    B = list(map(int, input().split()))

    res = []
    for i in range(n):
        L = len(B)
        for j in reversed(range(L)):
            if j + 1 == B[j]:
                res.append(B[j])
                B.pop(j)
                break
        else:
            print(-1)
            exit()

    res = res[::-1]
    for i in res:
        print(i)


if __name__ == '__main__':
    resolve()

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

if B[0] != 1:
	print(-1)
	exit()

cnt = 1
for i in range(1, n):
	if B[i] == 1:
		cnt = 1
	
	if B[i] - 1 <= cnt:
		cnt += 1
	else:
		print(-1)
		exit()

res = []
end = n
for i in reversed(range(n)):
	if B[i] == 1:
		A = B[i + 1 : end]
		res.append(1)
		L = []
		for j in range(len(A)):
			if j + 2 != A[j]:
				L.append(A[j])
				A.pop(j)
			
		L.sort()
		for l in L:
			res.append(l)
		
		for a in A:
			res.append(a)
			
		end = i

for i in res:
	print(i)
Problem p03096 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    C = list(int(input()) for _ in range(n))
    MAX_C = max(C)

    dp = [0] * (n + 1)
    dp[0] = 1
    dp2 = [-1] * (MAX_C + 1)
    for i in range(n):
        c = C[i]
        if dp2[c] >= 0 and dp2[c] < i - 1:
            dp[i + 1] = dp[i] + dp[dp2[c] + 1]
        else:
            dp[i + 1] = dp[i]
        dp[i + 1] %= mod
        dp2[c] = i

    print(dp[-1] % mod)


if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    C = list(int(input()) for _ in range(n))

    dp = [0] * (n + 1)
    dp[0] = 1
    dp2 = [-1] * (n + 1)
    for i in range(n):
        c = C[i]
        if dp2[c] >= 0 and dp2[c] < i - 1:
            dp[i + 1] = dp[i] + dp[dp2[c] + 1]
        else:
            dp[i + 1] = dp[i]
        dp2[c] = i

    print(dp[-1])


if __name__ == '__main__':
    resolve()
Problem p03112 (python)

Fixed submission:
import sys
from bisect import bisect_left

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    a, b, q = map(int, input().split())
    S = [-f_inf] + list(int(input()) for _ in range(a)) + [f_inf]
    T = [-f_inf] + list(int(input()) for _ in range(b)) + [f_inf]

    for _ in range(q):
        res = f_inf
        x = int(input())

        idx_s = bisect_left(S, x)
        idx_t = bisect_left(T, x)
        for s in [S[idx_s - 1], S[idx_s]]:
            for t in [T[idx_t - 1], T[idx_t]]:
                d1 = abs(s - x) + abs(s - t)
                d2 = abs(t - x) + abs(t - s)
                res = min(res, d1, d2)
        print(res)


if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
import sys
from bisect import bisect_left

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    a, b, q = map(int, input().split())
    S = list(int(input()) for _ in range(a))
    T = list(int(input()) for _ in range(b))

    for _ in range(q):
        x = int(input())
        idx_s = bisect_left(S, x)

        kouho_s = []
        if idx_s != 0:
            kouho_s.append(idx_s - 1)
        if idx_s != a:
            kouho_s.append(idx_s)

        res = f_inf
        for idx_s in kouho_s:
            dist = abs(x - S[idx_s])
            now = S[idx_s]
            idx_t = bisect_left(T, now)
            kouho_t = []
            if idx_t != 0:
                kouho_t.append(idx_t - 1)
            if idx_t != b:
                kouho_t.append(idx_t)
            for idx_t in kouho_t:
                dist += abs(now - T[idx_t])
                res = min(res, dist)

        kouho_t = []
        if idx_t != 0:
            kouho_t.append(idx_t - 1)
        if idx_t != b:
            kouho_t.append(idx_t)

        for idx_t in kouho_t:
            dist = abs(x - T[idx_t])
            now = T[idx_t]
            idx_s = bisect_left(S, now)
            kouho_s = []
            if idx_s != 0:
                kouho_s.append(idx_s - 1)
            if idx_s != b:
                kouho_s.append(idx_s)
            for idx_s in kouho_s:
                dist += abs(now - S[idx_t])
                res = min(res, dist)
        print(res)


if __name__ == '__main__':
    resolve()
Problem p03128 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))

    L = [(1, 2), (2, 5), (3, 5), (4, 4), (5, 5), (6, 6), (7, 3), (8, 7), (9, 6)]
    B = []
    for num, cost in L:
        if num in A:
            B.append([num, cost])
    B.sort(key=lambda x: -x[0])
    dp = [-f_inf] * (n + 1)
    dp[0] = 0
    for i in range(n + 1):
        for _, cost in B:
            if i - cost == 0:
                dp[i] = max(dp[i], dp[0] + 1)
            elif i - cost > 0 and dp[i - cost] != 0:
                dp[i] = max(dp[i], dp[i - cost] + 1)
    j = 0
    k = n
    res = ""
    while k > 0 and j < m:
        num, cost = B[j]
        if k - cost >= 0 and dp[k] - dp[k - cost] == 1:
            res += str(num)
            k -= cost
        else:
            j += 1
    print(res)


if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))

    L = [(1, 2), (2, 5), (3, 5), (4, 4), (5, 5), (6, 6), (7, 3), (8, 7), (9, 6)]
    B = []
    for num, cost in L:
        if num in A:
            B.append([num, cost])
    B.sort(key=lambda x: -x[0])
    dp = [-f_inf] * (n + 1)
    dp[0] = 0
    for i in range(n + 1):
        for _, cost in B:
            if i - cost == 0:
                dp[i] = max(dp[i], dp[0] + 1)
            elif dp[i - cost] != 0:
                dp[i] = max(dp[i], dp[i - cost] + 1)
    j = 0
    k = n
    res = ""
    while k > 0 and j < n:
        num, cost = B[j]
        if k - cost >= 0 and dp[k] - dp[k - cost] == 1:
            res += str(num)
            k -= cost
        else:
            j += 1
    print(res)


if __name__ == '__main__':
    resolve()
Problem p03148 (python)

Fixed submission:
import sys
from collections import deque
from heapq import heappop, heappush

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    TD = [list(map(int, input().split())) for _ in range(n)]
    TD.sort(key=lambda z: -z[1])
    TD_new = [[] for _ in range(n)]
    for t, d in TD:
        TD_new[t - 1].append([d, 0] if len(TD_new[t - 1]) else [d, 1])

    ALL = []
    for td in TD_new:
        ALL.extend(td)
    ALL.sort(reverse=True)
    que = deque(ALL)

    x = y = 0
    zero = []
    for _ in range(k):
        d, ex = que.popleft()
        x += d
        y += ex
        if ex == 0:
            heappush(zero, d)

    res = x + y ** 2
    while que:
        d, ex = que.popleft()
        if ex:
            if zero:
                x += d - heappop(zero)
                y += 1
                res = max(res, x + y ** 2)
            else:
                break

    print(res)


if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
from heapq import heappop, heappush

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    LD = [[] for _ in range(n)]
    for _ in range(n):
        t, d = map(int, input().split())
        LD[t - 1].append([d, 0] if len(LD[t - 1]) else [d, 1])

    ALL = []
    for ld in LD:
        ALL.extend(ld)
    ALL.sort(reverse=True)
    que = deque(ALL)

    x = y = 0
    zero, one = [], []
    for _ in range(k):
        d, ex = que.popleft()
        x += d
        y += ex
        heappush(zero, d) if ex == 0 else heappush(one, d)

    res = x + y ** 2
    while que:
        d, ex = que.popleft()
        if ex:
            if zero:
                x += d - heappop(zero)
                y += 1
                res = max(res, x + y ** 2)
            else:
                x += d - heappop(one)
                res = max(res, x + y ** 2)
    print(res)


if __name__ == '__main__':
    resolve()
Problem p03150 (python)

Fixed submission:
s = list(input())
n = len(s)

if "".join(s) == "keyence":
	print("YES")
	exit()

for i in range(n):
	ss = s[::]
	for j in range(i, n):
		ss.pop(i)
		if "".join(ss) == "keyence":
			print("YES")
			break
	else:
		continue
	break
else:
	print("NO")

Buggy submission (verdict: Runtime Error):
s = list(input())
n = len(s)

if "".join(s) == "keyence":
	print("YES")
	eixt()

for i in range(n):
	ss = s[::]
	for j in range(i, n):
		ss.pop(i)
		print("".join(ss))
		if "".join(ss) == "keyence":
			print("YES")
			break
	else:
		continue
	break
else:
	print("NO")
Problem p03161 (python)

Fixed submission:
import numpy as np
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
h = [int(i) for i in input().split()]

f_inf = float('inf')
dp = np.zeros(n, dtype=int)
h = np.array(h)
for i in range(1, n):
    start = max(0, i - k)
    dp[i] = min(dp[start: i] + np.abs(h[i] - h[start: i]))

print(dp[n-1])

Buggy submission (verdict: Runtime Error):
in, k = map(int, input().split())
h = [int(i) for i in input().split()]
def chmin(a, b):
    if a > b:
        return b
    else:
        return a
f_inf = float('inf')
dp = [f_inf] * (10**5+10)
dp[0] = 0
for i in range(1, n):
    for j in range(1, k+1):
        if i - j >= 0:
            dp[i] = chmin(dp[i], dp[i-j]+ abs(h[i] - h[i - j]))
print(dp[n-1])
Problem p03229 (python)

Fixed submission:
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = sorted(list(int(input()) for _ in range(n)))
    B = deque([])
    for i in range(n // 2):
        if i % 2 == 0:
            B.appendleft(A[i])
            B.append(A[-(i + 1)])
        else:
            B.append(A[i])
            B.appendleft(A[-(i + 1)])

    if n % 2 != 0:
        if abs(B[0] - A[n // 2]) < abs(B[-1] - A[n // 2]):
            B.append(A[n // 2])
        else:
            B.appendleft(A[n // 2])

    res = 0
    for i in range(1, n):
        res += abs(B[i] - B[i - 1])

    print(res)

if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = sorted(list(int(input()) for _ in range(n)))
    A = deque(A)
    B = deque([])

    for i in range(n):
        if i == 0:
            mi = A.popleft()
            B.append(mi)
        elif i == 1:
            ma = A.pop()
            B.append(ma)
        else:

            diff_left_mi = ["A.popleft()", "B.appendleft(A[0])", abs(B[0] - A[0])]
            diff_right_mi = ["A.popleft()", "B.append(A[0])", abs(B[-1] - A[0])]

            diff_left_ma = ["A.pop()", "B.appendleft(A[-1])", abs(B[0] - A[-1])]
            diff_right_ma = ["A.pop()", "B.append(A[-1])", abs(B[-1] - A[-1])]

            L = [diff_left_mi, diff_right_mi, diff_left_ma, diff_right_ma]
            ma = 0
            for l in L:
                if ma < l[2]:
                    op1 = l[0]
                    op2 = l[1]
                    ma = l[2]
            eval(op2)
            eval(op1)

    res = 0
    for i in range(1, n):
        res += abs(B[i] - B[i - 1])

    print(res)


if __name__ == '__main__':
    resolve()
Problem p03231 (python)

Fixed submission:
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def resolve():
    n, m = map(int, input().split())
    s = input()
    t = input()

    L = lcm(n, m)

    X = dict()
    for i in range(n):
        idx = (L // n) * i
        X[idx] = s[i]

    for i in range(m):
        idx = (L // m) * i
        if X.get(idx) != None and X[idx] != t[i]:
            print("-1")
            break
    else:
        print(L)


if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def resolve():
    n, m = map(int, input().split())
    s = input()
    t = input()

    L = lcm(n, m)

    X = [""] * L
    for i in range(n):
        idx = (L // n) * i
        X[idx] = s[i]

    for i in range(m):
        idx = (L // m) * i
        if X[idx] != "" and X[idx] != t[i]:
            print("-1")
            break
    else:
        print(L)


if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def resolve():
    n, m = map(int, input().split())
    s = input()
    t = input()

    L = lcm(n, m)
    X = [""] * L
    for i in range(n):
        idx = i * L // n
        X[idx] = s[i]

    for i in range(m):
        idx = i * L // m
        if X[idx] != "" and X[idx] != t[i]:
            print("-1")
            break
    else:
        print(L)


if __name__ == '__main__':
    resolve()
Problem p03393 (python)

Fixed submission:
def main():
    s = input()
    alphabet = "".join([chr(i) for i in range(97, 97 + 26)])
    if len(s) < 26:
        for i in alphabet:
            if i not in s:
                print(s + i)
                exit()
    else:
        if s == "zyxwvutsrqponmlkjihgfedcba":
            print(-1)
        else:
            for i in reversed(range(26)):
                for j in reversed(range(i + 1, 26)):
                    if s[i] < s[j]:
                        print(s[:i] + s[j])
                        exit()


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
s = input()
L = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
res = ""
if len(s) < 26:
    for i in range(26):
        if L[i] in s:
            continue
        else:
            res += s + L[i]
            break
else:
    for i in range(1, 26):
        if s[i - 1] > s[i]:
            if L[L.index(s[i]) + 1] != s[i - 1]:
                continue
            else:
                res = s[: i - 1]
                res += L[res.index(res[-1]) + 1]
                break
    else:
        res ="-1"

print(res)
Problem p03488 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = input()
    gx, gy = map(int, input().split())

    spl = list(map(len, s.split("T")))
    init_x = spl[0]
    is_x = 0
    to_x, to_y = [], []
    for i in range(1, len(spl)):
        to_x.append(spl[i]) if is_x else to_y.append(spl[i])
        is_x ^= 1

    now_x = [init_x]
    for move in to_x:
        nx = set()
        for x in now_x:
            nx.add(x + move)
            nx.add(x - move)
        now_x = nx

    now_y = [0]
    for move in to_y:
        ny = set()
        for y in now_y:
            ny.add(y + move)
            ny.add(y - move)
        now_y = ny

    print("Yes" if gx in now_x and gy in now_y else "No")


if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
MAX = 8010


def resolve():
    S = input()
    X, Y = map(int, input().split())

    x = 0
    y = 0
    flg = 1
    for s in S:
        if s == "F":
            if flg:
                x += 1
            else:
                y += 1
        else:
            flg ^= 1

    dp_x = [0] * MAX
    dp_x[MAX // 2] = 1
    for i in range(x):
        j = 0
        while j < MAX:
            if dp_x[j] == 1:
                dp_x[j] = 0
                dp_x[j - 1] = 1
                dp_x[j + 1] = 1
                j += 2
            else:
                j += 1

    dp_y = [0] * MAX
    dp_y[MAX // 2] = 1
    for i in range(y):
        j = 0
        while j < MAX:
            if dp_y[j] == 1:
                dp_y[j] = 0
                dp_y[j - 1] = 1
                dp_y[j + 1] = 1
                j += 2
            else:
                j += 1

    print("Yes" if dp_x[MAX // 2 + X] and dp_y[MAX // 2 + Y] else "No")


if __name__ == '__main__':
    resolve()
Problem p03569 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = input()
    ss = []
    for i in s:
        if i != "x":
            ss.append(i)

    if ss != ss[::-1]:
        print(-1)
    else:
        n = len(ss) + 1
        cnt = 0
        cnt_x = [0] * (n)
        pos = 0
        for i in range(len(s)):
            if s[i] == "x":
                cnt += 1

            if s[i] != "x" or i == len(s) - 1:
                cnt_x[pos] = cnt
                cnt = 0
                pos += 1

        res = 0
        for i in range(n // 2):
            res += abs(cnt_x[i] - cnt_x[-(i + 1)])

        print(res)


if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = input()
    n = len(s)
    ss = "".join(s.replace("x", ""))
    if ss != ss[::-1]:
        print(-1)
        exit()

    res = 0
    left = 0
    right = n - 1
    while left != right:
        if s[left] == s[right]:
            left += 1
            right -= 1
        else:
            if s[left] == "x":
                left += 1
            else:
                right -= 1
            res += 1
    print(res)


if __name__ == '__main__':
    resolve()
Problem p03573 (python)

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

if a == b:
    print(c)
elif a == c:
    print(b)
elif b == c:
    print(a)

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

if a == b:
    print(c)
elif a == c:
    print(b)
elif b == c:
    pritn(a)
Problem p03599 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    A, B, C, D, E, F = map(int, input().split())
    W = set()
    for a in range(F // (100 * A) + 1):
        for b in range(F // (100 * B) + 1):
            if 0 < 100 * A * a + 100 * B * b <= F:
                W.add(100 * A * a + 100 * B * b)
    W = sorted(list(W))
    kouho = []
    for w in W:
        max_S = (w // 100) * E
        tmp = 0
        for c in range(0, max_S + 1, C):
            for d in range(0, max_S + 1 - c, D):
                s = c + d
                if s + w <= F:
                    tmp = max(tmp, s)
        kouho.append([w + tmp, tmp])

    ma = 0
    res = [W[0], 0]
    for total, sugar in kouho:
        noudo = (sugar * 100) / total
        if ma < noudo:
            ma = noudo
            res = [total, sugar]

    print(*res)


if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    A, B, C, D, E, F = map(int, input().split())
    W = set()
    for a in range(F // (100 * A) + 1):
        for b in range(F // (100 * B) + 1):
            if 0 < 100 * A * a + 100 * B * b <= F:
                W.add(100 * A * a + 100 * B * b)
    W = sorted(list(W))

    kouho = []
    for w in W:
        max_S = (w // 100) * E
        tmp = 0
        for c in range(0, max_S + 1, C):
            for d in range(0, max_S + 1 - c, D):
                s = c + d
                total = s + w
                if total <= F:
                    tmp = max(tmp, s)
        kouho.append([w + tmp, tmp])

    ma = 0
    for total, sugar in kouho:
        noudo = (sugar * 100) / total
        if ma < noudo:
            ma = noudo
            res = [total, sugar]
    print(*res)


if __name__ == '__main__':
    resolve()
Problem p03611 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = sorted(list(map(int, input().split())))

    if n == 1:
        print(1)
    else:
        L = []
        for i in range(n):
            L.append(list(range(A[i] - 1, A[i] + 2)))

        ma = L[-1][-1]
        mi = L[0][0]
        res = [0] * (ma - mi + 1)
        for l in L:
            for i in l:
                res[i - mi] += 1

        print(max(res))


if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = sorted(list(map(int, input().split())))

    if n == 1:
        print(1)
    else:
        L = []
        for i in range(n):
            L.append(list(range(A[i] - 1, A[i] + 2)))

        ma = L[-1][-1]
        mi = L[0][0]
        res = [0] * (ma - mi + 1)
        for l in L:
            for i in l:
                res[i] += 1

        print(max(res))


if __name__ == '__main__':
    resolve()
Problem p03612 (python)

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

res = 0
for i in range(n):
    if i + 1 == P[i]:
        if i == n - 1:
            res += 1
        else:
            P[i], P[i + 1] = P[i + 1], P[i]
            res += 1
print(res)

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

res = 0
for i in range(n):
    if i + 1 == P[i]:
        P[i], P[i + 1] = P[i + 1], P[i]
        res += 1
print(res)