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

Fixed submission:
import math

s = input()
n = len(s)

l = math.floor(n/2)
if n % 2 == 0:
  k = l
else:
  k = l+1
  

s_f = s[:l]
s_r = s[k:]
j = 0

#print(s_f)
#print(s_r)

for i in range(0,l):
  if s_f[i] != s_r[(l-1)-i]:
    #print(s_f[i] + " " + s_r[(l-1)-i])
    j+=1
    
print(j)

Buggy submission (verdict: Runtime Error):
import math

s = input()
n = len(s)

l = math.floor(n/2)
if n % 2 == 0:
  k = l
else:
  k = l+1
  

s_f = s[:l]
s_r = s[k:]
j = 0

for i in [0,l-1]:
  if s_f[i] != s_r[(l-1)-i]:
    j+=1
    
print(j)
Problem p02790 (python)

Fixed submission:
Input = input().split()
Input[0] = int(Input[0])
Input[1] = int(Input[1])
 
if Input[0] >= Input[1]:
  print(str(Input[1])*Input[0])
  
else:
  print(str(Input[0])*Input[1])

Buggy submission (verdict: Runtime Error):
Input = input().split()
Input[0] = int(Input[0])
Input[1] + int(Input[1])

if Input[0] >= Input[1]:
  print(str(Input[1])*Input[0])

else:
  print(str(Input[0])*Input[1])

Buggy submission (verdict: Runtime Error):
Input = input().spilit()
Input[0] = int(Input[0])
Input[1] = int(Input[1])

i = 0

if Input[0] > Input[1]:
  print(str(Input[0])*Input[1])

elif Input[1] > Input[0]:
  print(str(Input[1])*Input[0])

else:
  print(str(Input[0])*Input[0])
Problem p02933 (python)

Fixed submission:
a = int(input())
s = input()
print(s if a>=3200 else 'red')

Buggy submission (verdict: Runtime Error):
# REになった
# 各ルートの4方向で行ってないところを覚えるのではなく、すでに行ったマスのみをマークするようにする
# line input as int generator
def li():
    return map(int, input().split())


H, W = li()
# C = [input().split() for _ in range(H)]
C = [['' for _ in range(W)] for _ in range(H)]
# すでに行った道など、もう通らない道
route = []
for h in range(H):
    for w, c in enumerate(input()):
        C[h][w] = c
        if c == '#':
            route.append((h,w))
        # if h-1 >= 0:
        #     route[(h, w)].append((h - 1, w))
        # if h+1 < H:
        #     route[(h, w)].append((h + 1, w))
        # if w-1 >= 0:
        #     route[(h, w)].append((h, w - 1))
        # if w+1 < W:
        #     route[(h, w)].append((h, w + 1))
        if c == 's':
            start = (h, w)
# print(route)

def dfs(now):
    h, w = now
    # print(now)
    # if not ((0 <= h < H) and (0 <= w < W)):
    #     return False
    # print(route[now])
    if (h,w) in route:
        return False
    if C[h][w] == 'g':
        # OK!
        return True
    # elif C[h][w] == '#':
    #     return False
    else:
        # append
        route.append((h,w))
        if h-1 >= 0 and ((h-1,w) not in route):
            if dfs((h-1,w)):
                return True
        if h+1 < H and ((h+1,w) not in route):
            if dfs((h+1,w)):
                return True
        if w-1 >= 0 and ((h,w-1) not in route):
            if dfs((h,w-1)):
                return True
        if w+1 < W and ((h,w+1) not in route):
            if dfs((h,w+1)):
                return True
        return False

print('Yes' if dfs(start) else 'No')
Problem p03135 (python)

Fixed submission:
str_ = input().split()
x = int(str_[0])
t = int(str_[1])
print(x/t)

Buggy submission (verdict: Runtime Error):
K = int(input().split()[1])
As = [int(i) for i in input().split()]
As.sort(reverse=True)
bit_num = len(bin(K))-2
arr = [[int(s) for s in format(val,'b').zfill(bit_num)] for val in As]
temp = [0]*len(As)
for j in range(len(arr[0])):
    for i in range(len(arr)):
        temp[j] += arr[i][j]
ans = int("".join(["0" if i>len(arr)/2 else "1" for i in temp]), 2)
ans = ans if ans < K else K
print(sum([ans^i for i in As]))

Buggy submission (verdict: Runtime Error):
K = int(input().split()[1])
As = [int(i) for i in input().split()]
As.sort(reverse=True)
print(bin(K))
bit_num = len(bin(K))-2
arr = [[int(s) for s in format(val,'b').zfill(bit_num)] for val in As]
arr = [sum(arr[i][j] for i in range(len(arr))) for j in range(len(arr[0]))]
ans = int("".join(["0" if i>len(arr)/2 else "1" for i in arr]), 2)
ans = ans if ans < K else K
print(sum([ans^i for i in As]))

Buggy submission (verdict: Runtime Error):
K = int(input().split()[1])
As = [int(i) for i in input().split()]
As.sort(reverse=True)
bit_num = len(bin(K))-2
arr = [[int(s) for s in format(val,'b').zfill(bit_num)] for val in As]
temp = [0]*len(As)
for j in range(len(arr[0])):
    for i in range(len(arr)):
        temp[j] += arr[i][j]
ans = int("".join(["0" if i>len(arr)/2 else "1" for i in temp]), 2)
ans = ans if ans < K else K
print(sum([ans^i for i in As]))

Buggy submission (verdict: Runtime Error):
K = int(input().split()[1])
As = [int(i) for i in input().split()]
As.sort(reverse=True)
bit_num = len(bin(K))-2
arr = [[int(s) for s in format(val,'b').zfill(bit_num)] for val in As]
# ここか？
arr = [sum([arr[i][j] for i in range(len(arr))]) for j in range(len(arr[0]))]

Buggy submission (verdict: Runtime Error):
K = int(input().split()[1])
As = [int(i) for i in input().split()]
As.sort(reverse=True)
bit_num = len(bin(K))-2
arr = [[int(s) for s in format(val,'b').zfill(bit_num)] for val in As]
arr = [sum([arr[i][j] for i in range(len(arr))]) for j in range(len(arr[0]))]
ans = int("".join(["0" if i>len(arr)/2 else "1" for i in arr]), 2)
ans = ans if ans < K else K
print(sum([ans^i for i in As]))

Buggy submission (verdict: Runtime Error):
import numpy as np
K = int(input().split()[1])
As = [int(i) for i in input().split()]
As.sort(reverse=True)
bit_num = len(bin(K))-2
arr = np.array([[int(s) for s in format(val,'b').zfill(bit_num)] for val in As])
ans = int("".join(["0" if i>arr.shape[0]/2 else "1" for i in np.sum(arr, axis=0)]), 2)
ans = ans if ans < K else K
print(sum([ans^i for i in As]))

Buggy submission (verdict: Runtime Error):
x = int(input())
t = int(input())
print(x/t)
Problem p02753 (python)

Fixed submission:
#!/usr/bin/env python3 ## -*- python -*-

s = input()

if "AB" in s:
  print("Yes")
elif "BA" in s:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3 ## -*- python -*-

s = input()
q = int(input())

for i in range(q):
    d = input()
    if d[:1] == "1":
        if not s[:1] == s[-1:1]:
            s = s[::-1]
    else: # 2
        dd = d.split()
        f = int(dd[1])
        c = dd[2]
        if f == 1:
            s = c + s
        else: # f == 2
            s = s + c

print(s)
Problem p02897 (python)

Fixed submission:
from math import ceil

if __name__ == "__main__":
    n = int(input())
    print(ceil(n/2)/n)

Buggy submission (verdict: Runtime Error):
if __name__ == "__main__":
    n = int(input())
    """studentNumbers = [(x, str(i)) for x, i in
        zip(input().split(), range(1, 1000000))]
    studentNumbers.sort(key=lambda tup: tup[0])
    print(' '.join([x[1] for x in studentNumbers]))"""
    studentNumbers = [(str(i + 1), x) for i, x in enumerate(input().split())]
    if (n > 1):
        studentNumbers.sort(key=lambda tup: tup[1])
    print(' '.join([x[0] for x in studentNumbers]))

Buggy submission (verdict: Runtime Error):
if __name__ == "__main__":
    n = int(input())
    """studentNumbers = [(x, str(i)) for x, i in
        zip(input().split(), range(1, 1000000))]
    studentNumbers.sort(key=lambda tup: tup[0])
    print(' '.join([x[1] for x in studentNumbers]))"""
    studentNumbers = [(x, str(i + 1)) for x, i in zip(input().split(), range(n))]
    if (n > 1):
        studentNumbers.sort(key=lambda tup: tup[0])
    print(' '.join([x[1] for x in studentNumbers]))
Problem p02948 (python)

Fixed submission:
from sys import exit
from collections import deque
import heapq
if __name__ == "__main__":
    n, m = map(int, input().split())
    jobs = []
    for i in range(n):
        job = tuple(map(int, input().split()))
        if job[0] <= m:
            jobs.append(job)
    jobs.sort(key=lambda tup: tup[0])
    income = 0
    jobs = deque(jobs)
    hp = []
    for day in range(m):
        while len(jobs) != 0 and jobs[0][0] <= day + 1:
            job = jobs[0]
            heapq.heappush(hp, - job[1])
            jobs.popleft()
        if hp != []:
            income -= heapq.heappop(hp)
    
    print(income)

Buggy submission (verdict: Runtime Error):
from sys import exit
if __name__ == "__main__":
    n, m = map(int, input().split())
    jobs = []
    for i in range(n):
        job = tuple(map(int, input().split()))
        if job[0] <= m:
            jobs.append(job)
    jobs.sort(key=lambda tup: tup[1], reverse=True)
    income = 0
    daysUsed = -1
    if m == 1:
        print(jobs[1])
        exit()

    for job in jobs:
        daysLeft = (m - daysUsed) - job[0]
        if daysLeft > 0:
            income += job[1]
            daysUsed += 1
        else:
            income += job[1]
            break
    print(income)

Buggy submission (verdict: Runtime Error):
from sys import exit
if __name__ == "__main__":
    n, m = map(int, input().split())
    jobs = []
    for i in range(n):
        job = tuple(map(int, input().split()))
        if job[0] <= m:
            jobs.append(job)
    jobs.sort(key=lambda tup: tup[1], reverse=True)
    income = 0
    daysUsed = -1
    if m == 1:
        print(jobs[0][1])
        exit()
        
    for job in jobs:
        daysLeft = (m - daysUsed) - job[0]
        if daysLeft > 0:
            income += job[1]
            daysUsed += 1
        else:
            income += job[1]
            break
    print(income)
Problem p02785 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10**9)

h, k = map(int, input().split())
hi = list(map(int, input().split()))
hi.sort(reverse=True)
del hi[:k]

num = 0
if hi == []:
    print(0)
else:
    for i in hi:
        num += i
    print(num)

Buggy submission (verdict: Runtime Error):
hi = list(map(int, input().split()))
hi.sort(reverse=True)
del hi[:k]

num = 0
if hi == []:
    print(0)
else:
    for i in hi:
        num += i
    print(num)
Problem p02835 (python)

Fixed submission:
a, b, c = map(int, input().split())
num = a + b + c
if (num >= 22):
  print('bust')
else:
  print('win')

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split)
num = a + b + c
if (num >= 22):
  print('bust')
else:
  print('win')
Problem p03634 (python)

Fixed submission:
n = int(input())
g = []
d = [0] * (n + 1)
for i in range(n + 1):
    g.append([]);
for i in range(n - 1):
    u, v, w = map(int, input().split())
    g[u].append([v, w])
    g[v].append([u, w])
q, k = map(int, input().split())
def bfs(u):
    s = []
    s.append(u)
    while s:
        v = s[-1]
        s.pop()
        for go in g[v]:
            if not d[go[0]] and go[0] != u:
                d[go[0]] = d[v] + go[1]
                s.append(go[0])
bfs(k)
while q > 0:
    u, v = map(int, input().split())
    print(d[u] + d[v])
    q -= 1

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

using namespace std;

const int N = 100005;

long long d[N];
vector<pair<int, int>> g[N];

void dfs(int u, int f, long long w) {
  d[u] = w;
  for (auto &go : g[u]) {
    if (go.first != f) {
      dfs(go.first, u, w + go.second);
    }
  }
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  int q, k;
  scanf("%d %d", &q, &k);
  dfs(k, k, 0);
  while (q--) {
    int u, v;
    scanf("%d %d", &u, &v);
    cout << d[u] + d[v] << endl;
  }
  return 0;
}

Buggy submission (verdict: Runtime Error):
n = int(input())
g = []
d = [0] * (n * 2)
for i in range(n * 2):
    g.append([]);
for i in range(n - 1):
    u, v, w = map(int, input().split())
    g[u].append([v, w])
    g[v].append([u, w])
q, k = map(int, input().split())
def dfs(u, f, w):
    d[u] = w;
    for go in g[u]:
        if go[0] != f:
            dfs(go[0], u, go[1] + w)
dfs(k, k, 0)
while q > 0:
    u, v = map(int, input().split())
    print(d[u] + d[v])
    q -= 1

Buggy submission (verdict: Runtime Error):
n = int(input())
g = []
d = [0] * (n + 1)
for i in range(n + 1):
    g.append([]);
for i in range(n - 1):
    u, v, w = map(int, input().split())
    g[u].append([v, w])
    g[v].append([u, w])
q, k = map(int, input().split())
def dfs(u, f, w):
    d[u] = w;
    for go in g[u]:
        if go[0] != f:
            dfs(go[0], u, go[1] + w)
dfs(k, k, 0)
while q > 0:
    u, v = map(int, input().split())
    print(d[u] + d[v])
    q -= 1

Buggy submission (verdict: Runtime Error):
n = int(input())
g = []
d = [0] * (n + 1)
for i in range(n + 1):
    g.append([]);
for i in range(n - 1):
    u, v, w = map(int, input().split())
    g[u].append([v, w])
    g[v].append([u, w])
q, k = map(int, input().split())
def dfs(u, f, w):
    d[u] = w;
    for go in g[u]:
        if go[0] != f:
            dfs(go[0], u, go[1] + w)
dfs(k, k, 0)
while q > 0:
    u, v = map(int, input().split())
    print(d[u] + d[v])
    q -= 1
Problem p03745 (python)

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

def ans(x,L):
    ans = 1
    flag = 0
    tmp = L[0:2]
    if tmp[0] < tmp[1]:
        flag  = 1
    elif tmp[0] > tmp[1]:
        flag = -1
    for i in range(2,n):
        tmp.append(L[i])
        if len(tmp) == 1:
            pass
        elif (flag == -1 and tmp[-2] < tmp[-1]) or (flag == 1 and tmp[-2] > tmp[-1]):
            ans += 1
            flag = 0
            tmp = [tmp[-1]]
        elif flag == 0 and tmp[-2] < tmp[-1]:
            flag = 1
        elif flag == 0 and tmp[-2] > tmp[-1]:
            flag = -1
    return(ans)
if n <= 2:
    print(1)
else:
    print(ans(n,l))

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

def ans(x,L):
    ans = 1
    flag = 0
    tmp = L[0:2]
    if tmp[0] < tmp[1]:
        flag  = 1
    elif tmp[0] > tmp[1]:
        flag = -1
    for i in range(2,n):
        tmp.append(L[i])
        if len(tmp) == 1 and i == n-1:
            pass
        elif (flag == -1 and tmp[-2] < tmp[-1]) or (flag == 1 and tmp[-2] > tmp[-1]):
            ans += 1
            flag = 0
            tmp = [tmp[-1]]
        elif flag == 0 and tmp[-2] < tmp[-1]:
            flag = 1
        elif flag == 0 and tmp[-2] > tmp[-1]:
            flag = -1
    return(ans)
print(ans(n,l))

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

def ans(x,L):
    ans = 1
    flag = 0
    tmp = L[0:2]
    if tmp[0] < tmp[1]:
        flag  = 1
    elif tmp[0] > tmp[1]:
        flag = -1
    for i in range(2,n):
        tmp.append(L[i])
        if len(tmp) == 1 and i == n-1:
            pass
        elif (flag == -1 and tmp[-2] < tmp[-1]) or (flag == 1 and tmp[-2] > tmp[-1]):
            ans += 1
            flag = 0
            tmp = [tmp[-1]]
        elif flag == 0 and tmp[-2] < tmp[-1]:
            flag = 1
        elif flag == 0 and tmp[-2] > tmp[-1]:
            flag = -1
    return(ans)
print(ans(n,l))

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

def ans(x,L):
    ans = 1
    flag = 1
    tmp = L[0:3]
    if (tmp[0]<tmp[1] and tmp[2]<tmp[1]) or (tmp[0]>tmp[1] and tmp[2]>tmp[1]):
        ans += 1
        flag = 0
    for i in range(3,x):
        tmp = tmp[1:3]
        tmp.append(L[i])
        if (tmp[0]<tmp[1] and tmp[2]<tmp[1] and flag > 0) or (tmp[0]>tmp[1] and tmp[2]>tmp[1] and flag > 0):
            ans += 1
            flag = 0
        else:
            flag += 1
    return(ans)
        
print(ans(n,l))
Problem p02879 (python)

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

if a<10 and b<10:
    print(a*b)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
import math
n=int(input())
ans=1
for i in reversed(range(2,int(math.sqrt(n)))):
    if n%i==0 and abs(n/ans-ans)>abs(n/i-i):
        ans=n/i
            
print(int(ans-1+n/ans-1))
Problem p03042 (python)

Fixed submission:
s=int(input())
num=[]
while s > 0:
    num.append(s % 100)
    s //= 100

if len(num)==0:
    num.append(0)
if len(num)==1:
    num.append(0)
num.reverse()

if num[0]<=12 and num[0]>0:
    if num[1]<=12 and num[1]>0:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if num[1]<=12 and num[1]>0:
        print("YYMM")
    else:
        print("NA")

Buggy submission (verdict: Runtime Error):
s=int(input())
num=[]
while s > 0:
    num.append(s % 100)
    s //= 100

num.reverse()

if num[0]<=12 and num[0]>0:
    if num[1]<=12 and num[1]>0:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if num[1]<=12 and num[1]>0:
        print("YYMM")
    else:
        print("NA")
Problem p03108 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
N, M = [int(n) for n in input().split()]
AB = []

P = list(range(N))
P_num = [1] * N

def root(x):
    if P[x] == x:
        return x
    else:
        P[x] = root(P[x])
        return P[x]
        
def unite(x, y):
    P[root(y)] = root(x)
    

for m in range(M):
    A, B = [int(n) - 1 for n in input().split()]
    AB.append((A, B))

convenience = [0]
for i in range(M):
    A, B = AB[M - 1 - i]
    convenience.append(convenience[-1])
    if root(A) != root(B):
        convenience[-1] += P_num[root(A)] * P_num[root(B)]
        next_num = P_num[root(A)] + P_num[root(B)]
        unite(A, B)
        P_num[root(A)] = next_num

for m in range(M):
    print(N * (N - 1) // 2 - convenience[M - 1 - m])

Buggy submission (verdict: Runtime Error):

N, M = [int(n) for n in input().split()]
AB = []

P = list(range(N))
P_num = [1] * N

def root(x):
    if P[x] == x:
        return x
    else:
        P[x] = root(P[x])
        return P[x]
        
def unite(x, y):
    P[root(y)] = root(x)
    

for m in range(M):
    A, B = [int(n) - 1 for n in input().split()]
    AB.append((A, B))

convenience = [0]
for i in range(M):
    A, B = AB[M - 1 - i]
    convenience.append(convenience[-1])
    if root(A) != root(B):
        convenience[-1] += P_num[root(A)] * P_num[root(B)]
        next_num = P_num[root(A)] + P_num[root(B)]
        unite(A, B)
        P_num[root(A)] = next_num

for m in range(M):
    print(N * (N - 1) // 2 - convenience[M - 1 - m])

Buggy submission (verdict: Runtime Error):

N, M = [int(n) for n in input().split()]
AB = []

P = list(range(N))
P_num = [1] * N

def root(x):
    if P[x] == x:
        return x
    else:
        P[x] = root(P[x])
        return P[x]
        
def unite(x, y):
    P[root(y)] = root(x)
    

for m in range(M):
    A, B = [int(n) - 1 for n in input().split()]
    AB.append((A, B))

convenience = [0]
for i in range(M):
    A, B = AB[M - 1 - i]
    convenience.append(convenience[-1])
    if root(A) != root(B):
        convenience[-1] += P_num[root(A)] * P_num[root(B)]
        next_num = P_num[root(A)] + P_num[root(B)]
        unite(A, B)
        P_num[root(A)] = next_num

for m in range(M):
    print(N * (N - 1) // 2 - convenience[M - 1 - m])

Buggy submission (verdict: Runtime Error):

N, M = [int(n) for n in input().split()]
AB = []

P = list(range(N))
P_num = [1] * N

def root(x):
    if P[x] == x:
        return x
    else:
        P[x] = root(P[x])
        return P[x]
        
def unite(x, y):
    P[root(y)] = root(x)
    

for m in range(M):
    A, B = [int(n) - 1 for n in input().split()]
    AB.append((A, B))

# comp_ans[i] = i番目の橋ができたときに減る不便度
comp_ans = [0] * (M + 1)
for m in range(M - 1, 0 - 1, -1):
    A, B = AB[m]
    comp_ans[m] = comp_ans[m + 1]
    if root(A) != root(B):
        comp_ans[m] += P_num[root(A)] * P_num[root(B)]
    buf = P_num[root(A)] + P_num[root(B)]
    unite(A, B)
    P_num[root(A)] = buf



for m in range(1, M + 1):
    print(N * (N - 1) // 2 - comp_ans[m])
Problem p03631 (python)

Fixed submission:
import sys

N = input()

for i in range(len(N)):
  if N[i] != N[len(N)-1-i]:
    print("No")
    sys.exit()

print("Yes")

Buggy submission (verdict: Runtime Error):
from fractions import gcd

N = int(input())
T = []
for i in range(N):
  T.append(int(input()))

res = 1
for t in T:
  res = int(res/(gcd(res, t))) * t
print(res)
Problem p03805 (python)

Fixed submission:
import itertools
N, M = [int(n) for n in input().split()]
path = [[False for i in range(N)]for j in range(N)]


for i in range(M):
    a, b = [int(n)-1 for n in input().split()]
    path[a][b] = True
    path[b][a] = True


res = 0
for way in itertools.permutations(range(1,N), N-1):
    exist = True
    if path[0][way[0]] == False:
        exist = False
    for n in range(N-2):
        if path[way[n]][way[n+1]] == False:
            exist = False
    if exist == True:
        res += 1

print(res)

Buggy submission (verdict: Runtime Error):
import itertools
N, M = [int(n) for n in input().split()]
path = [[False for i in range(M)]for j in range(M)]


for i in range(M):
    a, b = [int(n)-1 for n in input().split()]
    path[a][b] = True
    path[b][a] = True


res = 0
for way in itertools.permutations(range(1,N), N-1):
    exist = True
    if path[0][way[0]] == False:
        exist = False
    for n in range(N-2):
        if path[way[n]][way[n+1]] == False:
            exist = False
    if exist == True:
        res += 1

print(res)
Problem p03821 (python)

Fixed submission:
N = int(input())
A=[]
B=[]
for i in range(N):
    a,b=[int(n) for n in input().split()]
    A.append(a)
    B.append(b)

cnt=0

# print(list(reversed(range(N))))
for i in reversed(range(N)):
    if (A[i]+cnt)%B[i]==0:
        d=0
    else:
        d=B[i]-(A[i]+cnt)%B[i]
    cnt+=d
#    A=[A[n]+r if n<=i else A[n] for n in range(N)]

print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
A=[]
B=[]
for i in range(N):
    a,b=[int(n) for n in input().split()]
    A.append(a)
    B.append(b)

cnt=0

# print(list(reversed(range(N))))
for i in reversed(range(N)):
    if A[i]%B[i]==0:
        r=0
    else
        r=B[i]-A[i]%B[i]
    cnt+=r
    A=[A[n]+r if n<=i else A[n] for n in range(N)]

print(cnt)
Problem p03822 (python)

Fixed submission:
import sys
sys.setrecursionlimit(500000)

N=int(input())


depth=[-1]*N
parent=[-1]*N
childs=[[] for i in range(N)]

depth[0]=0
def calc_depth(n):
    for child in childs[n]:
        depth[child]=depth[n]+1
        calc_depth(child)

def calc_height(n):
    if childs[n]==[]:
        return 0 
    childs_height=[]
    for child in childs[n]:
        childs_height.append(calc_height(child))
    childs_height.sort(reverse=True)
    heightlist=[childs_height[i]+i for i in range(len(childs_height))]
    return max(heightlist)+1

for i in range (1,N):
    a=int(input())-1
    childs[a].append(i)

print(calc_height(0))

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


depth=[-1]*N
parent=[-1]*N
childs=[[] for i in range(N)]

depth[0]=0
def calc_depth(n):
    for child in childs[n]:
        depth[child]=depth[n]+1
        calc_depth(child)

def calc_height(n):
    if childs[n]==[]:
        return 0 
    childs_height=[]
    for child in childs[n]:
        childs_height.append(calc_height(child))
    childs_height.sort(reverse=True)
    heightlist=[childs_height[i]+i for i in range(len(childs_height))]
    return max(heightlist)+1

for i in range (1,N):
    a=int(input())-1
    childs[a].append(i)

print(calc_height(0))

Buggy submission (verdict: Runtime Error):


depth=[-1]*N
parent=[-1]*N
childs=[[] for i in range(N)]

depth[0]=0
def calc_depth(n):
    for child in childs[n]:
        depth[child]=depth[n]+1
        calc_depth(child)

def calc_height(n):
    if childs[n]==[]:
        return 0 
    childs_height=[]
    for child in childs[n]:
        childs_height.append(calc_height(child))
    childs_height.sort(reverse=True)
    heightlist=[childs_height[i]+i for i in range(len(childs_height))]
    return max(heightlist)+1

for i in range (1,N):
    a=int(input())-1
    childs[a].append(i)

print(calc_height(0))