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

Fixed submission:
import numpy as np

def solve(N, Z, W, A):
    # dp_x[n] := y さんが n 枚目を引いて x さんに手番が回ったときの最大値
    dp_x = np.full(N+1, 1<<61, dtype=np.int64)
    dp_y = np.zeros(N+1, dtype=np.int64)
    for i in range(N-1, 0, -1):
        dp_x[i] = max(dp_y[i+1:].max(), abs(A[-1]-A[i-1]))
        dp_y[i] = min(dp_x[i+1:].min(), abs(A[-1]-A[i-1]))
    ans = max(abs(A[-1]-W), dp_y[1:].max())
    return ans

N, Z, W = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
ans = solve(N, Z, W, A)
print(ans)

Buggy submission (verdict: Runtime Error):
N, Z, W = map(int, input().split())
A = list(map(int, input().split()))
L = []
D = []
def rec(x, y, n, turn):
    xp, yp = x, y
    C = []
    for i in range(n+1, N+1):
        x, y = xp, yp
        if i == N:
            C.append(abs(A[-1]-y if turn else x-A[-1]))
            continue
        if turn:
            x = A[i-1]
        else:
            y = A[i-1]
        if [x, y, i, not turn] in L:
            C.append(D[L.index([x, y, i, not turn])])
        else:
            C.append(rec(x, y, i, not turn))
    ret = max(C) if turn else min(C)
    L.append([xp, yp, n, turn])
    D.append(ret)
    return ret


print(rec(Z, W, 0, True))
Problem p03579 (python)

Fixed submission:
N, M = map(int, input().split())
V = [[] for i in range(N+1)]
for i in range(M):
    A, B = map(int, input().split())
    V[A].append(B)
    V[B].append(A)

L = [-1]*(N+1)
L[1] = 0
al = False

from collections import deque
Open = deque()
Open.append(1)
Close = set()
while len(Open)>0:
    v = Open.pop()
    Close.add(v)
    for v2 in V[v]:
        if v2 not in Close:
            Open.append(v2)
        if L[v2] == -1:
            L[v2] = 1-L[v]
        elif L[v] + L[v2] != 1:
            al = True
            break
    if al:
        break

if al:
    print(N*(N-1)//2-M)
else:
    c = L.count(1)
    print(c*(N-c)-M)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
E = [sorted(list(map(int, input().split()))) for i in range(M)]
E.sort()
print(E)
L = [-1]*(N+1)
L[1] = 0
al = False
for e in E:
    a, b = e
    if L[b] == -1:
        L[b] = 1-L[a]
    elif L[a] + L[b] != 1:
        al = True
        break
if al:
    print(N*(N-1)//2-M)
else:
    c = L.count(1)
    print(c*(N-c)-M)
    raise ValueError()
Problem p03660 (python)

Fixed submission:
import sys
sys.setrecursionlimit(500000)
N = int(input())
Node = [[] for i in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    Node[a].append(b)
    Node[b].append(a)
Route = [1]
def dfs(n, np):
    for nc in Node[n]:
        if nc == np:
            continue
        elif nc == N:
            Route.append(N)
            return True
        else:
            Route.append(nc)
            if dfs(nc, n):
                return True
            else:
                Route.pop()
    return False

dfs(1, 0)
b = (len(Route)+1)//2
Node[Route[b-1]].remove(Route[b])
Node[Route[b]].remove(Route[b-1])

cnt = 0
def dfs2(n, np):
    global cnt
    for nc in Node[n]:
        if nc == np:
            continue
        else:
            cnt += 1
            dfs2(nc, n)

dfs2(1, 0)
cnt = -cnt
dfs2(N, 0)
if cnt >= 0:
    print("Snuke")
else:
    print("Fennec")

Buggy submission (verdict: Runtime Error):
N = int(input())
Node = [[] for i in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    Node[a].append(b)
    Node[b].append(a)


Route = [1]
def dfs(n, np):
    for nc in Node[n]:
        if nc == np:
            continue
        elif nc == N:
            Route.append(N)
            return True
        else:
            Route.append(nc)
            if dfs(nc, n):
                return True
            else:
                Route.pop()
    return False

dfs(1, 0)
b = (len(Route)+1)//2
Node[Route[b-1]].remove(Route[b])
Node[Route[b]].remove(Route[b-1])

cnt = 0
def dfs2(n, np):
    global cnt
    for nc in Node[n]:
        if nc == np:
            continue
        else:
            cnt += 1
            dfs2(nc, n)

dfs2(1, 0)
cnt = -cnt
dfs2(N, 0)
if cnt >= 0:
    print("Snuke")
else:
    print("Fennec")
Problem p03671 (python)

Fixed submission:
A = list(map(int, input().split()))
print(sum(A)-max(A))

Buggy submission (verdict: Runtime Error):
# 拡張ユークリッド互除法
# ax + by = gcd(a,b)の最小整数解を返す
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y


# mを法とするaの乗法的逆元
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

      
n = int(input())
A = list(map(int, input().split()))
C = [-1] * (n+1)
lr = 0
for i, a in enumerate(A):
    if C[a] == -1:
        C[a] = i
    else:
        lr = C[a] + n - i
        break


def combination(n, mod):
    lst = [1]
    for i in range(1, n+1):
        lst.append(lst[-1] * (n+1-i) % mod * modinv(i, mod) % mod)
    return lst


mod = 10**9+7
NC = combination(n+1, mod)
LRC = combination(lr, mod)
for i in range(1, n+2):
    print((NC[i] - (LRC[i-1] if i-1 <= lr else 0)) % mod)
Problem p03674 (python)

Fixed submission:
# 拡張ユークリッド互除法
# ax + by = gcd(a,b)の最小整数解を返す
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y


# mを法とするaの乗法的逆元
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m


n = int(input())
A = list(map(int, input().split()))
C = [-1] * (n+1)
lr = 0
for i, a in enumerate(A):
    if C[a] == -1:
        C[a] = i
    else:
        lr = C[a] + n - i
        break


def combination(n, mod):
    lst = [1]
    for i in range(1, n+1):
        lst.append(lst[-1] * (n+1-i) % mod * modinv(i, mod) % mod)
    return lst


mod = 10**9+7
NC = combination(n+1, mod)
LRC = combination(lr, mod)
for i in range(1, n+2):
    print((NC[i] - (LRC[i-1] if i-1 <= lr else 0)) % mod)

Buggy submission (verdict: Runtime Error):
    # 拡張ユークリッド互除法
    # ax + by = gcd(a,b)の最小整数解を返す
    def egcd(a, b):
        if a == 0:
            return b, 0, 1
        else:
            g, y, x = egcd(b % a, a)
            return g, x - (b // a) * y, y
     
     
    # mを法とするaの乗法的逆元
    def modinv(a, m):
        g, x, y = egcd(a, m)
        if g != 1:
            raise Exception('modular inverse does not exist')
        else:
            return x % m
     
          
    n = int(input())
    A = list(map(int, input().split()))
    C = [-1] * (n+1)
    lr = 0
    for i, a in enumerate(A):
        if C[a] == -1:
            C[a] = i
        else:
            lr = C[a] + n - i
            break
     
     
    def combination(n):
        lst = [1]
        mod = 10**9+7
        for i in range(1, n+1):
            lst.append(lst[-1] * (n+1-i) % mod * modinv(i, mod) % mod)
        return lst
     
     
    NC = combination(n+1)
    LRC = combination(lr)
    for i in range(1, n+2):
        print(NC[i] - (LRC[i-1] if i-1 <= lr else 0))
Problem p03682 (python)

Fixed submission:
import sys
sys.setrecursionlimit(500000)

N = int(input())
T = [[i] + list(map(int, input().split())) for i in range(N)]
E = [[] for i in range(N)]
E = []
T.sort(key=lambda x: x[1])
for i in range(N-1):
    s, l = T[i:i+2]
    E.append([s[0], l[0], l[1]-s[1]])
T.sort(key=lambda x: x[2])
for i in range(N-1):
    s, l = T[i:i+2]
    E.append([s[0], l[0], l[2]-s[2]])
E.sort(key=lambda x: x[2])

Par = list(range(N))
def root(x):
    if Par[x] == x:
        return x
    else:
        Par[x] = root(Par[x])
        return Par[x]

def same(x, y):
    return root(x) == root(y)

def unite(x, y):
    x = root(x)
    y = root(y)
    if x != y:
        Par[x] = y

ans = 0
for e in E:
    if not same(e[0], e[1]):
        ans += e[2]
        unite(e[0], e[1])

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
T = [[i] + list(map(int, input().split())) for i in range(N)]
E = [[] for i in range(N)]
E = []
T.sort(key=lambda x: x[1])
for i in range(N-1):
    s, l = T[i:i+2]
    E.append([s[0], l[0], l[1]-s[1]])
T.sort(key=lambda x: x[2])
for i in range(N-1):
    s, l = T[i:i+2]
    E.append([s[0], l[0], l[2]-s[2]])
E.sort(key=lambda x: x[2])

Par = list(range(N))
def root(x):
    if Par[x] == x:
        return x
    else:
        Par[x] = root(Par[x])
        return Par[x]

def same(x, y):
    return root(x) == root(y)

def unite(x, y):
    x = root(x)
    y = root(y)
    if x != y:
        Par[x] = y

ans = 0
for e in E:
    if not same(e[0], e[1]):
        ans += e[2]
        unite(e[0], e[1])

print(ans)
Problem p03714 (python)

Fixed submission:
import bisect
N = int(input())
A = list(map(int, input().split()))
L = sorted(A[:2*N])
sumL = sum(L[N:])
R = sorted(A[N:])
sumR = sum(R[:N])
AL = [sumL]
p = N
BL = [False] * (2*N)
for a in reversed(A[N:2*N]):  # sumLはだんだん減る
    ind = bisect.bisect_left(L, a)
    if BL[ind] != False:
        BL[ind] += 1
        ind += BL[ind] - 1
    if ind >= p:
        sumL -= L[ind]
        p -= 1
        while BL[p] != False:
            p -= 1
        sumL += L[p]
    AL.append(sumL)
    BL[ind] = 1
AR = [sumR]
p = N-1
BR = [False] * (2*N)
for a in A[N:2*N]:  # sumRはだんだん増える
    ind = bisect.bisect_left(R, a)
    if BR[ind] != False:
        BR[ind] += 1
        ind += BR[ind] - 1
    if ind <= p:
        sumR -= R[ind]
        p += 1
        while BR[p] != False:
            p += 1
        sumR += R[p]
    AR.append(sumR)
    BR[ind] = 1
AL.reverse()
C = [AL[i] - AR[i] for i in range(N+1)]
print(max(C))

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

L = sorted(A[:2*N])
sumL = sum(L[N:])
R = sorted(A[N:])
sumR = sum(R[:N])

AL = [sumL]
p = N
for a in reversed(A[N:2*N]):  # sumLはだんだん減る
    ind = bisect.bisect_left(L, a)
    if ind >= p:
        sumL -= L[ind]
        p -= 1
        while L[p] == False:
            p -= 1
        sumL += L[p]
    AL.append(sumL)
    L[ind] = False
AR = [sumR]
p = N-1
for a in A[N:2*N]:  # sumRはだんだん増える
    ind = bisect.bisect_left(R, a)
    if ind <= p:
        sumR -= R[ind]
        p += 1
        while R[p] == False:
            p += 1
        sumR += R[p]
    AR.append(sumR)
    R[ind] = False
AL.reverse()
C = [AL[i] - AR[i] for i in range(N+1)]
print(max(C))
Problem p03732 (python)

Fixed submission:
from collections import defaultdict
N, W = map(int, input().split())
dd = defaultdict(int)
dd[0] = 0
for i in range(N):
    w, v = map(int, input().split())
    ddOld = dd.copy()
    ddOld2 = dd.copy()
    for dk, dv in ddOld.items():
        dd[dk+w] = max(ddOld2[dk+w], dv+v)
ans = 0
for dk, dv in dd.items():
    if dk <= W:
        ans = max(ans, dv)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
N, W = map(int, input().split())
dd = defaultdict(int)
dd[0] = 0
for i in range(N):
    w, v = map(int, input().split())
    ddOld = dd.copy()
    for dk, dv in ddOld.items():
        dd[dk+w] = max(ddOld[dk+w], ddOld[dk]+v)
ans = 0
for dk, dv in dd.items():
    if dk <= W:
        ans = max(ans, dv)
print(ans)
Problem p03780 (python)

Fixed submission:
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
dp1 = np.zeros((N+1, K), dtype=bool)
dp1[0][0] = 1
for i, a in enumerate(A, 1):
    dp1[i, :] = dp1[i-1, :]
    dp1[i, a:] += dp1[i-1, :-a]
dp2 = np.zeros((N+1, K), dtype=bool)
dp2[N][0] = 1
for i, a in zip(range(N-1, -1, -1), A[::-1]):
    dp2[i, :] = dp2[i+1, :]
    dp2[i, a:] += dp2[i+1, :-a]
ans = 0
for a, d1, d2 in zip(A, dp1[:-1], dp2[1:]):
    if a >= K:
        continue
    d2_ = np.zeros(K+a, dtype=np.int32)
    d2_[a:] = d2
    d2_cum = np.cumsum(d2_)
    d2_diff = d2_cum[a:] - d2_cum[:-a]
    d = d2_diff[::-1] * d1
    if (d == 0).all():
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
dp1 = np.zeros((N+1, K), dtype=bool)
dp1[0][0] = 1
for i, a in enumerate(A, 1):
    dp1[i, :] = dp1[i-1, :]
    dp1[i, a:] += dp1[i-1, :-a]
dp2 = np.zeros((N+1, K), dtype=bool)
dp2[N][0] = 1
for i, a in zip(range(N-1, -1, -1), A[::-1]):
    dp2[i, :] = dp2[i+1, :]
    dp2[i, a:] += dp2[i+1, :-a]
ans = 0
for a, d1, d2 in zip(A, dp1[:-1], dp2[1:]):
    d2_ = np.zeros(K+a, dtype=np.int32)
    d2_[a:] = d2
    d2_cum = np.cumsum(d2_)
    d2_diff = d2_cum[a:] - d2_cum[:-a]
    d = d2_diff[::-1] * d1
    if (d == 0).all():
        ans += 1
print(ans)
Problem p03879 (python)

Fixed submission:
def norm(x1, y1, x2, y2):
    return ((x1-x2)**2 + (y1-y2)**2)**0.5
def d(a, b, c, x, y):
    return abs(a*x + b*y + c) / (a**2 + b**2)**0.5
def points2line(x1, y1, x2, y2):
    la = y1 - y2
    lb = x2 - x1
    lc = x1 * (y2 - y1) + y1 * (x1 - x2)
    return la, lb, lc
from numpy import argmax
#def argmax(L):
#    return max(enumerate(L), key=lambda x: x[1])[0]

x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
x3, y3 = map(int, input().split())

a = norm(x3, y3, x2, y2)
b = norm(x1, y1, x3, y3)
c = norm(x1, y1, x2, y2)

xc = (a*x1 + b*x2 + c*x3)/(a+b+c)
yc = (a*y1 + b*y2 + c*y3)/(a+b+c)

iw = argmax([a, b, c])
w = [a, b, c][int(iw)]

L = [[x1, y1], [x2, y2], [x3, y3]]
del L[int(iw)]
m, n = L[0]
p, q = L[1]
s, t, u = points2line(m, n, p, q)
h = d(s, t, u, xc, yc)
print(w*h/(2*h + w))

Buggy submission (verdict: Runtime Error):
def norm(x1, y1, x2, y2):
    return ((x1-x2)**2 + (y1-y2)**2)**0.5
def d(a, b, c, x, y):
    return abs(a*x + b*y + c) / (a**2 + b**2)**0.5
def points2line(x1, y1, x2, y2):
    la = y1 - y2
    lb = x2 - x1
    lc = x1 * (y2 - y1) + y1 * (x1 - x2)
    return la, lb, lc
#from numpy import argmax
def argmax(L):
    return max(enumerate(L), key=lambda x: x[1])[0]

x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
x3, y3 = map(int, input().split())

a = norm(x3, y3, x2, y2)
b = norm(x1, y1, x3, y3)
c = norm(x1, y1, x2, y2)

xc = (a*x1 + b*x2 + c*x3)/(a+b+c)
yc = (a*y1 + b*y2 + c*y3)/(a+b+c)

iw = argmax([a, b, c])
w = [a, b, c][int(iw)]

L = [[x1, y1], [x2, y2], [x3, y3]]
del L[int(iw)]
h = d(*points2line(*L[0], *L[1]), xc, yc)
print(w*h/(2*h + w))

Buggy submission (verdict: Runtime Error):
def norm(x1, y1, x2, y2):
    return ((x1-x2)**2 + (y1-y2)**2)**0.5
def d(a, b, c, x, y):
    return abs(a*x + b*y + c) / (a**2 + b**2)**0.5
def points2line(x1, y1, x2, y2):
    la = y1 - y2
    lb = x2 - x1
    lc = x1 * (y2 - y1) + y1 * (x1 - x2)
    return la, lb, lc
from numpy import argmax

x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
x3, y3 = map(int, input().split())

a = norm(x3, y3, x2, y2)
b = norm(x1, y1, x3, y3)
c = norm(x1, y1, x2, y2)

xc = (a*x1 + b*x2 + c*x3)/(a+b+c)
yc = (a*y1 + b*y2 + c*y3)/(a+b+c)

iw = argmax([a, b, c])
w = [a, b, c][int(iw)]

L = [[x1, y1], [x2, y2], [x3, y3]]
del L[int(iw)]
h = d(*points2line(*L[0], *L[1]), xc, yc)
print(w*h/(2*h + w))

Buggy submission (verdict: Runtime Error):
def norm(x1, y1, x2, y2):
    return ((x1-x2)**2 + (y1-y2)**2)**0.5
def d(a, b, c, x, y):
    return abs(a*x + b*y + c) / (a**2 + b**2)**0.5
def points2line(x1, y1, x2, y2):
    la = y1 - y2
    lb = x2 - x1
    lc = x1 * (y2 - y1) + y1 * (x1 - x2)
    return la, lb, lc
from numpy import argmax

x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
x3, y3 = map(int, input().split())

a = norm(x3, y3, x2, y2)
b = norm(x1, y1, x3, y3)
c = norm(x1, y1, x2, y2)

xc = (a*x1 + b*x2 + c*x3)/(a+b+c)
yc = (a*y1 + b*y2 + c*y3)/(a+b+c)

iw = argmax([a, b, c])
w = [a, b, c][iw]

L = [[x1, y1], [x2, y2], [x3, y3]]
del L[iw]
h = d(*points2line(*L[0], *L[1]), xc, yc)
print(w*h/(2*h + w))
Problem p03880 (python)

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

s = 0
L = [False]*44
for a in A:
    s ^= a
    c = 0
    while a&1==0:
        c += 1
        a >>= 1
    L[c] = True
if s==0:
    print(0)
    exit()
ss = "0" + bin(s)[2:]
ans = 0
for i in range(len(ss)-1):
    if ss[-1-i] != ss[-2-i]:
        if L[i]:
            ans += 1
        else:
            print(-1)
            exit()
print(ans)

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

s = 0
L = [False]*22
for a in A:
    s ^= a
    c = 0
    while a&1==0:
        c += 1
        a >>= 1
    L[c] = True
if s==0:
    print(0)
    exit()
ss = "0" + bin(s)[2:]
ans = 0
for i in range(len(ss)-1):
    if ss[-1-i] != ss[-2-i]:
        if L[i]:
            ans += 1
        else:
            print(-1)
            exit()
print(ans)
Problem p04022 (python)

Fixed submission:
import sys
from collections import Counter

def make_prime_checker(n):
    # nまでの自然数が素数かどうかを表すリストを返す  O(nloglogn)
    is_prime = [False, True, False, False, False, True] * (n//6+1)
    del is_prime[n+1:]
    is_prime[1:4] = False, True, True
    for i in range(5, int(n**0.5)+1):
        if is_prime[i]:
            is_prime[i*i::i] = [False] * (n//i-i+1)
    return is_prime

def main():
    Primes = [p for p, is_p in enumerate(make_prime_checker(2200)) if is_p]
    def decomp(n):
        res1 = res2 = 1
        for p in Primes:
            cnt = 0
            while n % p == 0:
                n //= p
                cnt += 1
            cnt %= 3
            if cnt == 1:
                res1 *= p
            elif cnt == 2:
                res2 *= p
        if int(n**0.5)**2 == n:
            res2 *= int(n**0.5)
        else:
            res1 *= n
        return res1 * res2 * res2, res1 * res1 * res2

    N, *S = map(int, sys.stdin.buffer.read().split())
    T = []
    inv_dict = {}
    for s in S:
        t, t_inv = decomp(s)
        T.append(t)
        inv_dict[t] = t_inv

    counter_T = Counter(T)
    ans = 0
    for t, t_cnt in counter_T.items():
        if t == 1:
            ans += 1
            continue
        t_inv = inv_dict[t]
        t_inv_cnt = counter_T[t_inv]
        if t_cnt > t_inv_cnt or (t_cnt == t_inv_cnt and t > t_inv):
            ans += t_cnt
    print(ans)

main()

Buggy submission (verdict: Runtime Error):
import sys
from subprocess import Popen, PIPE
from itertools import groupby
from collections import Counter

def main():
    sys.stdin.readline()
    S = sys.stdin.read()
    T = []
    inv_dict = {}
    Factors = Popen("factor " + S, stdout=PIPE).communicate()[0].split(b"\n")
    for factors in Factors:
        factors = map(int, factors.split()[1:])
        t = 1
        t_inv = 1
        for f, group in groupby(factors):
            n = len(list(group)) % 3
            if n == 1:
                t *= f
            elif n == 2:
                t_inv *= f
        t, t_inv = t * t_inv * t_inv, t * t * t_inv
        T.append(t)
        inv_dict[t] = t_inv

    counter_T = Counter(T)
    ans = 0
    for t, t_cnt in counter_T.items():
        if t == 1:
            ans += 1
            continue
        t_inv = inv_dict[t]
        t_inv_cnt = counter_T[t_inv]
        if t_cnt > t_inv_cnt or (t_cnt == t_inv_cnt and t > t_inv):
            ans += t_cnt
    print(ans)

main()
Problem p02658 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a.sort()
if a[0] == 0:
    print(0)
else:
    ans = -1
    for i in range(n):
        if(ans == -1):
            ans = a[i]
        else:
            ans *= a[i]
            if(ans > 1e18):
                ans = -1
                break
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a.sort()
if a[0] == 0:
    print(0)
else:
    ans = -1
    for i in range(n):
        if(ans == -1):
            ans = a[i]
        else:
            ans *= a[i]
            if(ans > 1e18):
                ans = -1
                break
print(ans)
Problem p02675 (python)

Fixed submission:
N = int(input())%10
if N ==3:
  print('bon')
elif N in [0,1,6,8]:
  print('pon')
else:
  print('hon')

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
import collections

sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()

N, M = nm()
adj = [[] for _ in range(N)]
for i in range(M):
    a, b = nm()
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)


def solve():
    INF = 1 << 62
    q = collections.deque([(0, 0, -1)])
    dist = [INF] * N
    prev = [None] * N
    while q:
        l, node, pnode = q.popleft()
        if dist[node] < l:
            continue
        dist[node] = l
        prev[node] = pnode
        for nxt in adj[node]:
            if nxt != pnode and dist[nxt] > l + 1:
                q.append((l + 1, nxt, node))
    if any(x is None for x in prev):
        print("No")
        return
    print("Yes")
    for i in range(1, N):
        print(prev[i] + 1)


if __name__ == "__main__":
    solve()
Problem p02702 (python)

Fixed submission:
import sys

M = 2019
S = sys.stdin.readline().rstrip()
N = len(S)

dmod = [0] * (N + 1)
amod = [0] * (N + 1)
tenmod = 1
prev_amod = 0
mcnt = [0] * 2019
ans = 0
for i in range(N, -1, -1):
    d = ord(S[i]) - ord("0") if i < N else 0
    dmod[i] = d * tenmod % M
    amod[i] = (dmod[i] + prev_amod) % M
    ans += mcnt[amod[i]]
    mcnt[amod[i]] += 1
    tenmod = tenmod * 10 % M
    prev_amod = amod[i]
print(ans)

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

def solve(S):
	M = 2019
	t = 1
	ans = 0
	c = np.zeros(M, dtype=np.int64)
	c[0] = 1
	r = 0
	for d in S:
		r = (d * t + r) % M
		ans += c[r]
		c[r] += 1
		t = t * 10 % M
	return ans



def cc_export():
	from numba.pycc import CC
	cc = CC('my_module')
    S = np.array([], dtype=np.int32)
	cc.export('solve', numba.i8(numba.typeof(S)))(solve)
	cc.compile()

if __name__ == '__main__':
	import sys
	if sys.argv[-1] == 'ONLINE_JUDGE':
		cc_export()
		exit(0)
	from my_module import solve
	S = sys.stdin.buffer.readline().decode('utf-8').rstrip()
	S = np.array([int(d) for d in S[::-1]], dtype=np.int32)
	print(solve(S))

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
S = sys.stdin.buffer.readline().decode('utf-8').rstrip()
S = np.array([int(d) for d in S[::-1]], dtype=np.int32)

def solve(S):
	M = 2019
	t = 1
	ans = 0
	c = np.zeros(M, dtype=np.int64)
	c[0] = 1
	r = 0
	for d in S:
		r = (d * t + r) % M
		ans += c[r]
		c[r] += 1
		t = t * 10 % M
	return ans



def cc_export():
	from numba.pycc import CC
	cc = CC('my_module')
	cc.export('solve', numba.i8(numba.typeof(S)))(solve)
	cc.compile()

if __name__ == '__main__':
	import sys
	if sys.argv[-1] == 'ONLINE_JUDGE':
		cc_export()
		exit(0)
	from my_module import solve
	print(solve(S))