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

Fixed submission:
from collections import deque

N, u, v = map(int, input().split())
u -= 1
v -= 1
table = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    table[a].append(b)
    table[b].append(a)

depthu = [-1] * N
depthu[u] = 0
depthv = [-1] * N
depthv[v] = 0

par = deque([u])
while par:
    p = par.popleft()
    for q in table[p]:
        if depthu[q] == -1:
            depthu[q] = depthu[p] + 1
            par.append(q)

par = deque([v])
while par:
    p = par.popleft()
    for q in table[p]:
        if depthv[q] == -1:
            depthv[q] = depthv[p] + 1
            par.append(q)

p = [i for i in range(N) if depthu[i] < depthv[i]]
if p:
    print(max(depthv[i] - 1 for i in p))
else:
    print(depthu[v] - 1)

Buggy submission (verdict: Runtime Error):
from sys import setrecursionlimit
setrecursionlimit(10101)

N, u, v = map(int, input().split())
u -= 1
v -= 1
table = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    table[a].append(b)
    table[b].append(a)

depthu = [-1] * (N)
depthu[u] = 0
depthv = [-1] * (N)
depthv[v] = 0

def dfs_depth(p, depth):
    for q in table[p]:
        if depth[q] == -1:
            depth[q] = depth[p] + 1
            dfs_depth(q, depth)

dfs_depth(v, depthv)
dfs_depth(u, depthu)

p = [i for i in range(1, N-1) if depthu[i] >= depthv[i] + 2]
if p:
    print(max(depthu[i] + (depthu[i] - depthv[i]) // 2 for i in p))
else:
    print(depthv[u] // 2)
Problem p02862 (python)

Fixed submission:
x,y = map(int,input().split())
mod = 10**9 + 7

def getComb(a,b,mod):
  if b > a:
    return 0
  if a - b > b :
    b = a - b
  comb = 1
  for i in range(b+1,a+1):
    comb = (comb * i) % mod
  d = 1
  for i in range(1,a-b+1):
    d = (d * i) % mod
  comb *= pow(d,mod-2,mod)
  return comb % mod

if x > 2*y or y > 2*x:
  print(0)
  exit()
if (x+y)%3 != 0:
  print(0)
  exit()
times = (x+y)//3
tmp = abs(x-y)
xtimes = (times - tmp) //2
ans = getComb(times,xtimes,mod)
print(ans)

Buggy submission (verdict: Runtime Error):
X,Y=map(int,input().split())

def cnb(n,k,p):
  if k>n:
    return 0
  c,d=1,1
  for i in range(k+1,n+1):
    c = (c*i)%p
  for i in range(1,k+1):
    d = (d*i)%p
  return (c*pow(d,p-2,p))%p

p=10**9+7
if X > 2*Y or Y > 2*X:
  pass
elif (X+Y)%3:
  pass
else:
  ans=cnb((X+Y)//3,(-X+2*Y)//3,p)

print(ans)
Problem p02864 (python)

Fixed submission:
N, K = map(int, input().split())
H = [0] + [int(a) for a in input().split()]
X = [[1<<100] * (N-K+1) for _ in range(N+1)]
X[0][0] = 0
for i in range(1, N+1):
    for j in range(1, min(i+1, N-K+1)):
        X[i][j] = min([X[ii][j-1] + max(H[i] - H[ii], 0) for ii in range(i)])

print(min([x[-1] for x in X]))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
H = [0] + list(map(int, input().split()))
dp = [[10 ** 100] * (N-K+1) for _ in range(N+1)]
dp[0][0] = 0
for x in range(1, N+1):
    for y in range(1, min(x+1, N-K+1)):
        dp[x][y] = min(dp[i][y-1] + max(0, H[x] - H[i]) for i in range(x))
print(min(dp[i][N-L] for i in range(1, N+1)))
Problem p02954 (python)

Fixed submission:
from itertools import groupby
S = input()
A = [len(list(it)) for s, it in groupby(S)]
for n1, n2 in zip(A[::2], A[1::2]):
    print(*([0]*(n1-1)+[(n1+1)//2+n2//2]+[n1//2+(n2+1)//2]+[0]*(n2-1)), end=" ")

Buggy submission (verdict: Runtime Error):
from itertools import groupby
S = input()
A = [len(list(it)) for s, it in groupby(S)]
B = [[0]*(n1-1)+[(n1+1)//2+n2//2]+[n1//2+(n2+1)//2]+[0]*(n2-1)
     for n1, n2 in zip(A[::2], A[1::2])]
print(*sum(B, []))from itertools import groupby
S = input()
A = [len(list(it)) for s, it in groupby(S)]
for n1, n2 in zip(A[::2], A[1::2]):
    print(*([0]*(n1-1)+[(n1+1)//2+n2//2]+[n1//2+(n2+1)//2]+[0]*(n2-1)), end=" ")
Problem p02984 (python)

Fixed submission:
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
X1 = sum(A) - 2 * sum(A[1::2])


def g():
    state = X1
    yield X1
    for i in range(N-1):
        state = 2 * A[i] - state
        yield state


print(*list(g()))

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
B = list(accumulate([0] + A[1::2] + A[::2] + [A[1]]))
C = [S - 2 * (B[i+N//2] - B[i]) for i in range(N)]
print(*sum(list(map(list, zip(C[:N//2+1], C[N//2+1:]+[0]))), [])[:-1])
Problem p02873 (python)

Fixed submission:
#!/usr/bin/env python3
import sys


def count_L_slow(S, N):
    ret=0
    for i in range(N):
        if S[i:i+1]=='>':
            ret+=1
        else:
            break
    return ret

def solve(S: str):
########################### added
    next_S = [-1 for i in range(len(S) + 1)]
    next_L = [-1 for i in range(len(S) + 1)]

    next_S[len(S)] = -1

    for i in range(len(S) - 1, -1, -1):
        if S[i] == '>':
            next_S[i] = i
        else:
            next_S[i] = next_S[i + 1]

    next_L[len(S)] = -1

    for i in range(len(S) - 1, -1, -1):
        if S[i] == '<':
            next_L[i] = i
        else:
            next_L[i] = next_L[i + 1]

###########################

    #count '<'
    def count_S(i, N):
#        ret=S.find('>')
        if i >= len(next_S):
            return N
        ret = next_S[i] - i
        if ret < 0:
            ret = N
        return ret
    
    #count '>'
    def count_L(i, N):
#        ret=S.find('<')
        if i >= len(next_L):
            return N
        ret = next_L[i] - i
        if ret < 0:
            ret = N
        return ret


#    #count '<'
#    def count_S(S, N):
#        ret=S.find('>')
#        #print("<",S,N,ret)
#        if ret==-1:
#            ret=N
#        return ret
#    
#    #count '>'
#    def count_L(S, N):
#        ret=S.find('<')
#        if ret==-1:
#            ret=N
#        #print(">",S,N,ret)
#        return ret

    answer=0

    cnt_l=count_L(0,len(S))
    answer+=int((cnt_l+1)*cnt_l/2)
    i=cnt_l


    while i<len(S):
#        cnt_s=count_S(S[i:],len(S[i:]))
#        cnt_l=count_L(S[i+cnt_s:],len(S[i+cnt_s:]))

        cnt_s=count_S(i, len(S) - i)
        cnt_l=count_L(i+cnt_s, len(S) - (i+cnt_s))

        answer+=int((cnt_s+1)*cnt_s/2)
        answer+=int((cnt_l+1)*cnt_l/2)
        if cnt_l>cnt_s:
           answer-=cnt_s
        else:
           answer-=cnt_l
        #answer+=(cnt_l+1)*cnt_l//2
        #print("cnt_s,cnt_l",cnt_s, cnt_l,answer)
        i+=cnt_s+cnt_l

    print(answer)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;


void solve(std::string S){

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}
Problem p02557 (python)

Fixed submission:
import sys
input = sys.stdin.readline

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

start = 0
ind = 0
NG = [0]*(2*N+1)

bdic = {}
for i, b in enumerate(B):
    if not b in bdic:
        bdic[b] = [i, i]
    else:
        bdic[b] = [min(bdic[b][0], i), max(bdic[b][1], i)]


for i, a in enumerate(A):
    if a in bdic:
        j1, j2 = bdic[a]
        if j1 >= i:
            NG[j1-i] += 1
            NG[j2-i+1] -= 1
        elif j2 < i:
            NG[j1-i+N] += 1
            NG[j2-i+1+N] -= 1
        else:
            NG[j1-i+N] += 1
            NG[0] += 1
            NG[j2-i+1] -= 1

start = -1
for i in range(N):
    if NG[i] == 0:
        start = i
        break
    NG[i+1] += NG[i]

if start == -1:
    print("No")
else:
    print("Yes")
    ans = []
    for i in range(N):
        ans.append(B[(i+start)%N])
    print(*ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

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

start = 0
ind = 0
for a in A:
    while start < N and B[(start+ind)%N] == a:
        start += 1
    if start >= N: break
    ind += 1

if start >= N:
    print("No")
else:
    print("Yes")
    ans = []
    for i in range(N):
        if B[(i+start)%N] == A[i]:
            raise Exception
        ans.append(B[(i+start)%N])
    print(*ans)
Problem p02634 (python)

Fixed submission:
import sys
input = sys.stdin.readline

mod = 998244353


NN = 10**4 # 使うデータによって変える

inv = [0]
for i in range(1, NN):
    inv.append(pow(i, mod-2, mod))

def main():
    A, B, C, D = map(int, input().split())
    dp = [[0]*(D+1) for _ in range(C+1)]
    dp2 = [[0]*(D+1) for _ in range(C+1)]


    for w in range(B-1, D+1):
        dp[A][w] = 0
        dp2[A][w] = pow(A, (D-B), mod)


    for c in range(A+1, C+1):
        if D - B - 1 >= 0:
            t = pow(c*inv[c-1] % mod, D-B-1, mod)
        kakeru = (c-1)*inv[c] % mod
        dp[c][B] = pow(B,c-A,mod) * pow(c, D-B, mod) % mod
        dp2[c][B] = dp[c][B]
        for d in range(B+1, D+1):
            dp[c][d] = (dp2[c-1][d-1] + dp[c-1][d]*d % mod ) * t % mod
            t = t * kakeru % mod
            dp2[c][d] = (dp2[c][d-1] + dp[c][d]) % mod

    print(dp2[C][D])


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

mod = 998244353


NN = 10**4 # 使うデータによって変える

inv = [0]
for i in range(1, NN):
    inv.append(pow(i, mod-2, mod))

def main():
    A, B, C, D = map(int, input().split())
    dp = [[0]*(D+1) for _ in range(C+1)]
    dp2 = [[0]*(D+1) for _ in range(C+1)]


    for w in range(B-1, D+1):
        dp[A][w] = 0
        dp2[A][w] = pow(A, (D-B), mod)


    for c in range(A+1, C+1):
        t = pow(c*inv[c-1] % mod, D-B-1, mod)
        kakeru = (c-1)*inv[c] % mod
        dp[c][B] = pow(B,c-A,mod) * pow(c, D-B, mod) % mod
        dp2[c][B] = dp[c][B]
        for d in range(B+1, D+1):
            dp[c][d] = (dp2[c-1][d-1] + dp[c-1][d]*d % mod ) * t % mod
            t = t * kakeru % mod
            dp2[c][d] = (dp2[c][d-1] + dp[c][d]) % mod

    print(dp2[C][D])


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

mod = 998244353

A, B, C, D = map(int, input().split())
dp = [[0]*(D+1) for _ in range(C+1)]
dp2 = [[0]*(D+1) for _ in range(C+1)]


for w in range(B-1, D+1):
    dp[A][w] = 0
    dp2[A][w] = pow(A, (D-B), mod)

for c in range(A+1, C+1):
    invc = pow(c-1, mod-2, mod)
    t = pow(c*invc, D-B-1, mod)
    kakeru = pow(invc*c, mod-2, mod)
    dp[c][B] = pow(B,c-A,mod) * pow(c, D-B, mod) % mod
    dp2[c][B] = dp[c][B]
    for d in range(B+1, D+1):
        dp[c][d] = (dp2[c-1][d-1] + dp[c-1][d]*d ) * t % mod
        t = t * kakeru % mod
        dp2[c][d] = (dp2[c][d-1] + dp[c][d]) % mod

print(dp2[C][D])
Problem p02679 (python)

Fixed submission:
import sys
input = sys.stdin.readline
import math

mod = 10**9+7

N = int(input())
As = {}
Empty = 0
for _ in range(N):
    x, y = map(int, input().split())
    g = math.gcd(x, y)
    if g == 0:
        Empty += 1
        continue
    x, y = x//g, y//g
    if y < 0 or (y==0 and x < 0):
        y = -y
        x = -x
    if (x, y) in As:
        As[(x, y)] += 1
    else:
        As[(x, y)] = 1

ans = 1
for (x, y), num in As.items():
    if (-y, x) in As:
        ans = (ans * (pow(2, num, mod) + pow(2, As[(-y, x)], mod) - 1)) % mod
    elif not (y, -x) in As:
        ans = (ans * pow(2, num, mod)) % mod

print((ans-1+Empty)%mod)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import math

mod = 10**9+7

N = int(input())
As = {}
for _ in range(N):
    x, y = map(int, input().split())
    g = math.gcd(x, y)
    x, y = x//g, y//g
    if x != 0 or y != 0:
        if y < 0 or (y==0 and x < 0):
            y = -y
            x = -x
        if (x, y) in As:
            As[(x, y)] += 1
        else:
            As[(x, y)] = 1

ans = 1
for (x, y), num in As.items():
    if (-y, x) in As:
        if x > 0:
            ans = (ans * (pow(2, num, mod) + pow(2, As[(-y, x)], mod) - 1)) % mod
    elif not (y, -x) in As:
        ans = (ans * pow(2, num, mod)) % mod

print((ans-1)%mod)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import math

mod = 10**9+7

N = int(input())
As = {}
Empty = 0
for _ in range(N):
    x, y = map(int, input().split())
    g = math.gcd(x, y)
    x, y = x//g, y//g
    if x == 0 and y == 0:
        Empty += 1
    else:
        if y < 0 or (y==0 and x < 0):
            y = -y
        if (x, y) in As:
            As[(x, y)] += 1
        else:
            As[(x, y)] = 1

M = N - Empty
ans = 1
for (x, y), num in As.items():
    if (-y, x) in As:
        if x > 0:
            ans = (ans * (pow(2, num, mod) + pow(2, As[(-y, x)], mod) - 1)) % mod
    elif not (y, -x) in As:
        ans = (ans * pow(2, num, mod)) % mod

print((ans-1)%mod)
Problem p02990 (python)

Fixed submission:
N, K = map(int, input().split()) # 横に2個

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
X = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, X + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


for i in range(1, K+1):
    ans = (cmb(N-K+1, i, mod) * cmb(K-1, i-1, mod)) % mod
    print(int(ans))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split()) # 横に2個

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

for i in range(1, K+1):
    ans = (cmb(N-K+1, i) * cmb(K-1, i-1)) % (1E9+7)
    print(int(ans))
Problem p03011 (python)

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

a1 = a+b
a2 = a+c
a3 = b+c
x = [a1, a2, a3]
print(min(x))

Buggy submission (verdict: Runtime Error):
import copy

H, W = map(int, input().split())
state = []
for i in range(H):
    row_list = list(input())
    state.append(row_list)


def light(row, col, state):
    lighted_count = 0
    col1 = copy.copy(col)
    next = '.'
    while next == '.':
        lighted_count += 1
        col1 += 1
        if col1 >= W:
            break
        next = state[row][col1]
    
    col2 = copy.copy(col)
    next = '.'
    while next == '.':
        lighted_count += 1
        col2 -= 1
        if col2 < 0:
            break
        next = state[row][col2]

    row1 = copy.copy(row)
    next = '.'
    while next == '.':
        lighted_count += 1
        row1 += 1
        if row1 >= H:
            break
        next = state[row1][col]

    row2 = copy.copy(row)
    next = '.'
    while next == '.':
        lighted_count += 1
        row2 -= 1
        if row2 < 0:
            break
        next = state[row2][col]

    lighted_count -= 3
    return lighted_count



def blank_fun(state):
    blank_list = []
    for h in range(H):
        for w in range(W):
            if state[h][w] == '.':
                blank_list.append([h, w])
    return blank_list


blank_list = blank_fun(state)
blank_count = 0
for blank in blank_list:
    row = blank[0]
    col = blank[1]
    blank_count_now = light(row, col, state)

    if blank_count_now > blank_count:
        blank_count = blank_count_now


print(blank_count)
Problem p03327 (python)

Fixed submission:
N = int(input())

if N < 1000:
    print('ABC')
else:
    print('ABD')

Buggy submission (verdict: Runtime Error):
N, C = map(int, input().split())
D = [list(map(int, input().split())) for _ in range(C)]
grid = [list(map(int, input().split())) for _ in range(N)]

def main():
    state = [[0 for _ in range(C)] for _ in range(3)]
    for c in range(C):
        for w in range(N):
            for h in range(N):
                cost = D[grid[h][w]-1][c]
                state[(h+w)%3][c] += cost

    for c1 in range(C):
        for c2 in range(C):
            if c1 == c2:
                continue
            for c3 in range(C):
                if c3 == c1 or c3 == c2:
                    continue
                cost = state[0][c1] + state[1][c2] + state[2][c3]
                if c1 == 0 and c2 == 1 and c3 == 2:
                    ans = cost
                    continue
                ans = min(cost, ans)
    print(ans)

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

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


if K == 1:
    if A[0] == 2:
        print(2, 3)
    else:
        print(-1)
else:
    M = 2
    L = 2
    ok = True
    for i in range(K-1, -1, -1):
        a = A[i]
        nM = (M//a)*a
        if M%a != 0:
            nM += a
        nL = (L//a)*a + a - 1
        if nM >= M + a or nM > nL:
            ok = False
            break
        
        L, M = nL, nM
        #print(L, M, a, b)

    if not ok:
        print(-1)
    else:
        print(M, L)

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

M = 2
L = 2
ok = True
for i in range(K-1, 0, -1):
    a, b = A[i], A[i-1]
    nM = (M//b)*b
    if M%b != 0:
        nM += b
    if nM >= M + a:
        ok = False
        break
    
    nL = (L+a-1)//b * b
    L, M = nL, nM

if not ok:
    print(-1)
else:
    L = L + b-1
    print(M, L)
Problem p03618 (python)

Fixed submission:
from collections import Counter
import sys
sys.setrecursionlimit(5000000)

S = list(input())
L = len(S)
A = Counter(S)

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

if L == 1:
    print(1)
else:
    ans = cmb(L, 2) + 1
    for v in A.values():
        if v == 1: continue
        ans -= cmb(v, 2)
    print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
import sys
sys.setrecursionlimit(5000000)

S = list(input())
L = len(S)
A = Counter(S)

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

ans = cmb(L, 2) + 1
for v in A.values():
    if v == 1: continue
    ans -= cmb(v, 2)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
import sys
sys.setrecursionlimit(1000000)

S = list(input())
L = len(S)
A = Counter(S)

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

ans = cmb(L, 2) + 1
for v in A.values():
    if v == 1: continue
    ans -= cmb(v, 2)
print(ans)
Problem p03726 (python)

Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

q = []
checked = [-1]*N
for n in range(N):
    if len(graph[n]) == 1:
        q.append(n)
        checked[n] = 0

ok = False
while q:
    posiq = []
    for p in q:
        update = False
        for np in graph[p]:
            if checked[np] == -1:
                checked[np] = checked[p] + 1
                update = True
                posiq.append(np)
            elif checked[np] == checked[p] + 1:
                ok = True
                break
            elif checked[np] == checked[p]:
                update = True
        if not update:
            ok = True
            break
    
    q = set()
    for p in posiq:
        for np in graph[p]:
            if checked[np] == -1 and not np in q:
                c = 0
                for mp in graph[np]:
                    if checked[mp] == -1:
                        c += 1
                    if c >= 2: break
                if c <= 1:
                    q.add(np)
    for np in q:
        checked[np] = checked[p] + 1

print("First" if ok else "Second")

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

q = []
checked = [-1]*N
for n in range(N):
    if len(graph[n]) == 1:
        q.append(n)
        checked[n] = 0

ok = False
while q:
    posiq = []
    for p in q:
        update = False
        for np in graph[p]:
            if checked[np] == -1:
                checked[np] = checked[p] + 1
                update = True
                posiq.append(np)
            elif checked[np] == checked[p] + 1:
                ok = True
                break
            elif checked[np] == checked[p]:
                update = True
        if not update:
            ok = True
            break
    
    q = set()
    for p in posiq:
        for np in graph[p]:
            if checked[np] == -1 and not np in q:
                c = 0
                for mp in graph[np]:
                    if checked[mp] == -1:
                        c += 1
                    if c >= 2: break
                if c <= 1:
                    q.append(np)
    for np in q:
        checked[np] = checked[p] + 1

print("First" if ok else "Second")
Problem p02935 (python)

Fixed submission:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
v = na()
v.sort()

s = 0
for i in range(n):
    s = s * 0.5 + v[i]
    if i == 0:
        s += v[i]
print("{:.14f}".format(s*0.5))

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
v = na()
v.sort()

s = 0
for i in range(n):
    s = s * 0.5 + v[i]
    if i == 0:
        s += v[i]
print(f"{s*0.5:.14f}")
Problem p02948 (python)

Fixed submission:
import sys
from operator import itemgetter

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
ab = []
for i in range(n):
    ab.append(na())

ab.sort(key=itemgetter(0))

pq = []
import  heapq

ans = 0
p = 0
for i in range(m+1):
    while p < n and ab[p][0] <= i:
        heapq.heappush(pq, -ab[p][1])
        p += 1

    if len(pq) == 0:
        continue

    ans -= heapq.heappop(pq)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
ab = []
for i in range(n):
    ab.append(na())

ab.sort(key=itemgetter(0))

pq = []
import  heapq

ans = 0
p = 0
for i in range(m+1):
    while p < n and ab[p][0] <= i:
        heapq.heappush(pq, -ab[p][1])
        p += 1

    if len(pq) == 0:
        continue

    ans -= heapq.heappop(pq)

print(ans)