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

Fixed submission:
# D
N, Q = map(int, input().split())
A_list = list(map(int, input().split()))
q_list = [0]*Q
for i in range(Q):
    q_list[i] = int(input())

# precompute

# res
M = (N+1)//2
S1 = [0]*M
S2 = [0]*M

s1 = 0
s2 = 0
for i in range(M):
    s1 += A_list[N-1-i]
    S1[i] = s1
    s2 += A_list[N-1-2*i]
    S2[i] = s2

# bins
bins = [0]*(M-1)
for i in range(M-1):
    bins[i] = (A_list[N - (i+2)] + A_list[N - (2*i+3)]) / 2

# function for binary search
def bisearch(q):
    
    if q > bins[0]:
        return 0
    elif q <= bins[M-2]:
        return M - 1
    
    l = 0
    r = M - 2
    while l < r - 1:
        m = (l + r) // 2
        if q > bins[m]:
            r = m
        else:
            l = m
    return l+1
    
    
if N > 2:
    # first conflict
    for q in q_list:
        r = bisearch(q)
        print(S1[r]+s2-S2[r])
else:
    for q in q_list:
        print(A_list[1])

Buggy submission (verdict: Runtime Error):
# D
N, Q = map(int, input().split())
A_list = list(map(int, input().split()))
q_list = [0]*Q
for i in range(Q):
    q_list[i] = int(input())

# precompute

# res
M = (N+1)//2
S1 = [0]*M
S2 = [0]*M

s1 = 0
s2 = 0
for i in range(M):
    s1 += A_list[N-1-i]
    S1[i] = s1
    s2 += A_list[N-1-2*i]
    S2[i] = s2

# bins
bins = [0]*(M-1)
for i in range(M-1):
    bins[i] = (A_list[N - (i+2)] + A_list[N - (2*i+3)]) / 2

# function for binary search
def bisearch(q):
    
    if q > bins[0]:
        return 0
    elif q <= bins[M-2]:
        return M - 1
    
    l = 0
    r = M - 2
    while l < r - 1:
        m = (l + r) // 2
        if q > bins[m]:
            r = m
        else:
            l = m
    return l+1
    
    

# first conflict
for q in q_list:
    r = bisearch(q)
    print(S1[r]+s2-S2[r])
Problem p03203 (python)

Fixed submission:
# D
H, W, N = map(int,input().split())
field_dict = dict()
X_list = [0]*N
Y_list = [0]*N

for i in range(N):
    X, Y = map(int,input().split())
    X_list[i] = X-1
    Y_list[i] = Y-1
    field_dict[(X-1)*1000000 + (Y-1)] = 1

def query(posi_x, posi_y):
    return field_dict.get(posi_x*1000000+posi_y, 0)

# minimam x reachable
reach_y = [H]*W
reach_y[0] = 0
posi_x, posi_y = 0, 0

while posi_x < H - 1:
    # takahashi
    if query(posi_x+1, posi_y) == 1:
        # gameover
        break
    else:
        posi_x += 1
    # aoki
    if query(posi_x, posi_y+1) == 0 and posi_y + 1 < W:
        # move
        posi_y += 1
        reach_y[posi_y] = posi_x
        
res = H

for i in range(N):
    if reach_y[Y_list[i]] < X_list[i]:
        res = min(res, X_list[i])
        
print(res)

Buggy submission (verdict: Runtime Error):
# D
H, W, N = map(int,input().split())
field_dict = dict()
X_list = [0]*N
Y_list = [0]*N

for i in range(N):
    X, Y = map(int,input().split())
    X_list[i] = X-1
    Y_list[i] = Y-1
    field_dict[(X-1)*1000000 + (Y-1)] = 1

def query(posi_x, posi_y):
    return field_dict.get(posi_x*1000000+posi_y, 0)

# minimam x reachable
reach_y = [W]*H
reach_y[0] = 0
posi_x, posi_y = 0, 0

while posi_x < W - 1:
    # takahashi
    if query(posi_x+1, posi_y) == 1:
        # gameover
        break
    else:
        posi_x += 1
    # aoki
    if query(posi_x, posi_y+1) == 0 and posi_y + 1 < H:
        # move
        posi_y += 1
        reach_y[posi_y] = posi_x
        
res = W

for i in range(N):
    if reach_y[Y_list[i]] < X_list[i]:
        res = min(res, X_list[i])
        
print(res)

Buggy submission (verdict: Runtime Error):
# D
H, W, N = map(int,input().split())
field_dict = dict()
X_list = [0]*N
Y_list = [0]*N

for i in range(N):
    X, Y = map(int,input().split())
    X_list[i] = X-1
    Y_list[i] = Y-1
    field_dict[(X-1)*1000000 + (Y-1)] = 1

def query(posi_x, posi_y):
    return field_dict.get(posi_x*1000000+posi_y, 0)

# minimam x reachable
reach_y = [W]*H
reach_y[0] = 0
posi_x, posi_y = 0, 0

while posi_x < W - 1:
    # takahashi
    if query(posi_x+1, posi_y) == 1:
        # gameover
        break
    else:
        posi_x += 1
    # aoki
    if query(posi_x, posi_y+1) == 0:
        # move
        posi_y += 1
        reach_y[posi_y] = posi_x
        
res = W

for i in range(N):
    if reach_y[Y_list[i]] < X_list[i]:
        res = min(res, X_list[i])
        
print(res)
Problem p03247 (python)

Fixed submission:
# D
N = int(input())
X_list = [0]*N
Y_list = [0]*N

res_flag = 1

r = -1
for i in range(N):
    X, Y = map(int, input().split())
    if r >= 0:
        if r != (X+Y)%2:
            res_flag = -1
    else:
        r = (X+Y)%2
    X_list[i] = X
    Y_list[i] = Y
    
if res_flag == -1:
    print(-1)
else:
    if r == 0:
        print(32)
        print(" ".join([str(2**i) for i in range(30, -1, -1)]+["1"]))
        X_add = 1
        m_list_add = ["L"]
    else:
        print(31)
        print(" ".join([str(2**i) for i in range(30, -1, -1)]))
        X_add = 0
        m_list_add = []
    for n in range(N):
        X = X_list[n] + X_add
        Y = Y_list[n]
        
        S = X + Y
        T = X - Y
        m_list = []
        for i in range(30, -1, -1):
            if S < 0 and T < 0:
                m_list.append("L")
                S += 2**i
                T += 2**i
            elif S < 0 and T > 0:
                m_list.append("D")
                S += 2**i
                T -= 2**i
            elif S > 0 and T > 0:
                m_list.append("R")
                S -= 2**i
                T -= 2**i
            elif S > 0 and T < 0:
                m_list.append("U")
                S -= 2**i
                T += 2**i
            else:
                print("?")
        if S != 0 or T != 0:
            print("?")
        
        print("".join(m_list + m_list_add))

Buggy submission (verdict: Runtime Error):
# D
N = int(input())
X_list = [0]*N
Y_list = [0]*N

res_flag = 1

r = -1
for i in range(N):
    X, Y = map(int, input().split())
    if r >= 0:
        if r != (X+Y)%2:
            res_flag = -1
    else:
        r = (X+Y)%2
    X_list[i] = X
    Y_list[i] = Y
    
if res_flag == -1:
    print(-1)
else:
    if r == 0:
        print(22)
        print("1 1 2 2 3 3 4 4 5 5 1 1 2 2 3 3 4 4 5 5 1 1")
    else:
        print(23)
        print("1 1 2 2 3 3 4 4 5 5 1 1 2 2 3 3 4 4 5 5 1 1 1")        
        for i in range(N):
            m_list = list("LRLRLRLRLRDUDUDUDUDULR")
            X = X_list[i]
            Y = Y_list[i]
            
            if r != 0:
                if X >= 0:
                    X -= 1
                    m_list_add = ["R"]
                else:
                    X += 1
                    m_list_add = ["L"]
            else:
                m_list_add = []
            if X % 2 == 1:
                if X > 0:
                    m_list[20] = "R"
                    X -= 1
                else:
                    X += 1
                if Y > 0:
                    m_list[21] = "U"
                    Y -= 1
                else:
                    m_list[21] = "D"
                    Y += 1
            if X > 0:
                m_list[X - 2] = "R"
            elif X < 0:
                m_list[-X - 1] = "L"
            if Y > 0:
                m_list[Y + 8] = "U"
            elif Y < 0:
                m_list[-Y + 9] = "D"
            print("".join(m_list + m_list_add))
Problem p03256 (python)

Fixed submission:
# C
from collections import deque

N, M = map(int, input().split())
s = list(input())
s_ = []
for c in s:
    s_.append(c)

# Graph
G = dict()
for i in range(1, N+1):
    G[i] = dict()

for _ in range(M):
    a, b = map(int, input().split())
    G[a][b] = 1
    G[b][a] = 1
    
# clean up
queue = deque()
go = True

As = [0]*N
Bs = [0]*N

for i in range(1, N+1):
    if s[i-1] != "C":
        a = 0
        b = 0
        for k in G[i].keys():
            v = s_[k-1]
            if v == "A":
                a += 1
            elif v == "B":
                b += 1
        As[i-1] = a
        Bs[i-1] = b
        if a*b == 0:
            queue.append(i)
            s[i-1] = "C"

while len(queue) > 0:
    j = queue.popleft()
    for i in G[j].keys():
        if s[i-1] != "C":
            if s_[j-1] == "A":
                As[i-1] -= 1
            else:
                Bs[i-1] -= 1
            if As[i-1] * Bs[i-1] == 0:
                queue.append(i)
                s[i-1] = "C"

if "A" in s and "B" in s:
    print("Yes")
else:
    print("No")

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

N, M = map(int, input().split())
s = list(input())
s_ = s.copy()

# Graph
G = dict()
for i in range(1, N+1):
    G[i] = dict()

for _ in range(M):
    a, b = map(int, input().split())
    G[a][b] = 1
    G[b][a] = 1
    
# clean up
queue = degue()
go = True

As = [0]*N
Bs = [0]*N

for i in range(1, N+1):
    if s[i-1] != "C":
        a = 0
        b = 0
        for k in G[i].keys():
            v = s[k-1]
            if v == "A":
                a += 1
            elif v == "B":
                b += 1
        As[i-1] = a
        Bs[i-1] = b
        if a*b == 0:
            queue.append(i)
            s[i-1] = "C"

while len(queue) > 0:
    j = queue.popleft()
    for i in G[j].keys():
        if s[i-1] != "C":
            if s_[j] == "A":
                As[i-1] -= 1
            else:
                Bs[i-1] -= 1
            if As[i-1] * Bs[i-1] == 0:
                queue.append(i)
                s[i-1] = "C"

if "A" in s and "B" in s:
    print("Yes")
else:
    print("No")
Problem p03276 (python)

Fixed submission:
# C
N, K = map(int, input().split())
x_list = list(map(int, input().split()))

zero_cnt = 0
posi_ind = N
nega_ind = -1

# minus
for i in range(N):
    if x_list[i] == 0:
        zero_cnt = 1
        nega_ind = i-1
    elif x_list[i] > 0:
        posi_ind = i
        if zero_cnt == 0:
            nega_ind = i-1
        break
if zero_cnt == 1:
    K -= 1

if x_list[N-1] < 0:
    nega_ind = N-1
    
nega_seq = list(reversed(x_list[:(nega_ind+1)]))
posi_seq = x_list[posi_ind:]

res = 10**13
if K == 0:
    res = 0
else:
    for i in range(1, min(len(posi_seq)+1, K)):
        if K-i-1 >= len(nega_seq) or K-i-1 < 0:
            continue
        p = posi_seq[i-1]
        n = -nega_seq[K-i-1]
        r = min(2*p+n, 2*n+p)
        res = min(res, r)
    if len(posi_seq) >= K:
        r = posi_seq[K-1]
        res = min(res, r)
    if len(nega_seq) >= K:
        r = -nega_seq[K-1]
        res = min(res, r)
print(res)

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

zero_cnt = 0
posi_ind = N+1
nega_ind = -1
# minus
for i in range(N):
    if x_list[i] == 0:
        zero_cnt = 1
        nega_ind = i-1
    elif x_list[i] > 0:
        posi_ind = i
        if zero_cnt == 0:
            nega_ind = i-1
        break
if zero_cnt == 1:
    K -= 1
res = 10**13
if K == 0:
    res = 0
for i in range(1, min(nega_ind+1, K)+1):
    p = x_list[posi_ind+(K-i-1)]
    n = -x_list[nega_ind - i + 1]
    r = min(2*p+n, 2*n+p)
    res = min(res, r)
l = posi_ind+(K-1)
if l < N:
    r = x_list[l]
    res = min(res, r)
print(res)
Problem p03287 (python)

Fixed submission:
# D
N, M = map(int, input().split())
A_list = list(map(int, input().split()))

mod_dict = dict()
mod_dict[0] = 0
sum_k = 0
for a in A_list:
    sum_k += a
    r = sum_k % M
    if r not in mod_dict.keys():
        mod_dict[r] = 1
    else:
        mod_dict[r] += 1

res = 0
sum_k = 0

r = 0

for a in A_list:
    res += mod_dict[r]    
    sum_k += a
    r = sum_k % M
    mod_dict[r] -= 1
    
    
print(res)

Buggy submission (verdict: Runtime Error):
# D
N, M = map(int, input().split())
A_list = list(map(int, input().split()))

mod_dict = dict()

sum_k = 0
for a in A_list:
    sum_k += a
    r = sum_k % M
    if r not in mod_dict.keys():
        mod_dict[r] = 1
    else:
        mod_dict[r] += 1

res = 0
sum_k = 0

r = 0

for a in A_list:
    res += mod_dict[r]    
    sum_k += a
    r = sum_k % M
    mod_dict[r] -= 1
    
    
print(res)
Problem p03330 (python)

Fixed submission:
# D
import numpy as np

N, C = map(int, input().split())

C_cost_mat = np.zeros((C, C), dtype="int32")
now_mat = np.zeros((3, C), dtype="int32")

for i in range(C):
    c_list = list(map(int, input().split()))
    for j in range(C):
        C_cost_mat[i][j] = c_list[j]
        
for i in range(N):
    c_list = list(map(int, input().split()))
    for j in range(N):
        now_mat[(i + j + 2) % 3, c_list[j] - 1] += 1
        
res_mat = np.dot(now_mat, C_cost_mat)

res = 1000*N*N
for i1 in range(C):
    for i2 in range(C):
        for i3 in range(C):
            if i1 != i2 and i2 != i3 and i3 != i1:
                res = min(res, res_mat[0, i1] + res_mat[1, i2] + res_mat[2, i3])
print(res)

Buggy submission (verdict: Runtime Error):
# D
import numpy as np

N, C = map(int, input().split())

C_cost_mat = np.zeros((C, C), dtype="int32")
now_mat = np.zeros((3, C), dtype="int32")

for i in range(C):
    c_list = list(map(int, input().split()))
    for j in range(C):
        C_cost_mat[i][j] = c_list[j]
        
for i in range(N):
    c_list = list(map(int, input().split()))
    for j in range(N):
        now_mat[(i + j + 2) % 3, c_list[j] - 1] += 1
        
res_mat = np.matmul(now_mat, C_cost_mat)

res = 3000
for i1 in range(C):
    for i2 in range(C):
        for i3 in range(C):
            if i1 != i2 and i2 != i3 and i3 != i1:
                res = min(res, res_mat[0, i1] + res_mat[1, i2] + res_mat[2, i3])
print(res)

Buggy submission (verdict: Runtime Error):
# D
import numpy as np

N, C = map(int, input().split())

C_cost_mat = np.zeros((C, C), dtype="int32")
now_mat = np.zeros((3, C), dtype="int32")

for i in range(C):
    c_list = list(map(int, input().split()))
    for j in range(C):
        C_cost_mat[i][j] = c_list[j]
        
for i in range(N):
    c_list = list(map(int, input().split()))
    for j in range(N):
        now_mat[(i + j + 2) % 3, c_list[j] - 1] += 1
        
res_mat = now_mat @ C_cost_mat

res = 3000
for i1 in range(C):
    for i2 in range(C):
        for i3 in range(C):
            if i1 != i2 and i2 != i3 and i3 != i1:
                res = min(res, res_mat[0, i1] + res_mat[1, i2] + res_mat[2, i3])
print(res)
Problem p03341 (python)

Fixed submission:
# C
N = int(input())
S = list(input())


res = 0
for i in range(1, N):
    if S[i] == "E":
        res += 1
res_min = res
for i in range(1, N):
    if S[i-1] == "W":
        res += 1
    if S[i] == "E":
        res -= 1
    res_min = min(res, res_min)
print(res_min)

Buggy submission (verdict: Runtime Error):
# E
from heapq import heappush, heappop
import numpy as np

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

A_args = np.argsort(A)

nodeid = np.ones(N).astype("int32")
canput = np.ones(N)
nodeid_dict = dict()
nodeid_dict[1] = [0, N]

# initial output
res = A[A_args[Q-1]] - A[A_args[0]]

ind_del = 0

for i in range(N):
    
    nid = A_args[i]
    
    # update nodeid
    ndid = nodeid[nid]
    nodeid[nid] = 0
    left, right = nodeid_dict[ndid]
    nodeid[(nid+1):right] = i+2
    nodeid_dict[nid] = [left, nid]
    nodeid_dict[i+2] = [nid+1, right]

    # update canput
    canput[nid] = 0
    
    canput[left:nid] = 0
    h = []
    for j in range(left, nid):
        heappush(h, (-A[j], j))
    while len(h) >= K:
        _, j = heappop(h)
        canput[j] = 1
    
    canput[(nid+1):right] = 0
    h = []
    for j in range(nid+1, right):
        heappush(h, (-A[j], j))
    while len(h) >= K:
        _, j = heappop(h)
        canput[j] = 1
    
    # break
    if canput.sum() <= Q:
        break
        
    # calculate
    q = 0
    qmin = 10**9
    qmax = 1
    for i in range(N):
        if canput[A_args[i]] == 1:
            q += 1
            qmin = min(A[A_args[i]], qmin)
            qmax = max(A[A_args[i]], qmax)
            if q == Q:
                r = qmax - qmin
                break
    res = min(res, r)
print(res)
Problem p03389 (python)

Fixed submission:
# C
ABC = sorted(list(map(int, input().split())))

res = 0

res += ABC[2] - ABC[1]
ABC[0] += ABC[2] - ABC[1]
ABC[1] = ABC[2]

if (ABC[2] - ABC[0]) % 2 == 0:
    res += (ABC[2] - ABC[0]) // 2
else:
    res += (ABC[2] - ABC[0]) // 2 + 2
    
print(res)

Buggy submission (verdict: Runtime Error):
# D
import math
Q = int(input())
A_list = []
B_list = []
for _ in range(Q):
    A, B = map(int, input().split())
    A_list.append(min(A, B))
    B_list.append(max(A, B))
    
for i in range(Q):
    A = A_list[i]
    B = B_list[i]
        
    if A == B:
        print(A+B-2)
        continue
        
    R = int(math.sqrt(A*B-1))
    Q = (A*B-1) // R
    
    if Q <= R+1:
        add = min(Q - A - 1, B - R - 1)    
    elif (Q - R)**2 - 4*(A*B-Q*R) > 0:
        add = int(((Q - R) - math.sqrt((Q - R)**2 - 4*(A*B-Q*R))) / 2)
        if (R + add)*(Q-add) == A*B:
            add -= 1
    else:
        add = 0
    print((A-1) + R + add)
Problem p03440 (python)

Fixed submission:
# D
import numpy as np

N, M = map(int, input().split())
a_list = list(map(int, input().split()))

G = dict()
for i in range(N):
    G[i] = []

for _ in range(M):
    x, y = map(int, input().split())
    G[x].append(y)
    G[y].append(x)
    
res = 0
connec = 0
done_list = [0]*N

st = 0
while True:
    while st < N:
        if done_list[st] == 0:
            break
        st += 1

    if st == N:
        break

    queue = [st]
    conn = [a_list[st]]
    conn_ = [st]
    done_list[st] = 1
    connec += 1

    while len(queue) > 0:
        s = queue.pop()
        for t in G[s]:
            if done_list[t] == 0:
                done_list[t] = 1
                queue.append(t)
                conn.append(a_list[t])
                conn_.append(t)
                
    args = np.argsort(conn)
    res += conn[args[0]]
    a_list[conn_[args[0]]] = 2000000000

a_list.sort()

if connec == 1:
    print(0)
elif len(a_list) < 2*connec - 2:
    print('Impossible')
else:
    print(res + sum(a_list[:(connec - 2)]))

Buggy submission (verdict: Runtime Error):
# D
import numpy as np

N, M = map(int, input().split())
a_list = list(map(int, input().split()))

G = dict()
for i in range(N):
    G[i] = []

for _ in range(M):
    x, y = map(int, input().split())
    G[x].append(y)
    G[y].append(x)
    
res = 0
connec = 0
done_list = [0]*N

st = 0
while True:
    while st < N:
        if done_list[st] == 0:
            break
        st += 1

    if st == N:
        break

    queue = [st]
    conn = [a_list[st]]
    conn_ = [st]
    done_list[st] = 1
    connec += 1

    while len(queue) > 0:
        s = queue.pop()
        for t in G[s]:
            if done_list[t] == 0:
                done_list[t] = 1
                queue.append(t)
                conn.append(a_list[t])
                conn_.append(t)
                
    args = np.argsort(conn)
    res += conn[args[0]]
    a_list[conn_[args[0]]] = 2000000000

a_list.sort()

if connec == 1:
    print(0)
elif len(a_list) < 2*connec - 2:
    print('Impossible')
else:
    print(res + sum(conn_list[:(connec - 2)]))
Problem p03603 (python)

Fixed submission:
# E
N = int(input())
P_list = list(map(int, input().split()))
X_list = list(map(int, input().split()))

# graph
child_list = [[] for _ in range(N+1)]
for i in range(2, N+1):
    child_list[P_list[i-2]].append(i)

# from root
# minimize local total weight

color1 = [0]+X_list
color2 = [0]*(N+1)

# solve knapsack
def solve_knapsack(L, M):
    min_acc = sum([min(color1[j], color2[j]) for j in L])
    if min_acc > M:
        return -1
    else:
        add_can = M - min_acc
        add_set = set([0])
        for j in L:
            add_j = max(color1[j], color2[j]) - min(color1[j], color2[j])
            add_set_ = set(add_set)
            for s in add_set:
                if s + add_j <= add_can:
                    add_set_.add(s + add_j)
            add_set = add_set_
        
        total = sum([color1[j]+color2[j] for j in L])
        return total - max(add_set) - min_acc

res = "POSSIBLE"

for i in range(N, 0, -1):
    if len(child_list[i]) == 0:
        pass
    elif len(child_list[i]) == 1:
        j = child_list[i][0]
        if min(color1[j], color2[j]) > X_list[i-1]:
            res = "IMPOSSIBLE"
            break
        elif max(color1[j], color2[j]) > X_list[i-1]:
            color2[i] = max(color1[j], color2[j])
        else:
            color2[i] = min(color1[j], color2[j])
    else:
        c2 = solve_knapsack(child_list[i], X_list[i-1])
        if c2 < 0:
            res = "IMPOSSIBLE"
            break
        else:
            color2[i] = c2
    
print(res)

Buggy submission (verdict: Runtime Error):
# E
N = int(input())
P_list = list(map(int, input().split()))
X_list = list(map(int, input().split()))

# graph
child_list = [[] for _ in range(N+1)]
for i in range(2, N+1):
    child_list[P_list[i-2]].append(i)

# from root
# minimize local total weight

color1 = [0]+X_list
color2 = [0]*(N+1)

# solve knapsack
def solve_knapsack(L, M):
    min_acc = sum([min(color1[j], color2[j]) for j in L])
    if min_acc > M:
        return -1
    else:
        add_can = M - min_acc
        add_set = set([0])
        for j in L:
            add_j = max(color1[j], color2[j]) - min(color1[j], color2[j])
            add_set_ = set(add_set)
            for s in add_set:
                if s + add_j <= add_can:
                    add_set_.add(s + add_j)
            add_set = add_set_
        
        total = sum([color1[j]+color2[j] for j in L])
        return total - max(add_set)

res = "POSSIBLE"

for i in range(N, 0, -1):
    if len(child_list[i]) == 0:
        pass
    elif len(child_list[i]) == 1:
        j = child_list[i][0]
        if min(color1[j], color2[j]) > X_list[i-1]:
            res = "IMPOSSIBLE"
            break
        elif max(color1[j], color2[j]) > X_list[i-1]:
            color2[i] = max(color1[j], color2[j])
        else:
            color2[i] = min(color1[j], color2[j])
    else:
        c2 = solve_knapsack(child_list[i], X_list[i-1])
        if c2 < 0:
            res = "IMPOSSIBLE"
            break
        else:
            color2[j] = c2
    
print(res)
Problem p03615 (python)

Fixed submission:
# E
from collections import Counter

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

M = 998244353

res = pow(2, N, M)
# 0 points
res -= 1
# 1 points
res -= N

# all lines
line_cnt = [0]*(N+1)

for i in range(N):
    xi, yi = xy_list[i]
    angle_list = []
    for j in range(N):
        xj, yj = xy_list[j]
        if xj != xi:
            angle_list.append((yj-yi)/(xj-xi))
        elif yj != yi:
            angle_list.append(10000.0)
        
    # count points in same line
    cnt_i = Counter(angle_list)
    for k in cnt_i.values():
        line_cnt[k+1] += 1

for i in range(2, N+1):
    cnt = line_cnt[i] // i
    res -= cnt*(pow(2, i, M)-i-1)

res = res % M
print(res)

Buggy submission (verdict: Runtime Error):
# E
from collections import Counter

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

M = 998244353

res = pow(2, N, M)
# 0 points
res -= 1
# 1 points
res -= N

# all lines
line_cnt = [0]*(N+1)

for i in range(N):
    xi, yi = xy_list[i]
    angle_list = []
    for j in range(N):
        xj, yj = xy_list[j]
        if xj != xi:
            angle_list.append((yj-yi)/(xj-xi))
        elif yj != xj:
            angle_list.append(10000.0)
        
    # count points in same line
    cnt_i = Counter(angle_list)
    for k in cnt_i.values():
        line_cnt[k+1] += 1

for i in range(2, N+1):
    cnt = line_cnt[i] // i
    res -= cnt*(pow(2, i, M)-i-1)

res = res % M
print(res)
Problem p03633 (python)

Fixed submission:
N = int(input())
 
a_list = []
for _ in range(N):
    a_list.append(int(input()))
 
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
 
res = 1
for i in range(N):
    d = gcd(res, a_list[i])
    res = res // d
    res = res * a_list[i]
 
print(res)

Buggy submission (verdict: Runtime Error):
N = int(input())

a_list = []
for _ in range(N):
    a_list.append(int(input())

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

res = 1
for i in range(N):
    d = gcd(res, a_list[i])
    res = res // d
    res = res * a_list[i]

print(res)