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

Fixed submission:
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
px = [list(map(int, input().split())) for _ in range(q)]

graph = [[] for _ in range(n + 1)]
for a, b in ab:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (n + 1)
for p, x in px:
    value[p] += x


def dfs(v, p, add):
    value[v] += add
    for x in graph[v]:
        if x == p:
            continue
        dfs(x, v, value[v])


dfs(1, 0, 0)

ans = value[1:]
print(*ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
px = [list(map(int, input().split())) for _ in range(q)]

graph = [[] for _ in range(n + 1)]
for a, b in ab:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (n + 1)
for p, x in px:
    value[p] += x


def dfs(v, p, add):
    value[v] += add
    for x in graph[v]:
        if x == p:
            continue
        dfs(x, v, value[v])


dfs(1, 0, 0)

ans = value[1:]
print(*ans)
Problem p02947 (python)

Fixed submission:
# -*- coding: utf-8 -*-

def my_sort(word):
    sorted_word_list = sorted(word)
    sorted_word = ""
    for letter in sorted_word_list:
        sorted_word += letter
    return sorted_word

n = int(input())
words = {}
for i in range(n):
    word = my_sort(input())
    if word in words.keys():
        words[word] += 1
    else:
        words[word] = 1

for key in words.keys():
    words[key] = max(words[key]*(words[key]-1)//2, 0)

print(sum(words.values()))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

def my_sort(word):
    sorted_word_list = sorted(word)
    sorted_word = ""
    for letter in sorted_word_list:
        sorted_word += letter
    return sorted_word

def func(x):
    if x < 1:
        return x
    return x + func(x-1)

n = int(input())
words = {}
for i in range(n):
    word = my_sort(input())
    if word in words.keys():
        words[word] += 1
    else:
        words[word] = 0

for key in words.keys():
    words[key] = func(words[key])

print(sum(words.values()))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

def my_sort(word):
    sorted_word_list = sorted(word)
    sorted_word = ""
    for letter in sorted_word_list:
        sorted_word += letter
    return sorted_word

def func(x):
    if x < 1:
        return x
    return x + func(x-1)

n = int(input())
words = {}
for i in range(n):
    word = my_sort(input())
    if word in words.keys():
        words[word] += 1
    else:
        words[word] = 0

for key in words.keys():
    words[key] = func(words[key])

print(sum(words.values()))
Problem p02949 (python)

Fixed submission:
n, m, p = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(m)]


def bellman_ford(s, g):
    # loop 0 - (n-1) : bellman ford
    # loop n - (2n-1): check g can be updated
    dist = [float("inf")] * n
    dist[s] = 0
    for i in range(2 * n):
        for a, b, c in abc:
            a -= 1
            b -= 1
            cost = -(c - p)

            if dist[b] > dist[a] + cost:
                dist[b] = dist[a] + cost
                if i >= n:
                    dist[b] = -float("inf")

    if dist[g] == -float("inf"):
        return -1

    else:
        return max(-dist[g], 0)


ans = bellman_ford(0, n - 1)
print(ans)

Buggy submission (verdict: Runtime Error):
from scipy.sparse.csgraph import bellman_ford, NegativeCycleError
from scipy.sparse import csr_matrix

n, m, p = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(m)]

fwd = [[] for _ in range(n + 1)]
rev = [[] for _ in range(n + 1)]

for a, b, c in abc:
    fwd[a].append(b)
    rev[b].append(a)


def dfs(s, adj):
    stack = [s]
    arrived = [False] * (n + 1)
    arrived[s] = True
    while stack:
        u = stack.pop()
        for v in adj[u]:
            if not arrived[v]:
                arrived[v] = True
                stack.append(v)

    return arrived


can_go_fwd = dfs(1, fwd)
can_go_rev = dfs(n, rev)

row = []
col = []
cost = []
for a, b, c in abc:
    if can_go_fwd[a] and can_go_rev[b]:
        row.append(a)
        col.append(b)
        cost.append(p - c)

g = csr_matrix((cost, (row, col)), shape=(n + 1, n + 1))
try:
    dist = bellman_ford(g, indices=1).astype(int)
    ans = max(0, -dist[n])
    print(ans)
except NegativeCycleError:
    print(-1)
Problem p02972 (python)

Fixed submission:
# -*- coding: utf-8 -*-

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

res = [0] * (n + 1)

for i in range(1, n + 1)[::-1]:
    sum_res = sum(res[x] for x in range(i, n + 1, i))
    if sum_res % 2 != arr[i - 1]:
        res[i] = 1

print(sum(res))

if sum(res):
    ans = []
    for i, ele in enumerate(res):
        if ele:
            ans.append(i)
    print(*ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-                                                                              

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

res = [0] * (n + 1)

for i in range(1, n+1)[::-1]:
    sum_res = sum(res[x] for x in range(i, n+1, i))
    if sum_res % 2 != arr[i - 1]:
	res[i] = 1

print(sum(res))

if sum(res):
    ans = []
    for	i, ele in enumerate(res):
        if ele:
            ans.append(i)
    print(*ans)
Problem p02983 (python)

Fixed submission:
l, r = map(int, input().split())

i_max = min(r, l+2019)
mod_min = 2019
for i in range(l, i_max):
    j_max = min(r, i+2019)
    for j in range(i+1, j_max+1):
        mod = (i*j) % 2019
        if mod < mod_min:
            mod_min = mod

print(mod_min)

Buggy submission (verdict: Runtime Error):
l, r = map(int, input().split())

i_max =	min(r, l+2019)
mod_min = 2019
for i in range(l, i_max):
    j_max = min(r, i+2019)
    for	j in range(i+1, j_max+1):
	mod = (i*j) % 2019
        if mod < mod_min:
            mod_min = mod

print(mod_min)
Problem p02991 (python)

Fixed submission:
from collections import deque

n, m = map(int, input().split())
uv = [list(map(int, input().split())) for _ in range(m)]
s, t = map(int, input().split())

adj = [[] for _ in range(3 * n)]
for u, v in uv:
    u -= 1
    v -= 1
    adj[u].append(v + n)
    adj[u + n].append(v + 2 * n)
    adj[u + 2 * n].append(v)


def bfs(s):
    q = deque([s])
    d = [-1] * (3 * n)
    d[s] = 0
    while q:
        u = q.popleft()
        for v in adj[u]:
            if d[v] == -1:
                d[v] = d[u] + 1
                q.append(v)

    return d


dist = bfs(s - 1)
ans = dist[t - 1]
print(ans // 3)

Buggy submission (verdict: Runtime Error):
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
import sys
sys.setrecursionlimit(10 ** 6)

n, m = map(int, input().split())
uv = [list(map(int, input().split())) for _ in range(m)]
s, t = map(int, input().split())

adj = [[] for _ in range(n)]
for u, v in uv:
    u -= 1
    v -= 1
    adj[u].append(v)

u = []
v = []
c = []


def dfs(start, now, depth):
    if depth == 3:
        u.append(start)
        v.append(now)
        c.append(1)
        return

    for nxt in adj[now]:
        dfs(start, nxt, depth + 1)


for i in range(n):
    dfs(i, i, 0)

graph = csr_matrix((c, (u, v)), shape=(n, n))
dist = dijkstra(graph).astype(int)
ans = dist[s-1][t-1]
if ans < 0:
    ans = -1
print(ans)

Buggy submission (verdict: Runtime Error):
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

n, m = map(int, input().split())
uv = [list(map(int, input().split())) for _ in range(m)]
s, t = map(int, input().split())

adj = [[] for _ in range(n)]
for u, v in uv:
    u -= 1
    v -= 1
    adj[u].append(v)

u = []
v = []
c = []


def dfs(start, now, depth):
    if depth == 3:
        u.append(start)
        v.append(now)
        c.append(1)
        return

    for nxt in adj[now]:
        dfs(start, nxt, depth + 1)


for i in range(n):
    dfs(i, i, 0)

graph = csr_matrix((c, (u, v)), shape=(n, n))
dist = dijkstra(graph).astype(int)
ans = dist[s-1][t-1]
if ans < 0:
    ans = -1
print(ans)
Problem p02997 (python)

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

if k <= (n - 1) * (n - 2) // 2:
    g = [0] * (n * n)
    for i in range(n * n):
        u = i // n
        v = i % n
        if u < v:
            g[i] = 1

    i = 0
    for _ in range(k):
        while g[i] == 0 or i % n == n - 1:
            i += 1
        g[i] = 0

    cnt = sum(g)
    print(cnt)
    for i, e in enumerate(g):
        if e:
            u = i // n + 1
            v = i % n + 1
            print(u, v)

else:
    print(-1)

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

if k <= (n - 1) * (n - 2) // 2:
    raise Exception
else:
    print(-1)

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

mn = n - 2
mx = (n - 1) * (n - 2) // 2

if mn <= k <= mx:
    raise Exception

else:
    print(-1)
Problem p03029 (python)

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

print((3*a + p) // 2)

Buggy submission (verdict: Runtime Error):
n = int(input())
r = []
for i in range(n):
    city, score = map(str, input().split())
    score = int(score)
    r.append((city, score, i+1))

r.sort(key=lambda x: x[1], reverse=True)
r.sort(key=lambda x: x[0])

for x in r:
    print(x[2])
Problem p03035 (python)

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

if a >= 13:
    print(b)
elif a >= 6:
    print(b//2)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for _ in range(m)]

bc.sort(key=lambda x: x[1], reverse=True)
d = []
i = 0

while len(d) <= n and i < len(bc):
    d += ([bc[i][1]] * bc[i][0])
    i += 1

if len(d) > n:
    d = d[:n]

a += d
a.sort(reverse=True)

print(sum(a[:n]))
Problem p03044 (python)

Fixed submission:
n = int(input())
uvw = [list(map(int, input().split())) for _ in range(n-1)]

g = [[] for _ in range(n)]

for u, v, w in uvw:
    u -= 1
    v -= 1
    g[u].append([v, w])
    g[v].append([u, w])


WHITE = 0
GRAY = 1
BLACK = 2

ds = [0] * n
colors = [WHITE] * n
ps = [-1] * n


def dfs(s):
    global ds, colors, ps

    stack = []

    ds[s] = 0
    colors[s] = BLACK
    ps[s] = -1
    stack.append(ds[s])

    while stack:
        u = stack[-1]
        colors[u] = GRAY

        for v, w in g[u]:
            if colors[v] == WHITE:
                stack.append(v)
                ds[v] = ds[u] + w
                ps[v] = u
                g[u].remove([v, w])
                g[v].remove([u, w])
                break

        else:
            stack.pop()
            colors[u] = BLACK

    return ds, ps


dfs(0)

for d in ds:
    print(d % 2)

Buggy submission (verdict: Runtime Error):
class Tree:
    WHITE = 0
    GRAY = 1
    BLACK = 2

    def __init__(self, adj):
        n = len(adj)
        self.adj = adj
        self.colors = [self.WHITE] * n
        self.depths = [-1] * n
        self.depth = 0

    def dfs(self, u):
        if self.colors[u] == self.BLACK:
            return

        self.colors[u] = self.GRAY
        self.depths[u] = self.depth

        for v, w in self.adj[u]:
            if self.colors[v] == self.WHITE:
                self.depth += w
                self.dfs(v)
                self.depth -= w

        self.colors[u] = self.BLACK


if __name__ == "__main__":
    n = int(input())
    uvw = [list(map(int, input().split())) for _ in range(n - 1)]

    g = [[] for _ in range(n)]

    for u, v, w in uvw:
        u -= 1
        v -= 1
        g[u].append((v, w))
        g[v].append((u, w))

    tree = Tree(g)
    tree.dfs(0)
    ans = [x % 2 for x in tree.depths]
    print(*ans, sep="\n")

Buggy submission (verdict: Runtime Error):
n = int(input())
uvw = [list(map(int, input().split())) for _ in range(n-1)]

g = [[] for _ in range(n)]

for u, v, w in uvw:
    u -= 1
    v -= 1
    g[u].append([v, w])
    g[v].append([u, w])


WHITE = 0
GRAY = 1
BLACK = 2

ds = [0] * n
colors = [WHITE] * n


def dfs(u):
    if colors[u] == BLACK:
        return

    colors[u] = GRAY

    for v, w in g[u]:
        if colors[v] == WHITE:
            ds[v] = ds[u] + w
            dfs(v)

    colors[u] = BLACK


dfs(0)

for d in ds:
    print(d % 2)
Problem p03046 (python)

Fixed submission:
m, k = map(int, input().split())

if m == 0:
    if k == 0:
        ans = [0, 0]
    else:
        ans = []

elif m == 1:
    if k == 0:
        ans = [0, 0, 1, 1]
    else:
        ans = []

elif k < 2 ** m:
    li = list(range(2 ** m))
    li.remove(k)
    ans = li + [k] + li[::-1] + [k]

else:
    ans = []

if ans:
    print(*ans)
else:
    print(-1)

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

if m == 0:
    if k == 0:
        ans = [0, 0]
    else:
        ans = []

elif m == 1:
    if k == 0:
        ans = [0, 0, 1, 1]
    else:
        ans = []

elif k < 2 ** m:
    li = list(range(1,  2 ** m))
    li.remove(k)
    ans = li + [k] + li[::-1] + [k]

else:
    ans = []

if ans:
    print(*ans)
else:
    print(-1)
Problem p03061 (python)

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

def gcd(a, b):
    if min(a, b) == 0:
        return max(a, b)
    while b:
        a, b = b, a % b
    return a

l = [0]
r = [0]
for i in range(n):
    l.append(gcd(l[i], a[i]))
    r.append(gcd(r[i], a[n-i-1]))

r = r[::-1]

ans = 0
for i in range(n):
    g = gcd(l[i], r[i+1])
    ans = max(ans, g)

print(ans)

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

def gcd(a, b):
    if min(a, b) == 0:
        return max(a, b)
    while b:
        a, b = b, a % b
    return a

def gcd_l(l):
    if len(l) == 1:
        return l[0]
    else:
        return gcd(l[0], gcd_l(l[1:]))

ans = 0
from copy import deepcopy
for i in range(n):
    li = deepcopy(a)
    li.remove(a[i])
    ans = max(ans, gcd_l(li))

print(ans)

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

def gcd(a, b):
    if min(a, b) == 0:
        return max(a, b)
    while b:
        a, b = b, a % b
    return a

def l(i):
    if i == 0:
        return 0
    else:
        return gcd(l(i-1), a[i-1])

def r(i):
    if i == n:
        return 0
    else:
        return gcd(r(i+1), a[i])

gcd_max = 1
for i in range(n):
    i_gcd = gcd(l(i), r(i+1))
    if i_gcd > gcd_max:
        gcd_max = i_gcd

print(gcd_max)

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

def gcd(a, b):
    if min(a, b) == 0:
        return max(a, b)
    while b:
        a, b = b, a%b
    return a

def l(i):
    if i == 0:
        return 0
    else:
        return gcd(l(i-1), a[i-1])

def r(i):
    if i == n:
        return 0
    else:
        return gcd(r(i+1), a[i])

gcd_max = 1
for i in range(n):
    i_gcd = gcd(l(i), r(i+1))
    if i_gcd > gcd_max:
        gcd_max = i_gcd

print(gcd_max)

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

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

def gcd_l(l):
    if len(l) <= 1:
        return l[0]
    elif len(l) == 2:
        return gcd(l[0], l[1])
    else:
        return gcd(gcd_l(l[:-1]), l[-1])

gcd_max = 1
for i in range(n):
    if i == 0:
        i_gcd = gcd_l(a[i+1:])
    elif i == n-1:
        i_gcd = gcd_l(a[:i])
    else:
        i_gcd = gcd(gcd_l(a[:i]), gcd_l(a[i+1:]))
    if i_gcd > gcd_max:
        gcd_max = i_gcd

print(gcd_max)

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

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

def gcd_l(l):
    if len(l) == 1:
        return l[0]
    elif len(l) == 2:
        return gcd(l[0], l[1])
    else:
        return gcd(gcd_l(l[:-1]), l[-1])

gcd_max = 1
for i in range(n):
    i_gcd = gcd_l(a[:i]+a[i+1:])
    if i_gcd > gcd_max:
        gcd_max = i_gcd

print(gcd_max)
Problem p03086 (python)

Fixed submission:
s = input()

s += "X"
pat = ["A", "C", "G", "T"]
mx = 0
count = 0

for i in range(len(s)):
    if s[i] in pat:
        count += 1
    else:
        if count > mx:
            mx = count
        count = 0

print(mx)

Buggy submission (verdict: Runtime Error):
s = input()

s.append("X")
pat = ["A", "C", "G", "T"]
mx = 0
count = 0

for i in range(len(s)):
    if s[i] in pat:
        count += 1
    else:
        if count > mx:
            mx = count
        count = 0

print(mx)
Problem p03157 (python)

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

dct = {"#": 0, ".": 1, "-": 2}


def f(c):
    return dct[c]


h, w = map(int, input().split())
s = [[2] * (w + 2)]
for _ in range(h):
    s.append([2] + list(map(f, input())) + [2])
s.append([2] * (w + 2))

d = [(-1, 0), (1, 0), (0, -1), (0, 1)]


def dfs(col, hh, ww):
    if s[hh][ww] != col:
        return

    cnt[col] += 1
    s[hh][ww] = 2

    for dh, dw in d:
        nh = hh + dh
        nw = ww + dw
        dfs(1-col, nh, nw)


ans = 0
for hi in range(1, h + 1):
    for wi in range(1, w + 1):
        cnt = [0, 0]
        if s[hi][wi] != 2:
            dfs(s[hi][wi], hi, wi)
        ans += cnt[0] * cnt[1]

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
#sys.setrecursionlimit(10 ** 7)

dct = {"#": 0, ".": 1, "-": 2}


def f(c):
    return dct[c]


h, w = map(int, input().split())
s = [[2] * (w + 2)]
for _ in range(h):
    s.append([2] + list(map(f, input())) + [2])
s.append([2] * (w + 2))

d = [(-1, 0), (1, 0), (0, -1), (0, 1)]


def dfs(col, hh, ww):
    if s[hh][ww] != col:
        return

    cnt[col] += 1
    s[hh][ww] = 2

    for dh, dw in d:
        nh = hh + dh
        nw = ww + dw
        dfs(1-col, nh, nw)


ans = 0
for hi in range(1, h + 1):
    for wi in range(1, w + 1):
        cnt = [0, 0]
        if s[hi][wi] != 2:
            dfs(s[hi][wi], hi, wi)
        ans += cnt[0] * cnt[1]

print(ans)
Problem p03220 (python)

Fixed submission:
# -*- coding: utf-8 -*-                                                                              

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

import numpy as	np

ans = (T-A) / 0.006

h = np.abs(np.array(list(map(int, input().split()))) - ans)

print(np.argmin(h) + 1)

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

min_i =	0
min_temp = abs(T - H[0] * 0.006 - A)

for i in range(1, N):
    if abs(T-H[i]*0.006-A) < min_temp:
	min_temp = abs(T-H[i]*0.006-A)
        min_i =	i

print(min_i+1)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-                                                                              

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

min_i =	0
min_temp = abs(T - H[0] * 0.006 - A)

for i in range(1, N):
    if abs(T-H[i]*0.006-A) < min_temp:
	min_temp = abs(T-H[i]*0.006-A)
        min_i =	i

print(min_i+1)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-                                                                              

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

min_i =	0
min_temp = abs(T - H[0] * 0.006 - A)

for i in range(1, N):
    if abs(T-H[i]*0.006-A) < min_temp:
	min_temp = abs(T-H[i]*0.006-A)
        min_i =	i

print(min_i+1)
Problem p03328 (python)

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

import sys

sys.setrecursionlimit(2000)

def f(x):
    if x == 0:
        return x
    return x + f(x - 1)

diff = b - a
east = f(diff)
print(east - b)

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

def f(x):
    if x == 0:
        return x
    return x + f(x - 1)

diff = b - a
east = f(diff)
print(east - b)
Problem p03340 (python)

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

r = 0
s = 0

ans = 0
for l in range(n):
    while r < n and not (s & a[r]):
        s ^= a[r]
        r += 1
    ans += r - l
    s ^= a[l]

print(ans)

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

r = -1
s = 0

ans = 0
for l in range(n):
    while r < n and not (s & a[r+1]):
        s ^= a[r+1]
        r += 1
    ans += r - l + 1
    s ^= a[l]

print(ans)
Problem p03343 (python)

Fixed submission:
n, k, q = map(int, input().split())
a = list(map(int, input().split()))

if q == 1:
    print(0)
    exit()

ans = 10 ** 10
for i, y in enumerate(a):
    li = []
    l = 0
    cnd = []
    for j, x in enumerate(a + [-1]):
        if i == j:
            continue
        if x < y:
            if l - k + 1 >= 0:
                li.sort()
                cnd += li[:l-k+1]
            li = []
            l = 0
        else:
            li.append(x)
            l += 1

    if len(cnd) >= q - 1:
        cnd.sort()
        sub = cnd[q-2] - y
        ans = min(ans, sub)

print(ans)

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

ans = 10 ** 10
for i, y in enumerate(a):
    li = []
    l = 0
    cnd = []
    for j, x in enumerate(a + [-1]):
        if i == j:
            continue
        if x < y:
            if l - k + 1 >= 0:
                li.sort()
                cnd += li[:l-k+1]
            li = []
            l = 0
        else:
            li.append(x)
            l += 1

    if len(cnd) >= q - 1:
        cnd.sort()
        sub = cnd[q-2] - y
        ans = min(ans, sub)

print(ans)
Problem p03378 (python)

Fixed submission:
n, m, x = map(int, input().split())
a = list(map(int, input().split()))

l = 0
r = 0
for a_ele in a:
    if a_ele < x:
        l += 1
    else:
        r += 1

print(min(l, r))

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

li = [0] * (n - 1)
for a_ele in a:
    li[a_ele] = 1

print(min(sum(li[:x]), sum(li[x+1:])))
Problem p03399 (python)

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())

print(min(a, b) + min(c, d))

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

print(min(a, b) + min(c, d))
Problem p03424 (python)

Fixed submission:
n = int(input())
s = list(input().split())

print("Four" if "Y" in s else "Three")

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

print("Four" if "Y" in s else "Three")
Problem p03427 (python)

Fixed submission:
def main():
    n = input()

    l = len(n)

    nines = "0" + "9" * (l - 1)
    nines = int(nines)

    num = nines
    for i in range(1, 10):
        tmp = i * 10 ** (l - 1) + nines
        if tmp <= int(n):
            num = tmp

    ans = sum(map(int, str(num)))
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = input()

    l = len(n)

    nines = "9" * (l - 1)
    num = int(nines)

    for i in range(1, 10):
        tmp = str(i) + nines
        if int(tmp) <= int(n):
            num = tmp

    ans = sum(map(int, num))
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = input()

    l = len(n)
    diff = ""
    for i, e in enumerate(n):
        if i == 0:
            c = 0
        elif i == l - 1:
            c = int(e) + 1
        else:
            c = int(e)

        c = str(c)
        diff += c

    num = int(n) - int(diff)
    num = str(num)
    ans = sum(map(int, num))
    print(ans)


if __name__ == "__main__":
    main()
Problem p03434 (python)

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

a.sort(reverse=True)
score = [0, 0]
for i in range(n):
    score[i%2] += a[i]

print(score[0] - score[1])

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

a.sort(reversed=True)
score = [0, 0]
for i in range(n):
    score[i%2] += a[i]

print(score[0] - score[1])

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

a.sort(reversed=True)
score = [0, 0]
for i in range(n):
    score[i&2] += a[i]

print(score[0] - score[1])