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

Fixed submission:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import random

n = int(input())
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]
# n = 10
# a = []
# b = []
# for _ in range(10):
#     a.append(random.randrange(1, 4))
#     b.append(random.randrange(1, 4))
# a.sort()
# b.sort()
# print(*a)
# print(*b)

b.reverse()

same_val = None
same_id = []
for i, (ai, bi) in enumerate(zip(a, b)):
    if ai == bi:
        same_val = ai
        same_id.append(i)

changeable = []
for i, (ai, bi) in enumerate(zip(a, b)):
    if b[i] != same_val and a[i] != same_val:
        changeable.append(i)

if len(same_id) > len(changeable):
    print("No")
    exit()
for s, c in zip(same_id, changeable):
    b[s], b[c] = b[c], b[s]

print("Yes")
print(*b)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]

if n == 1:
    if a[0] == b[0]:
        print("No")
    else:
        print(*b)
        
left = 0
lv = b[0]
for i in range(n):
    if b[i] != lv:
        right = i
        break

for i in range(n - 1):
    if a[i] != b[i]:
        left += 1
        if right == left:
            right += 1
    else:
        if a[i] == b[right]:
            while b[right] == a[i]:
                right += 1
                if right == n:
                    print("No")
                    exit()
        b[i], b[right] = b[right], b[i]
        left += 1
        if right == left:
            right += 1

if a[-1] != b[-1]:
    print(*b)
    exit()
if a[-2] != b[-1] and a[-1] != b[-2]:
    b[-1], b[-2] = b[-2], b[-1]
    print(*b)
    exit()
print("No")
Problem p02589 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import defaultdict

def empty_list():
    return [0] * 26

class RollingHash():
    def __init__(self, s):
        length = len(s)
        base = 1009
        # self.mod = (1 << 61) - 1
        self.mod = 67280421310721
        self.hash = [0] * (length + 2)
        self.pow = [1] * (length + 2)

        for i in range(length):
            self.hash[i+1] = (self.hash[i] + s[i]) * base % self.mod
            self.pow[i+1] = self.pow[i] * base % self.mod
        self.pow[length+1] = self.pow[length] * base % self.mod 

    def get(self, l, r):
        t = self.hash[r] - self.hash[l] * self.pow[r-l] % self.mod
        return t % self.mod

ss = []
n = int(input())
for _ in range(n):
    ss.append([ord(item) for item in input().rstrip()])
ss.sort(key=lambda x: len(x), reverse=True)

orda = ord("a")
words = defaultdict(empty_list)
ans = 0
for s in ss:
    word_len = len(s)
    s_rev = s[::-1]
    RH = RollingHash(s_rev)
    rh = RH.get(0, word_len-1)
    ans += words[rh][s_rev[-1] - orda]
    initial = [0] * 26 
    for i, ch in enumerate(s):
        initial[ch - orda] = 1
        for j, is_initial in enumerate(initial):
            if is_initial:
                rh = RH.get(0, word_len-i-1)
                words[rh][j] += 1
print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

MOD = (1 << 61) - 1
mod_pow = [1] * (10**5 * 5 + 10)
base = 1009

for i in range(10**5 * 5 + 9):
    mod_pow[i+1] = mod_pow[i] * base % MOD

class RollingHash():
    def __init__(self, s):
        self.length = len(s)
        self.base = 1009
        self.mod = (1 << 61) - 1
        self.hash = [0] * (self.length + 2)

        for i in range(self.length):
            self.hash[i+1] = (self.hash[i] + ord(s[i])) * self.base % self.mod

    def get(self, l, r):
        t = self.hash[r] - self.hash[l] * mod_pow[r-l] % self.mod
        return t % self.mod

ss = []
n = int(input())
for _ in range(n):
    ss.append(input().rstrip())
ss.sort(key=lambda x: len(x), reverse=True)

words = dict()
ans = 0
orda = ord("a")
for s in ss:
    word_len = len(s)
    s_rev = s[::-1]
    RH = RollingHash(s_rev)
    rh = RH.get(0, word_len-1)
    if rh in words:
        ans += words[rh][ord(s_rev[-1]) - orda]
    initial = set()
    for i, ch in enumerate(s):
        initial.add(ord(ch) - orda)
        for key in initial:
            rh = RH.get(0, word_len-i-1)
            if rh in words:
                words[rh][key] += 1
            else:
                words[rh] = [0] * 26
                words[rh][key] += 1
print(ans)
Problem p02679 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import math
MOD = 10**9 + 7

n = int(input())
fish = dict() 
azero = 0
bzero = 0
abzero = 0
for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        abzero += 1
        continue
    if a == 0:
        azero += 1
        continue
    if b == 0:
        bzero += 1
        continue
    a_abs = abs(a); b_abs = abs(b)
    g = math.gcd(a_abs, b_abs)
    if (a > 0 and b > 0) or (a < 0 and b < 0): 
        key = (a_abs // g, b_abs // g)
    else:
        key = (a_abs // g, -b_abs // g)
    if key not in fish:
        fish[key] = 1
    else:
        fish[key] += 1

ans = 1
for a, b in fish:
    if fish[(a, b)] == 0:
        continue
    if b < 0:
        inv_key = (-b, a)
    else:
        inv_key = (b, -a)
    if inv_key in fish:
        val1 = ans * (pow(2, fish[(a, b)], MOD) - 1)
        val2 = ans * (pow(2, fish[inv_key], MOD) - 1)
        fish[inv_key] = 0
        ans = val1 + val2 + ans
    else:
        val1 = ans * (pow(2, fish[(a, b)], MOD) - 1)
        ans = val1 + ans
    ans %= MOD
# think a == 0 or b == 0
val1 = ans * (pow(2, azero, MOD) - 1)
val2 = ans * (pow(2, bzero, MOD) - 1)
ans = val1 + val2 + ans
ans += abzero
print((ans - 1) % MOD)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import math
MOD = 10**9 + 7

n = int(input())
fish = dict() 
for _ in range(n):
    a, b = map(int, input().split())
    a_abs = abs(a); b_abs = abs(b)
    g = math.gcd(a_abs, b_abs)
    if (a > 0 and b > 0) or (a < 0 and b < 0): 
        key = (a_abs // g, b_abs // g)
    else:
        key = (a_abs // g, -b_abs // g)
    if key not in fish:
        fish[key] = 1
    else:
        fish[key] += 1

ans = 1
for a, b in fish:
    if fish[(a, b)] == 0:
        continue
    if b < 0:
        inv_key = (-b, a)
    else:
        inv_key = (b, -a)
    if inv_key in fish:
        val1 = ans * (pow(2, fish[(a, b)], MOD) - 1)
        val2 = ans * (pow(2, fish[inv_key], MOD) - 1)
        fish[inv_key] = 0
        ans = val1 + val2 + ans
    else:
        val1 = ans * (pow(2, fish[(a, b)], MOD) - 1)
        ans = val1 + ans
    ans %= MOD
print((ans - 1) % MOD)
Problem p02851 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
from collections import Counter
input = sys.stdin.readline
INF = 10**9

n, k = [int(item) for item in input().split()]
a = [int(item) - 1 for item in input().split()]
cumsum = [0] * (n + 1)
for i in range(n):
    cumsum[i+1] = cumsum[i] + a[i]
    cumsum[i+1] %= k

ls = list(set(cumsum))
dic = dict()
for i, item in enumerate(ls):
    dic[item] = i

cnt = [0] * (n + 10)
num = 0
ans = 0
for i, item in enumerate(cumsum):
    index = dic[item]
    ans += cnt[index]
    cnt[index] += 1
    num += 1
    if num >= k:
        left = cumsum[i - k + 1]
        index = dic[left]
        if cnt[index] > 0:
            cnt[index] -= 1
        num -= 1

print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from collections import Counter
input = sys.stdin.readline
INF = 10**9

n, k = [int(item) for item in input().split()]
a = [int(item) - 1 for item in input().split()]
cumsum = [0] * (n + 1)
for i in range(n):
    cumsum[i+1] = cumsum[i] + a[i]
    cumsum[i+1] %= k

ls = list(set(cumsum))
dic = dict()
for i, item in enumerate(ls):
    dic[item] = i

cnt = [0] * n
num = 0
ans = 0
for i, item in enumerate(cumsum):
    index = dic[item]
    ans += cnt[index]
    cnt[index] += 1
    num += 1
    if num >= k:
        left = cumsum[i - k + 1]
        index = dic[left]
        if cnt[index] > 0:
            cnt[index] -= 1
        num -= 1

print(ans)
Problem p02875 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

MOD = 998244353
MAX_N = 10**7 

fac = [1] + [0] * MAX_N
fac_inv = [1] + [0] * MAX_N
mod_pow2_n = [1] + [0] * MAX_N
for i in range(1, MAX_N+1):
    fac[i] = fac[i-1] * i % MOD
    mod_pow2_n[i] = mod_pow2_n[i-1] * 2 % MOD

fac_inv[MAX_N] = pow(fac[MAX_N], MOD-2, MOD)
for i in range(MAX_N, 1, -1):
    fac_inv[i-1] = fac_inv[i] * i % MOD

def mod_nCr(n, r):
    if n < r or n < 0 or r < 0:
        return 0
    tmp = fac_inv[n-r] * fac_inv[r] % MOD
    return tmp * fac[n] % MOD 
    
n = int(input())
ans = 0
for i in range(n//2+1, n+1):
    ans += mod_nCr(n, i) * mod_pow2_n[n-i]
    ans %= MOD
print((pow(3, n, MOD) - ans * 2 + MOD)%MOD)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

MOD = 998244353
MAX_N = 10**6 

fac = [1] + [0] * MAX_N
fac_inv = [1] + [0] * MAX_N
mod_pow2_n = [1] + [0] * MAX_N
f = 1
finv = 1
p2 = 1
for i in range(1, MAX_N+1):
    # fac[i] = fac[i-1] * i % MOD
    f *= i
    f %= MOD
    fac[i] = f
    # Fermat's little theorem says
    # a**(p-1) mod p == 1
    # then, a * a**(p-2) mod p == 1
    # it means a**(p-2) is inverse element
    # fac_inv[i] = fac_inv[i-1] * pow(i, MOD-2, MOD) % MOD
    finv *= pow(i, MOD-2, MOD)
    finv %= MOD
    fac_inv[i] = finv
    p2 *= 2
    p2 %= MOD
    mod_pow2_n[i] = p2

def mod_nCr(n, r):
    if n < r or n < 0 or r < 0:
        return 0
    tmp = fac_inv[n-r] * fac_inv[r] % MOD
    return tmp * fac[n] % MOD 
    
def single_mod_nCr(n, r):
    if n < r or n < 0 or r < 0:
        return 0
    if r > n - r:
        r = n - r
    ret = 1
    for i in range(r):
        ret *= n - i
        ret *= pow(i+1, MOD-2, MOD)
        ret %= MOD
    return ret

n = int(input())
ans = 0
for i in range(n//2+1, n+1):
    ans += mod_nCr(n, i) * mod_pow2_n[n-i]
    ans %= MOD
print((pow(3, n, MOD) - ans * 2 + MOD)%MOD)
Problem p02998 (python)

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

MAXVAL = 10**5
N = int(input())
edge = [[] for _ in range(MAXVAL*2)]
visited = [0] * (MAXVAL*2)
ans = 0
xnum = 0; ynum = 0; nodes = 0

def dfs(n):
    global xnum, ynum, nodes
    if visited[n] == 1:
        return True
    if n < MAXVAL:
        xnum += 1
    else:
        ynum += 1
    visited[n] = 1
    for item in edge[n]:
        nodes += 1
        dfs(item)
    return True

for i in range(N):
    x, y = [int(item) for item in input().split()]
    x -= 1; y -= 1
    edge[x].append(y+MAXVAL)
    edge[y+MAXVAL].append(x)

for i in range(MAXVAL*2):
    if visited[i] == 1:
        continue
    xnum = 0; ynum = 0; nodes = 0
    dfs(i)
    if nodes >= 3:
        ans += xnum * ynum - nodes // 2
print(ans)

Buggy submission (verdict: Runtime Error):
MAXVAL = 10**5
N = int(input())
edge = [[] for _ in range(MAXVAL*2)]
visited = [0] * (MAXVAL*2)
ans = 0
xnum = 0; ynum = 0; nodes = 0

def dfs(n):
    global xnum, ynum, nodes
    if visited[n] == 1:
        return True
    if n < MAXVAL:
        xnum += 1
    else:
        ynum += 1
    visited[n] = 1
    for item in edge[n]:
        nodes += 1
        dfs(item)
    return True

for i in range(N):
    x, y = [int(item) for item in input().split()]
    x -= 1; y -= 1
    edge[x].append(y+MAXVAL)
    edge[y+MAXVAL].append(x)

for i in range(MAXVAL*2):
    if visited[i] == 1:
        continue
    xnum = 0; ynum = 0; nodes = 0
    dfs(i)
    if nodes >= 3:
        ans += xnum * ynum - nodes // 2
print(ans)
Problem p03015 (python)

Fixed submission:
MOD = 10**9 + 7
L = input().rstrip()
if L == "1":
    print(3)
    exit()
n = len(L)

ans = 0
l_num = L.count("1")
dp_t = [[0] * n for _ in range(2)]
dp_l = [[0] * n for _ in range(2)]
dp_t[1][0] = 2
dp_l[0][1] = 1
dp_l[1][1] = 2
for i in range(1, n):
    if L[i] == "0":
        dp_t[0][i] += dp_t[0][i-1] + dp_t[1][i-1] 
    elif L[i] == "1":
        dp_t[1][i] += (dp_t[0][i-1] + dp_t[1][i-1]) * 2
        dp_l[0][i] += dp_t[0][i-1] + dp_t[1][i-1]
    dp_l[0][i] += dp_l[0][i-1] + dp_l[1][i-1]
    dp_l[1][i] += (dp_l[0][i-1] + dp_l[1][i-1]) * 2

    dp_l[1][i] %= MOD
    dp_l[0][i] %= MOD
    dp_t[1][i] %= MOD
    dp_t[0][i] %= MOD

print((dp_t[1][n-1] + dp_t[0][n-1] + dp_l[1][n-1] + dp_l[0][n-1]) % MOD)

Buggy submission (verdict: Runtime Error):
MOD = 10**9 + 7
L = input().rstrip()
n = len(L)

ans = 0
l_num = L.count("1")
dp_t = [[0] * n for _ in range(2)]
dp_l = [[0] * n for _ in range(2)]
dp_t[1][0] = 2
dp_l[0][1] = 1
dp_l[1][1] = 2
for i in range(1, n):
    if L[i] == "0":
        dp_t[0][i] += dp_t[0][i-1] + dp_t[1][i-1] 
    elif L[i] == "1":
        dp_t[1][i] += (dp_t[0][i-1] + dp_t[1][i-1]) * 2
        dp_l[0][i] += dp_t[0][i-1] + dp_t[1][i-1]
    dp_l[0][i] += dp_l[0][i-1] + dp_l[1][i-1]
    dp_l[1][i] += (dp_l[0][i-1] + dp_l[1][i-1]) * 2

    dp_l[1][i] %= MOD
    dp_l[0][i] %= MOD
    dp_t[1][i] %= MOD
    dp_t[0][i] %= MOD

print((dp_t[1][n-1] + dp_t[0][n-1] + dp_l[1][n-1] + dp_l[0][n-1]) % MOD)
Problem p03055 (python)

Fixed submission:
import heapq
INF = 10**9

n = int(input())
edge = [[] for _ in range(n)]

class Dijkstra:
    def __init__(self, adj):
        self.adj = adj
        self.num = len(adj)
        self.dist = [INF] * self.num
        self.prev = [INF] * self.num
        self.q = []

    def reset(self):
        self.dist = [INF] * self.num
        self.prev = [INF] * self.num
        self.q = []

    def calc(self, start):
        self.dist[start] = 0
        heapq.heappush(self.q, (0, start))
        while len(self.q) != 0:
            prov_cost, src = heapq.heappop(self.q)
            if self.dist[src] < prov_cost:
                continue
            for dest in self.adj[src]:
                cost = 1
                if self.dist[dest] > self.dist[src] + cost:
                    self.dist[dest] = self.dist[src] + cost
                    heapq.heappush(self.q, (self.dist[dest], dest))
                    self.prev[dest] = src
        return self.dist 

for i in range(n-1):
    a, b = [int(item) for item in input().split()]
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)

dij = Dijkstra(edge)
dist = dij.calc(0)
left = dist.index(max(dist))
dij.reset()
dist = dij.calc(left)
diam = max(dist)
if diam % 3 == 1:
    print("Second")
else:
    print("First")

Buggy submission (verdict: Runtime Error):
import heapq
INF = 10**9

n = int(input())
edge = [[] for _ in range(n)]

def get_max_dist(frm, n, dist):
    val = 0
    index = -1
    for item in edge[n]:
        if item == frm:
            if len(edge[n]) == 1:
                return dist, n
            continue
        tmp, tindex = get_max_dist(n, item, dist+1)
        if val < tmp:
            val = tmp
            index = tindex
    return val, index

for i in range(n-1):
    a, b = [int(item) for item in input().split()]
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)

val, left = get_max_dist(-1, 0, 0)
diam, right = get_max_dist(-1, left, 0)

if diam % 3 == 1:
    print("Second")
else:
    print("First")
Problem p03107 (python)

Fixed submission:
s = input().rstrip()
a = s.count("0")
b = s.count("1")
print(min(a,b)*2)

Buggy submission (verdict: Runtime Error):
count = 0

oi10 = "0"*10 + "1"*10
io10 = "1"*10 + "0"*10

while oi10 in s or io10 in s:
    while oi10 in s:
        s = s.replace(oi10, "", 1)
        count += 10
    while io10 in s:
        s = s.replace(io10, "", 1)
        count += 10

while "01" in s or "10" in s:
    while "01" in s:
        num = s.count("01")
        s = s.replace("01", "")
        count += num
    while "10" in s:
        num = s.count("10")
        s = s.replace("10", "")
        count += num

print(count * 2)
Problem p03329 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

n = int(input())

get = []
for i in range(10):
  npow6 = 6**(i+1)
  npow9 = 9**(i+1)
  if npow6 <= 100000:
    get.append(npow6)
  if npow9 <= 100000:
    get.append(npow9)
  
get = sorted(get)

memo = [-1] * 110000
for i in range(6):
  memo[i] = i
  
def dfs(money):
  if memo[money] != -1:
    return memo[money]
  ret = 110000
  for g in get:
    if g > money:
      continue
    ret0 = dfs(money-g) + 1
    ret = min(ret, ret0)
  memo[money] = ret
  return ret

print(dfs(n))

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

get = []
for i in range(10):
  npow6 = 6**(i+1)
  npow9 = 9**(i+1)
  if npow6 <= 100000:
    get.append(npow6)
  if npow9 <= 100000:
    get.append(npow9)
  
get = sorted(get)

memo = [-1] * 110000
for i in range(6):
  memo[i] = i
  
def dfs(money):
  if memo[money] != -1:
    return memo[money]
  if money == 0:
    return 0
  
  ret = 110000
  for g in get:
    if g > money:
      continue
    ret0 = dfs(money-g) + 1
    ret = min(ret, ret0)
  memo[money] = ret
  return ret

print(dfs(n))
Problem p03634 (python)

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

n = int(input())
abc = [[int(item) for item in input().split()] for _ in range(n-1)]
q, k = [int(item) for item in input().split()]
xy = [[int(item) for item in input().split()] for _ in range(q)]

distance = [0] * n
e = [[] for _ in range(n)]
w = [[] for _ in range(n)]
for a, b, c in abc:
    e[a-1].append(b-1)
    e[b-1].append(a-1)
    w[a-1].append(c)
    w[b-1].append(c)

def dfs(v, par, dist):
    distance[v] = dist
    if len(e[v]) == 0:
        return True
    for i in range(len(e[v])):
        if e[v][i] == par:
            continue
        dfs(e[v][i], v, dist + w[v][i])

dfs(k-1, -1, 0)
for x, y in xy:
    print(distance[x-1] + distance[y-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
abc = [[int(item) for item in input().split()] for _ in range(n-1)]
q, k = [int(item) for item in input().split()]
xy = [[int(item) for item in input().split()] for _ in range(q)]

distance = [0] * n
e = [[] for _ in range(n)]
w = [[] for _ in range(n)]
for a, b, c in abc:
    e[a-1].append(b-1)
    e[b-1].append(a-1)
    w[a-1].append(c)
    w[b-1].append(c)

def dfs(v, par, dist):
    distance[v] = dist
    if len(e[v]) == 0:
        return True
    for i in range(len(e[v])):
        if e[v][i] == par:
            continue
        dfs(e[v][i], v, dist + w[v][i])

dfs(k-1, -1, 0)
for x, y in xy:
    print(distance[x-1] + distance[y-1])
Problem p03803 (python)

Fixed submission:
a, b = [int(item) for item in input().split()]
if a == 1:
  a += 100
if b == 1:
  b += 100
  
if a > b:
  print("Alice")
elif a == b:
  print("Draw")
else:
  print("Bob")

Buggy submission (verdict: Runtime Error):
a, b = [int(item) for item in input().split()]
if a > b:
  print("Alice")
eiif a == b:
  print("Draw")
else:
  print("Bob")
Problem p03804 (python)

Fixed submission:
n, m = [int(item) for item in input().split()]
a, b = [], []
for i in range(n):
    a.append(input().rstrip())
for i in range(m):
    b.append(input().rstrip())

for i in range(n-m+1):
    for j in range(n-m+1):
        ans = True
        for k in range(m):
            for l in range(m):
                if not a[i+k][j+l] == b[k][l]:
                    ans = False
                    break
        if ans:
            print("Yes")
            exit()
print("No")

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

match_line = 0
for i in range(n):
  for j in range(n-m):
    for k in range(m):
      if a[i+k][j:j+m] == b[k]:
        match_line += 1
        if match_line >= m:
          print("Yes")
          exit()
      else:
        match_line = 0
        continue
print("No")

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

match_line = 0
for i in range(n):
  for j in range(n-m):
    for k in range(m):
      if a[i+k][j:j+m] == b[k]:
        match_line += 1
        if match_line >= m:
          print("Yes")
          exit()
      else:
        match_line = 0
print("No")

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

ans = [0] * (n-m)
for i in range(n):
  for j in range(n-m):
    if a[i][j:j+m] == b[i]:
      ans[j] += 1
      if ans[j] >= m:
        print("Yes")
        exit()
    else:
      ans[n-m] = 0
print("No")
Problem p03822 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n = int(input())
a = []
edge = [[] for _ in range(n)]
visited = [0] * n

def dfs(n):
    visited[n] = 1
    if len(edge[n]) == 1 and n != 0:
        return 0
    childrank = []
    for item in edge[n]:
        if visited[item] == 1:
            continue
        childrank.append(dfs(item))
    childrank.sort(reverse=True)
    for i in range(len(childrank)):
        childrank[i] += i + 1
    return max(childrank)


for i in range(1, n):
    val = int(input()) - 1
    edge[i].append(val)
    edge[val].append(i)

print(dfs(0))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = []
edge = [[] for _ in range(n)]
visited = [0] * n

def dfs(n):
    visited[n] = 1
    if len(edge[n]) == 1 and n != 0:
        return 0
    childrank = []
    for item in edge[n]:
        if visited[item] == 1:
            continue
        childrank.append(dfs(item))
    childrank.sort(reverse=True)
    for i in range(len(childrank)):
        childrank[i] += i + 1
    return max(childrank)


for i in range(1, n):
    val = int(input()) - 1
    edge[i].append(val)
    edge[val].append(i)

print(dfs(0))
Problem p02546 (python)

Fixed submission:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7
s=str(input())
if s[len(s)-1]=='s':
  print(s+'es')
else:
  print(s+'s')

Buggy submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

n,x,m=map(int,input().split())
s=set()
l=[]
flag=False
cnt=1
ans=0

l.append(x)
for i in range(m):
  if x not in s:
    s.add(x)
    x=(x**2)%m
    l.append(x)
  else:
    break

h=len(l)
cnt=1
num=0
for i in range(h):
  if l[i]==l[h-1]:
    while l[i+cnt]!=l[h-1]:
      cnt+=1
    flag=True
    break
  else:
    num+=1
    ans+=l[i]

n-=num
if num!=0:
  del l[h-1]
  del l[0:num]

if n>=len(l):
  mod=n%len(l)
  ans+=sum(l)*(n//len(l))
  for i in range(1,mod):
    ans+=l[i-1]
  print(ans)
else:
  for i in range(n):
    ans+=l[i]
  print(ans)
Problem p02990 (python)

Fixed submission:
import math
def comb(n, r):
  if n-r>=0:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  else:
    return 0

n,k=map(int, input().split())
for i in range(1,k+1):
  print(comb(n-k+1,i)*comb(k-1,i-1)%(10**9+7))

Buggy submission (verdict: Runtime Error):
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,k=map(int, input().split())
for i in range(1,k+1):
  print(comb(n-k+1,i)*comb(k-1,i-1)%(10**9+7))
Problem p03041 (python)

Fixed submission:
a,b=map(int, input().split())
s=str(input())
b=b-1
slist=list(s)
if slist[b]=="A":
  slist[b]="a"
if slist[b]=="B":
  slist[b]="b"
if slist[b]=="C":
  slist[b]="c"
s="".join(slist)
print(s)

Buggy submission (verdict: Runtime Error):
a,b=map(int, input().split())
s=str(input())
if s[b]=="A":
  s[b]=="a"
if s[b]=="B":
  s[b]=="b"
if s[b]=="C":
  s[b]=="c"
print(s)
Problem p03072 (python)

Fixed submission:
n=int(input())
l=list(map(int, input().split()))
cnt=0
a=l[0]
for i in range(n):
  if a<=l[i]:
    cnt=cnt+1
    a=l[i]

print(cnt)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=int(input())
cnt=1
for i in range(n-1):
  b=int(input())
  if a<=b:
    cnt++
    a=b

print(cnt)