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

Fixed submission:
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
if n >= m:
    print(0)
    exit()

cost = []
for i in range(m-1):
    cost.append(x[i+1] - x[i])

cost.sort()
ans = 0
for i in range(m-n):
    ans += cost[i]
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
if n >= m:
    print(0)
    exit()

cost = []
for i in range(m-1):
    cost.append(x[i] - x[i+1])

l = sorted(cost)
ind = [0]
for i in range(n-1):
    ind.append(cost.index(l[i]) + 1)
ind.append(m)
ind.sort()

X = []
for i in range(n):
    X.append(x[ind[i]:ind[i+1]])

ans = 0
for i in X:
    ans += i[-1] - i[0]
print(ans)

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

if n >= m:
    print(0)
    exit()
    
cost = []
for i in range(m-1):
    cost.append(x[i] - x[i+1])

l = sorted(cost)
ind = [0]
for i in range(n-1):
    ind.append(cost.index(l[i]) + 1)
ind.append(m)

X = []
for i in range(n):
    X.append(x[ind[i]:ind[i+1]])

ans = 0    
for i in X:
    ans += i[-1] - i[0]

print(ans)
Problem p03785 (python)

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

n, c, k = map(int, input().split())
t = sorted([int(input()) for _ in range(n)])


def AirportBus(x=0,ans=0):
    y = x
    for i in range(x, n):
        if t[x]+k < t[i] or i - x >= c:
          y = i
          break
    if y == x:
      print(ans+1)
      return
    ans += 1
    AirportBus(y,ans)
    
AirportBus()

Buggy submission (verdict: Runtime Error):
import bisect
n, c, k = map(int, input().split())
t = sorted([int(input()) for _ in range(n)])


def AirportBus(x=0, y=0):
    if x == n:
        return    
    y = min(bisect.bisect(t, t[x]+k), x+3)
    l.append(t[x:y])
    AirportBus(y)
    
l = []    
AirportBus()

print(len(l))

Buggy submission (verdict: Runtime Error):
n, c, k = map(int, input().split())
t = sorted([int(input()) for _ in range(n)])


def AirportBus(x=0):
    y = x
    for i in range(x, n):
        if t[x]+k < t[i] or i-x >= c:
            y = i
            break
    if y == x:
        l.append(t[x:n])
        return
    l.append(t[x:y])
    AirportBus(y)
    
l = []    
AirportBus()

print(len(l))

Buggy submission (verdict: Runtime Error):
n, c, k = map(int, input().split())
t = sorted([int(input()) for _ in range(n)])


def AirportBus1(x=0):
    y = x
    for i in range(x, n):
        if t[x]+k < t[i] or i-x >= c:
            y = i
            break
    if y == x:
        l.append(t[x:n])
        return
    l.append(t[x:y])
    AirportBus1(y)
    
def AirportBus2(x=0):
    y = x
    for i in range(x, n):
        if t[x]-k > t[i] or i-x >= c:
            y = i
            break
    if y == x:
        r.append(t[x:n])
        return
    r.append(t[x:y])
    AirportBus2(y)

l = []    
AirportBus1()
t.sort(reverse = True)
r = []
AirportBus2()

ans1 = 0
for lis in l:
    ans1 += -(-len(lis) // c)

ans2 = 0
for lis in r:
    ans2 += -(-len(lis) // c)

print(min(ans1,ans2))

Buggy submission (verdict: Runtime Error):
n, c, k = map(int, input().split())
t = sorted([int(input()) for _ in range(n)], reverse = True)

l = []
def AirportBus(x=0):
    y = x
    for i in range(x, n):
        if t[x]-k > t[i]:
            y = i
            break
    if y == x:
        l.append(t[x:n])
        return
    l.append(t[x:y])
    AirportBus(y)
    
AirportBus()

ans = 0
for lis in l:
    ans += -(-len(lis) // c)

print(ans)

Buggy submission (verdict: Runtime Error):
n, c, k = map(int, input().split())
t = sorted([int(input()) for _ in range(n)])

l = []
def AirportBus(x=0):
    y = x
    for i in range(x, n):
        if t[x]+k < t[i]:
            y = i
            break
    if y == x:
        l.append(t[x:n])
        return
    l.append(t[x:y])
    AirportBus(y)
    
AirportBus()

ans = 0
for lis in l:
    ans += -(-len(lis) // c)

print(ans)
Problem p02735 (python)

Fixed submission:
h, w = map(int, input().split())
s = [input() for _ in range(h)]

INF = 10**9
dp = [[INF]*w for _ in range(h)]

dp[0][0] = 0 if s[0][0] == "." else 1

for i in range(h):
    for j in range(w):
        d, r = INF, INF

        if i != 0:
            d = dp[i - 1][j] + (s[i - 1][j] == "." and s[i][j] == "#")
        if j != 0:
            r = dp[i][j - 1] + (s[i][j - 1] == "." and s[i][j] == "#")

        dp[i][j] = min(r, d, dp[i][j])

print(dp[h-1][w-1])

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [input() for _ in range(h)]
INF = 10**9
dp = [[INF]*w for _ in range(h)]

dp[0][0] = 0 if s[0][0] == "." else 1

for i in range(w):
    for j in range(h):
        d, r = INF, INF

        if i != 0:
            r = dp[i - 1][j] + (s[i - 1][j] == "." and s[i][j] == "#")
        if j != 0:
            d = dp[i][j - 1] + (s[i][j - 1] == "." and s[i][j] == "#")

        dp[i][j] = min(r, d, dp[i][j])

print(dp[w-1][h-1])
Problem p02762 (python)

Fixed submission:
N,M,K = map(int,input().split())
#follow = [[False for i in range(N)] for j in range(N)]
follow = [[] for _ in range(N)]
labels = [-1 for _ in range(N)]
edges = [0 for _ in range(N)]

for i in range(M):
    A,B = map(int,input().split())
    A = A-1
    B = B-1
    follow[A].append(B)
    follow[B].append(A)
    edges[A] = edges[A] + 1
    edges[B] = edges[B] + 1

c = 0
for i in range(N):
    if (labels[i] == -1):
        s = []
        s.append(i)
        labels[i] = c
        while(len(s) != 0):
            u = s.pop()
            for i in range(len(follow[u])):
                if (labels[follow[u][i]] == -1):
                    labels[follow[u][i]] = c
                    s.append(follow[u][i])
        c += 1

groupV = [0]*(c+1)
for i in range(N):
    groupV[labels[i]] = groupV[labels[i]] + 1

for i in range(K):
    C,D = map(int,input().split())
    C = C-1
    D = D-1
    if (labels[C] != labels[D]) : continue
    edges[C] = edges[C] + 1
    edges[D] = edges[D] + 1

ans = ["0"]*N

for i in range(N):
    ans[i] = str(groupV[labels[i]] - 1 - edges[i])

print(" ".join(ans))

Buggy submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse.csgraph import connected_components
N,M,K = map(int,input().split())
follow = [[False for i in range(N)] for j in range(N)]
block = [[False for i in range(N)] for j in range(N)]
edges = [0 for i in range(N)]

for i in range(M):
    A,B = map(int,input().split())
    A = A-1
    B = B-1
    follow[A][B] = True
    follow[B][A] = True
    edges[A] = edges[A] + 1
    edges[B] = edges[B] + 1

n,labels = connected_components(np.array(follow))

groupV = [0]*n
for i in range(N):
    groupV[labels[i]] = groupV[labels[i]] + 1

for i in range(K):
    C,D = map(int,input().split())
    C = C-1
    D = D-1
    if (labels[C] != labels[D]) : continue
    block[C][D] = True
    block[D][C] = True
    edges[C] = edges[C] + 1
    edges[D] = edges[D] + 1

ans = ["0"]*N

for i in range(N):
    ans[i] = str(groupV[labels[i]] - 1 - edges[i])

print(" ".join(ans))

Buggy submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse.csgraph import connected_components
N,M,K = map(int,input().split())
follow = [[False for i in range(N)] for j in range(N)]
block = [[False for i in range(N)] for j in range(N)]
edges = [0 for i in range(N)]

for i in range(M):
    A,B = map(int,input().split())
    A = A-1
    B = B-1
    follow[A][B] = True
    follow[B][A] = True
    edges[A] = edges[A] + 1
    edges[B] = edges[B] + 1

n,labels = connected_components(np.array(follow))

groupV = [0]*n
for i in range(N):
    groupV[labels[i]] = groupV[labels[i]] + 1

for i in range(K):
    C,D = map(int,input().split())
    C = C-1
    D = D-1
    if (labels[C] != labels[D]) : continue
    block[C][D] = True
    block[D][C] = True
    edges[C] = edges[C] + 1
    edges[D] = edges[D] + 1

ans = ["0"]*N

for i in range(N):
    ans[i] = str(groupV[labels[i]] - 1 - edges[i])

print(" ".join(ans))
Problem p02820 (python)

Fixed submission:
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()

# 相手の手がkeyだった時に勝つと得られるポイント
score = {"s":R,"p":S,"r":P}
# K手前が同じ手だったフラグ
flag = [False for i in range(N)]
ans = 0
for i in range(N):
    if (flag[i]):
        pass
    else:
        ans += score[T[i]]
        if (N-i-1 >= K):
            if (T[i] == T[i+K]):
                flag[i+K] = True

print(ans)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()

# 相手の手がkeyだった時に勝つと得られるポイント
score = {"s":R,"p":S,"r":P}
# K手前が同じ手だったフラグ
flag = [False for i in range(N)]
ans = 0
for i in range(N):
    if (flag[i]):
        s += "l"
    else:
        ans += score[T[i]]
        s += "w"
        if (N-i-1 >= K):
            if (T[i] == T[i+K]):
                flag[i+K] = True

print(ans)
Problem p02912 (python)

Fixed submission:
import math
import heapq

N,M = map(int,input().split())
A = [0]*N
A = list(map(lambda x: int(x)*(-1),input().split()))
if (N == 1):
    print((-1 * A[0])//(2**M))
else:
    """
    while (M != 0):
        A.sort(reverse=True)
        y = min(math.floor(log2(A[0]/A[1])+1),M)
        A[0] //= 2**y
        M -= y
    """
    """
    A.sort(reverse=True)
    for i in range(N):
        y = min(A[i] // 2,M)
        A[i] //= 2**y
        M -= y
        if (M <= 0):
            break
    """
    heapq.heapify(A)

    for i in range(M):
        m = heapq.heappop(A) * -1
        heapq.heappush(A,(m//2 * -1))

    print(-sum(A))

Buggy submission (verdict: Runtime Error):
import math

N,M = map(int,input().split())
A = [0]*N
A = list(map(int,input().split()))
if (N == 1):
    print(A[0]//(2**M))
else:
    while (M != 0):
        A.sort(reverse=True)
        y = min(math.floor(math.log2(A[0]/A[1])+1),M)
        A[0] //= 2**y
        M -= y

    print(sum(A))
Problem p02793 (python)

Fixed submission:
import fractions
from functools import reduce

def gcd(*numbers):
  return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
  return reduce(fractions.gcd, numbers)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

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

mod = 10 ** 9 + 7

l = lcm_list(A)

ans = 0

for i in range(N):
  ans += l // A[i]

ans = ans % mod

print(ans)

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

def lcm_core(a,b):
    g = np.gcd(a,b)
    return (a*b)//g

def gcd_core(a, b):
    if b == 0:
        return a
    else:
        return gcd_core(b, a % b)

def lcm(arr):
    m = 10**9+7
    mcnt = 0
    l = lcm_core(arr[0],arr[1])
    for i in range(2,len(arr)):
        l = lcm_core(l,arr[i])
        mcnt += l//m
        l %= m
    return l,mcnt

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

# print(l,mcnt)

# print(l)
m = 10**9+7

ans = 0
for i in range(n):
    temp = l + (m%arr[i])*mcnt
    # print(temp)
    ans += (temp//arr[i]) + (m//arr[i])*mcnt
    ans %= m

print(ans)

Buggy submission (verdict: Runtime Error):
def lcm_core(a,b):
    g = gcd_core(a,b)
    return (a*b)//g

def gcd_core(a, b):
    if b == 0:
        return a
    else:
        return gcd_core(b, a % b)

def lcm(arr):
    m = 10**9+7
    mcnt = 0
    l = lcm_core(arr[0],arr[1])
    for i in range(2,len(arr)):
        l = lcm_core(l,arr[i])
        mcnt += l//m
        l %= m
    return l,mcnt

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

# print(l)
m = 10**9+7

ans = 0
for i in range(n):
    temp = l + (m%arr[i])*mcnt
    # print(temp)
    ans += (temp//arr[i]) + (m//arr[i])*mcnt
    ans %= m

print(ans)

Buggy submission (verdict: Runtime Error):
def lcm_core(a,b):
    g = gcd_core(a,b)
    return (a*b)//g

def gcd_core(a, b):
    if b == 0:
        return a
    else:
        return gcd_core(b, a % b)

def lcm(arr):
    l = lcm_core(arr[0],arr[1])
    for i in range(2,len(arr)):
        l = lcm_core(l,arr[i])
    return l

n = int(input())
arr = list(map(int,input().split()))
l = lcm(arr)
ans = 0
m = 10**9+7
for i in range(n):
    ans += l//arr[i]
    ans %=  m
print(ans)
Problem p02984 (python)

Fixed submission:
import numpy as np





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


#
# if n <= 3:
#     ans = np.linalg.solve(A, arr)
#
#     for i in range(n - 1):
#         print(int(ans[i]), end=" ")
#
#     print(int(ans[n - 1]))
# else:

odd = 0
eq = 0
all = [0,0]

for i in range(n):
    if i % 2 == 0:
        eq += arr[i]
        all.append(eq)
    else:
        odd += arr[i]
        all.append(odd)


ans = [0 for i in range(n)]

base = eq-odd
base2 = odd-eq+2*arr[0]
for i in range(n):
    if i %2 ==  0:
        ans[i] = base
        if i == n-1:
            break
        base -= 2*arr[i]
        base += 2* arr[i+1]


    if i %2 ==  1:
        ans[i] =base2
        base2 -= 2*arr[i]
        base2 += 2*arr[i+1]



for i in range(n-1):
    print(ans[i],end=" ")
print(ans[-1])

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





n = int(input())
arr = list(map(int,input().split()))
arr = np.array(arr)
A = np.zeros((n,n))

for i in range(n-1):
    A[i][i] = 0.5
    A[i][i+1] = 0.5
A[n-1][n-1] = 0.5
A[n-1][0] = 0.5

# print(A)
ans = np.linalg.solve(A, arr)

for i in range(n-1):
    print(int(ans[i]),end=" ")

print(int(ans[n-1]))

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


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  # 出力の制限
N = 10 ** 4
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

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


n = int(input())
arr = list(map(int,input().split()))
arr = np.array(arr)
A = np.zeros((n,n))

for i in range(n):
    A[i][i] = 0.5
    A[i][i-1] = 0.5

ans = np.linalg.solve(A, arr)

for i in range(n-1):
    print(int(ans[i-1]),end=" ")

print(int(ans[n-1]))
Problem p03017 (python)

Fixed submission:
import copy
N,A,B,C,D = map(int,input().split())
S = input()

for i in range(A,max(C,D)-1):
    if S[i:i+2] == "##":
        print("No")
        exit(0)

if C > D:
    flag = False
    for i in range(B-1,D):
        if S[i-1:i + 2] == "...":
            flag = True
            break

    if flag == False:
        print("No")
        exit(0)

print("Yes")

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

can_reach = True
bef = False
for i in range(a,c):
    if s[i] == "#":
        if bef:
            can_reach = False
        else:
            bef = True
    else:
        bef = False

bef = False
for i in range(b,d):
    if s[i] == "#":
        if bef == True:
            can_reach = False
        else:
            bef = True
    else:
        bef = False

if can_reach:
    if c < d:
        print("Yes")
    else:
        can_over = False
        bef1 = False
        bef2 = False
        for i in range(b-1,c+1):
            if s[i] == ".":
                if bef1:
                    if bef2:
                        can_over = True
                    else:
                        bef2 = True
                else:
                    bef1 = True
            else:
                bef1 = False
                bef2 = False
        if can_over:
            print("Yes")
        else:
            print("No")
else:
    print("No")
Problem p03045 (python)

Fixed submission:
class UnionFind():
    '''UnionFind木'''

    def __init__(self, n):
        self.data = [-1] * n

    def unite(self, x, y):
        '''x と y を結合'''
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.data[x] < self.data[y]:
            x, y = y, x  # swap
        self.data[x] += self.data[y]
        self.data[y] = x

    def find(self, x):
        '''ノード x の親を返す'''
        if self.data[x] < 0:
            return x
        self.data[x] = self.find(self.data[x])
        return self.data[x]

    def same(self, x, y):
        '''x と y が同じグループに属するか判定'''
        return self.find(x) == self.find(y)

    def size(self, x):
        '''x を含むグループのノード数を返す'''
        return self.data[self.find(x)]
    def indep(self):
        dep = 0
        for i in range(len(self.data)):
            if self.data[i] < 0:
                dep += 1
        return dep


n,m = map(int,input().split())
uf = UnionFind(n+1)
for i in range(m):
    x,y,z = map(int,input().split())
    uf.unite(x,y)

print(uf.indep()-1)

Buggy submission (verdict: Runtime Error):
class uf_tree():

    def __init__(self,n):
        self.n = n
        self.par = [i for i in range(n)]

    def indep(self):
        dep =0
        for i in range(self.n):
            if i == self.par[i]:
                dep += 1

        return dep

    def unite(self,child,mas):
        if self.root(child) == self.root(mas):
            return
        else:
            self.par[self.root(child)] = self.root(self.mas)

    def root(self,i):
        if self.par[i] == i:
            return i
        else:
            self.par[i] = self.root(self.par[i])
            return self.par[i]

    def same(self,x,y):
        if self.root(x) == self.root(y):
            return True
        else:
            return False



n,m = map(int,input().split())
uf = uf_tree(n+1)
for i in range(m):
    x,y,z = map(int,input().split())
    uf.unite(x,y)

print(uf.indep()-1)
Problem p03127 (python)

Fixed submission:
def gcd_core(a,b):
    if b == 0:
        return a
    else:
        return gcd_core(b,a%b)

def gcd(arr):
    g = gcd_core(arr[0],arr[1])
    for i in range(2,len(arr)):
        g = gcd_core(g,arr[i])
    return g

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

print(gcd(a))

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

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

print(np.gcd.reduce(a))
Problem p02688 (python)

Fixed submission:
def main(n, a):
    indexes = {i + 1 for i in range(n)}
    reduced = set()
    for s in a:
        reduced |= s
    return len(indexes - reduced)


if __name__ == '__main__':
    N, K = map(int, input().split())
    A = []
    for _ in range(K):
        input()
        A.append(set(tuple(map(int, input().split(' ')))))
    print(main(N, A))

Buggy submission (verdict: Runtime Error):
def main(n, a):
    indexes = {i + 1 for i in range(n)}
    reduced = set()
    for s in a:
        reduced |= s
    return len(indexes - reduced)


if __name__ == '__main__':
    S = input().rstrip()
    N, K = map(int, input().split())
    A = []
    for _ in range(K):
        input()
        A.append(set(tuple(map(int, input().split(' ')))))
    print(main(N, A))

Buggy submission (verdict: Runtime Error):
def main(n, a):
    indexes = {i + 1 for i in range(n)}
    reduced = set()
    for s in a:
        reduced |= s
    return len(indexes - reduced)


if __name__ == '__main__':
    S = input().rstrip()
    N, K = map(int, input().split())
    A = []
    for _ in range(K):
        input()
        A.append(set(tuple(map(int, input().split(' ')))))
    print(main(N, A))
Problem p03768 (python)

Fixed submission:
from sys import stdin, stderr
from collections import deque

def solve():
    N, M = map(int, input().split())

    Adj = [[] for i in range(N)]

    for i in range(M):
        a, b = map(int, stdin.readline().split())
        a, b = a - 1, b - 1
        Adj[a].append(b)
        Adj[b].append(a)

    Q = int(stdin.readline())

    v = [0] * Q
    d = [0] * Q
    c = [0] * Q

    for i in range(Q):
        v[i], d[i], c[i] = map(int, stdin.readline().split())
        v[i] -= 1

    v.reverse()
    d.reverse()
    c.reverse()

    cols = [0] * N
    nuta = [-1] * N

    for i in range(Q):
        bfs(N, Adj, v[i], d[i], c[i], cols, nuta)

    print(*cols, sep='\n')

def bfs(N, Adj, v, d, c, cols, nuta):
    if nuta[v] >= d:
        return

    nxts = deque([[v, d]])
    nuta[v] = d

    while nxts:
        u, step = nxts.popleft()

        if step < 0:
            continue

        if cols[u] == 0:
            cols[u] = c

        for w in Adj[u]:
            if nuta[w] < step - 1:
                nuta[w] = step - 1
                nxts.append([w, step - 1])

    return

if __name__ == '__main__':
    solve()

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

def solve():
    N, M = map(int, input().split())

    Adj = [[] for i in range(N)]

    for i in range(M):
        a, b = map(int, stdin.readline().split())
        a, b = a - 1, b - 1
        Adj[a].append(b)
        Adj[b].append(a)

    Q = int(stdin.readline())

    assert 1 <= N <= 2000
    assert 1 <= M <= 2000
    assert 1 <= Q <= 2000
    
    v = [0] * Q
    d = [0] * Q
    c = [0] * Q

    for i in range(Q):
        v[i], d[i], c[i] = map(int, stdin.readline().split())
        v[i] -= 1

    cols = [0] * N

    for i in range(Q):
        bfs(N, Adj, v[i], d[i], c[i], cols)

    print(*cols, sep='\n')

def bfs(N, Adj, v, d, c, cols):
    visited = [False] * N
    visited[v] = True

    nxts = deque([[v, 0]])

    while nxts:
        u, dis = nxts.popleft()

        if dis > d:
            continue

        cols[u] = c

        for w in Adj[u]:
            if not visited[w]:
                visited[w] = True
                nxts.append([w, dis + 1])

    return

if __name__ == '__main__':
    solve()
Problem p03822 (python)

Fixed submission:
import sys

limit = 10 ** 5 * 2
sys.setrecursionlimit(limit)

def calc_depth(n):
    if children[n] == set():
        return 0

    depth_l = [calc_depth(child) for child in children[n]]
    depth_l.sort(reverse=True)

    return max(depth + (i+1) for (i, depth) in enumerate(depth_l))

N = int(input())

children = [set() for i in range(N + 1)]

for i in range(N - 1):
    a = int(input())
    children[a].add(i + 2)

ans = calc_depth(1)

# print(children)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys

def calc_depth(n):
    if children[n] == set():
        return 0

    depth_l = [calc_depth(child) for child in children[n]]
    depth_l.sort(reverse=True)

    return max(depth + (i+1) for (i, depth) in enumerate(depth_l))

N = int(input())

children = [set() for i in range(N + 1)]

for i in range(N - 1):
    a = int(input())
    children[a].add(i + 2)

ans = calc_depth(1)

# print(children)

print(ans)
Problem p03834 (python)

Fixed submission:

s = input().split(",")

print(*s)

Buggy submission (verdict: Runtime Error):
K, S = map(int, input().split())
wariate = 0

for x in range(0, K + 1):
    if S - x <= K:
        wariate += max(S - x + 1, 0)
    else:
        wariate += max(0, 2 * K - (S - x) + 1)

print(wariate)
Problem p03013 (python)

Fixed submission:
modulo=10**9+7
n, m=map(int, input().split())
a_list=[]
for i in range(m):
    a=int(input())
    a_list.append(a)
a_list.append(-1)
dp=[0 for i in range(n+1)]#0~n
dp[0]=1
if a_list[0]==1:
    dp[1]=0
    j=1
    for i in range(2, n+1):#10^5
        if i!=a_list[j]:
            dp[i]=(dp[i-2]+dp[i-1])%modulo
        else:
            j=j+1
else:
    dp[1]=1
    j=0
    for i in range(2, n+1):#10^5
        if i!=a_list[j]:
            dp[i]=(dp[i-2]+dp[i-1])%modulo
        else:
            j=j+1

print(dp[n]%modulo)

Buggy submission (verdict: Runtime Error):
modulo=10**9+7
n, m=map(int, input().split())
a_list=[]
for i in range(m):
    a=int(input())
    a_list.append(a)
dp=[0 for i in range(n+1)]#0~n
dp[0]=1
if a_list[0]==1:
    dp[1]=0
else:
    dp[1]=1

for i in range(2, n+1):
    if not i in a_list:
        dp[i]=(dp[i-2]+dp[i-1])%modulo
print(dp[n]%modulo)

Buggy submission (verdict: Runtime Error):
modulo=10**9+7
n, m=map(int, input().split())
a_list=[]
for i in range(m):
    a=int(input())
    a_list.append(a)
dp=[0 for i in range(n+1)]#0~n
dp[0]=1
if a_list[0]==1:
    dp[1]=0
else:
    dp[1]=1

for i in range(2, n+1):
    if not i in a_list:
        dp[i]=dp[i-2]+dp[i-1]
print(dp[n]%modulo)