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

Fixed submission:
from functools import reduce
import heapq, sys


input = sys.stdin.readline
N = int(input())
XD = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[0], reverse=True)
P = 998244353


class Node:
    def __init__(self, ch):
        self.ch = ch
        if len(self.ch) == 0:
            self.score = 2
        else:
            self.score = reduce(lambda a, b: (a * b) % P, [ch.score for ch in self.ch]) + 1

hq = []  # (x, Node)
heapq.heapify(hq)
for x, d in XD:
    ch = []
    while len(hq) != 0 and hq[0][0] < x+d:
        ch.append(heapq.heappop(hq)[1])
    heapq.heappush(hq, (x, Node(ch)))

ans = reduce(lambda a, b: (a * b) % P, [node.score for x, node in hq])
print(ans)

Buggy submission (verdict: Runtime Error):
from functools import reduce
import heapq, sys


input = sys.stdin.readline
N = int(input())
XD = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[0], reverse=True)
P = 998244353


class Node:
    def __init__(self, ch):
        self.ch = ch

    def cal(self):
        if len(self.ch) == 0:
            return 2
        return reduce(lambda a, b: (a * b) % P, [ch.cal() for ch in self.ch]) + 1


hq = []  # (x, Node)
heapq.heapify(hq)
for x, d in XD:
    ch = []
    while len(hq) != 0 and hq[0][0] < x+d:
        ch.append(heapq.heappop(hq)[1])
    heapq.heappush(hq, (x, Node(ch)))

ans = reduce(lambda a, b: (a * b) % P, [node.cal() for x, node in hq])
print(ans)

Buggy submission (verdict: Runtime Error):
from functools import reduce
import heapq, sys


input = sys.stdin.readline
N = int(input())
XD = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[0], reverse=True)
P = 998244353


class Node:
    def __init__(self, ch):
        self.ch = ch

    def cal(self):
        if len(self.ch) == 0:
            return 2
        return reduce(lambda a, b: (a * b) % P, [ch.cal() for ch in self.ch]) + 1


hq = []  # (x, Node)
heapq.heapify(hq)
for x, d in XD:
    ch = []
    while len(hq) != 0 and hq[0][0] <= x+d:
        ch.append(heapq.heappop(hq)[1])
    heapq.heappush(hq, (x, Node(ch)))

ans = reduce(lambda a, b: (a * b) % P, [node.cal() for x, node in hq])
print(ans)
Problem p02902 (python)

Fixed submission:
import math
import sys
from collections import deque, defaultdict

N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
g = [set() for _ in range(N)]
for a, b in AB:
    g[a - 1].add(b - 1)


def find_loop(s, subnode):
    q = deque([(s, {s})])
    visited = defaultdict(lambda: math.inf)
    while len(q) > 0:
        node, p = q.popleft()
        for to_node in g[node] & subnode:
            if to_node == s:
                return p
            if visited[to_node] > len(p):
                visited[to_node] = len(p)
                q.append((to_node, p | {to_node}))
    return -1


V = set(range(N))
for i in range(N):
    subnode = find_loop(i, V)
    if subnode != -1:
        break
if subnode == -1:
    print(-1)
    sys.exit()


while True:
    # 条件判定
    flg = True
    for i in subnode:
        if len(g[i] & subnode) != 1:
            flg = False
            s = i
            break
    if flg:
        break
    subnode = find_loop(s, subnode)

print(len(subnode))
for node in subnode:
    print(node+1)

Buggy submission (verdict: Runtime Error):
import math

N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
d = [[math.inf]*N for _ in range(N)]
for a, b in AB:
    d[a-1][b-1] = 1


def warshall_floyd(d):
    for k in range(len(d)):
        for i in range(len(d)):
            for j in range(len(d)):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])


warshall_floyd(d)
min_d = min([d[i][i] for i in range(N)])
if min_d == math.inf:
    print(-1)
else:
    ans = []
    for i in range(N):
        if d[i][i] == min_d:
            ans.append(i + 1)
    if len(ans) != min_d:
        raise ValueError('同じループが二つ')
    print(min_d)
    for i in ans:
        print(i)
Problem p02985 (python)

Fixed submission:
import sys

input = sys.stdin.readline
N, K = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
P = int(1e9+7)
if N == 1:
    print(K % P)
    sys.exit(0)
kaizyo = [0]
kaizyo_inv = [0]
tmp = 1
for i in range(1, K+1):
    tmp = (tmp*i) % P
    kaizyo.append(tmp)
    kaizyo_inv.append(pow(tmp, P - 2, P))


def comb(n, r):
    if n < r or n < 0:
        return 0
    elif n == r or r == 0:
        return 1
    else:
        return kaizyo[n] * kaizyo_inv[r] * kaizyo_inv[n - r]


g=[[] for _ in range(N)]
for a, b in ab:
    g[a-1].append(b-1)
    g[b - 1].append(a - 1)

children = [[] for _ in range(N)]
q = [(0, None)]
while len(q) > 0:
    v, p = q.pop()
    for u in g[v]:
        if u != p:
            q.append((u, v))
            children[v].append(u)

if len(children[0]) > K - 1:
    print(0)
    sys.exit()
ans = 1
ans *= K
n_child = len(children[0])
ans = (ans * comb(K - 1, n_child)*kaizyo[n_child]) % P
q = [i for i in children[0]]
while len(q) > 0:
    v = q.pop()
    n_child = len(children[v])
    if n_child > K - 2:
        print(0)
        sys.exit()
    if n_child != 0:
        ans = (ans * comb(K - 2, n_child)*kaizyo[n_child]) % P
    q += children[v]
print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
if N < 10:
  raise ValueError
print(1)

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline
N, K = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
P = int(1e9+7)
kaizyo = [0]
kaizyo_inv = [0]
tmp = 1
for i in range(1, K+1):
    tmp = (tmp*i) % P
    kaizyo.append(tmp)
    kaizyo_inv.append(pow(tmp, P - 2, P))


def comb(n, r):
    if n < r or n < 0:
        return 0
    elif n == r or r == 0:
        return 1
    else:
        return kaizyo[n] * kaizyo_inv[r] * kaizyo_inv[n - r]


g=[[] for _ in range(N)]
for a, b in ab:
    g[a-1].append(b-1)
    g[b - 1].append(a - 1)

children = [[] for _ in range(N)]
q = [(0, None)]
while len(q) > 0:
    v, p = q.pop()
    for u in g[v]:
        if u != p:
            q.append((u, v))
            children[v].append(u)

ans = 1
ans *= K
ans = (ans * comb(K - 1, len(children[0]))*kaizyo[len(children[0])]) % P
q = [i for i in children[0]]
while len(q) > 0:
    v = q.pop()
    if len(children[v]) != 0:
        ans = (ans * comb(K - 2, len(children[v]))*kaizyo[len(children[v])]) % P
    q += children[v]
print(ans)
Problem p02684 (python)

Fixed submission:
n,k=map(int, input().split())
a=list(map(int, input().split()))
b=[False]*n
pos=0
for i in range(min(n,k)):
    if b[pos]!=False:
        loop=i-b[pos]+1
        break
    b[pos]=i+1
    pos=a[pos]-1
    k-=1
if k>0:
    for i in range(k%loop):
        pos=a[pos]-1
print(pos+1)

Buggy submission (verdict: Runtime Error):
n,k=map(int, input().split())
a=list(map(int, input().split()))
b=[False]*n
pos=0
for i in range(k):
    if b[pos]!=False:
        loop=i-b[pos]+1
        break
    b[pos]=i+1
    pos=a[pos]-1
    k-=1

for i in range(k%loop):
    pos=a[pos]-1
print(pos+1)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
next=0
visited=[0]*n #index:訪れたとき
teleport=[] #index
for i in range(k):
    now=next
    if visited[now]==0:
        visited[now]=i+1
        teleport.append(now)
        next=a[now]-1
        k-=1
    else:
        loop=i+1-visited[now]
        break
print(teleport[len(teleport)-loop+k%loop]+1)
Problem p02854 (python)

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

len=sum(a)
len_l=0
for i in range(n):
    if len/2>len_l:
        len_l+=a[i]
    else:
        center=i-1
        break
else:
    center=n-1
    
len_r=len-len_l
len_l-=a[center]
#半分との差
d=len/2-max(len_r,len_l)

print(int(d*2))

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

len=sum(a)
len_l=0
for i in range(n):
    if len/2>len_l:
        len_l+=a[i]
    else:
        center=i-1
        break
len_r=len-len_l
len_l-=a[center]

#半分との差
d=len/2-max(len_r,len_l)

print(int(d*2))
Problem p03076 (python)

Fixed submission:
x=[int(input()) for _ in range(5)]
r=list(map(lambda a: a%10,x))
min = min(list(filter(lambda x: x>0, r))+[10])
ans=0
for i in range(5):
    ans+=-(-x[i]//10)*10
ans+= min-10
print(ans)

Buggy submission (verdict: Runtime Error):
x = [int(input()) for _ in range(5)]
r = list(map(lambda a: a%10,x))
min = min(filter(lambda x: x>0, r))
ans=0
for i in range(5):
    ans+=-(-x[i]//10)*10
ans+= min-10
print(ans)
Problem p03163 (python)

Fixed submission:
n,w=map(int, input().split())
weight=[0]*n
value=[0]*n
for i in range(n):
    weight[i],value[i]=map(int,input().split())

dp=[[0]*(w+1) for i in range(n+1)]
for i in range(n):
    for sum_w in range(w+1):
        # i番目の品物を選ぶ場合
        if sum_w -  weight[i] >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - weight[i]]+value[i])
        # i番目の品物を選ばない場合
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])
print(dp[n][w])

Buggy submission (verdict: Runtime Error):
n,w=map(int, input().split())
weight=[0]*n
value=[0]*n
for i in range(n):
    weight[i],value[i]=map(int,input().split())

dp=[[0]*(n+10) for i in range(100100)]
for i in range(n):
    for sum_w in range(w+1):
        # i番目の品物を選ぶ場合
        if sum_w -  weight[i] >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - weight[i]]+value[i])
        # i番目の品物を選ばない場合
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])
print(dp[n][w])
Problem p03263 (python)

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

ans=[]
for i in range(h):
    for j in range(w-1):
        if a[i][j]%2==1:
            a[i][j+1]+=1
            ans.append([i+1,j+1,i+1,j+2])

for i in range(h-1):
    if a[i][w-1]%2==1:
        a[i+1][w-1]+=1
        ans.append([i+1,w,i+2,w])
print(len(ans))
for i in ans:
    print(*i)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
a=[list(map(int,list(input().split()))) for _ in range(h)]

ans=[]
for i in range(h):
    for j in range(w-1):
        if a[i][j]%2==1:
            a[i][j+1]+=1
            ans.append([i+1,j+1,i+1,j+2])

for i in range(h-1):
    if a[i][-1]%2==1:
        a[i+1][-1]+=1
        ans.append([i+1,j+1,i+2,j+1])

print(len(ans))
for i in ans:
    print(*i)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
a=[list(map(int,list(input().split()))) for _ in range(h)]

ans=[]
for i in range(h):
    for j in range(w-1):
        if a[i][j]%2==1:
            a[i][j+1]+=1
            ans.append([i+1,j+1,i+1,j+2])

for i in range(h):
    if a[i][-1]%2==1:
        a[i+1][-1]+=1
        ans.append([i+1,j+1,i+2,j+1])

print(len(ans))
for i in ans:
    print(*i)
Problem p03436 (python)

Fixed submission:
from collections import deque

def make_wall(maze,h,w):
    maze=deque(maze)
    for i in range(h):
        maze[i]="#"+maze[i]+"#"
    maze.appendleft("#"*(w+2))
    maze.append("#"*(w+2))
    return list(maze)

def bfs(maze, visited, sy, sx, gy, gx):
    queue = deque([[sy, sx]])
    visited[sy][sx] = 0
    while queue:
        y, x = queue.popleft()
        if [y, x] == [gy, gx]:
            return visited[y][x]
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y+j, x+k
            if maze[new_y][new_x] == "." and visited[new_y][new_x]==-1:
                visited[new_y][new_x]=visited[y][x]+1
                queue.append([new_y,new_x])
    return -1

h,w=map(int,input().split())
maze=[input() for _ in range(h)]
kabe=0
for i in range(h):
    kabe+=maze[i].count("#")
maze=make_wall(maze,h,w)
visited=[[-1]*(w+2) for _ in range(h+2)]
sy,sx=1,1
gy,gx=h,w
d=1+bfs(maze, visited, sy, sx, gy, gx)
if d==0:
    print(-1)
else:
    print(h*w-kabe-d)

Buggy submission (verdict: Runtime Error):
from collections import deque

def make_wall(maze,h,w):
    maze=deque(maze)
    for i in range(h):
        maze[i]="#"+maze[i]+"#"
    maze.appendleft("#"*(w+2))
    maze.append("#"*(w+2))
    return list(maze)

def bfs(maze, visited, sy, sx, gy, gx):
    queue = deque([[sy, sx]])
    visited[sy][sx] = 0
    while queue:
        y, x = queue.popleft()
        if [y, x] == [gy, gx]:
            return visited[y][x]
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y+j, x+k
            if maze[new_y][new_x] == "." and visited[new_y][new_x]==-1:
                visited[new_y][new_x]=visited[y][x]+1
                queue.append([new_y,new_x])

h,w=map(int,input().split())
maze=[input() for _ in range(h)]
kabe=0
for i in range(h):
    kabe+=maze[i].count("#")
maze=make_wall(maze,h,w)
visited=[[-1]*(w+2) for _ in range(h+2)]
sy,sx=1,1
gy,gx=h,w
d=1+bfs(maze, visited, sy, sx, gy, gx)
print(h*w-kabe-d)
Problem p03545 (python)

Fixed submission:
def calc(a,b,f):
    a=int(a)
    b=int(b)
    if f==0:
        return a+b
    else:
        return a-b

s=input()
op=[0]*3
for i in range(2):
    a=calc(s[0],s[1],i)
    for j in range(2):
        b=calc(a,s[2],j)
        for k in range(2):
            c=calc(b,s[3],k)
            if c==7:
                ret=[i,j,k]               
for i in range(3):
    if ret[i]==0:
        ret[i]="+"
    else:
        ret[i]="-"
for i in range(3):
    print(s[i]+ret[i],sep="",end="")
print(s[3]+"=7")

Buggy submission (verdict: Runtime Error):
s=input()
op=[0]*3
for i in range(2):
    a=calc(s[0],s[1],i)
    for j in range(2):
        b=calc(a,s[2],j)
        for k in range(2):
            c=calc(b,s[3],k)
            if c==7:
                ret=[i,j,k]               
for i in range(3):
    if ret[i]==0:
        ret[i]="+"
    else:
        ret[i]="-"
for i in range(3):
    print(s[i]+ret[i],sep="",end="")
print(s[3]+"=7")

Buggy submission (verdict: Runtime Error):
def calc(a,b,f):
    if f==0:
        return a+b
    else:
        return a-b
s=input()
op=[0]*3
for i in range(2):
    tmp=calc(int(s[0]),int(s[1]),i)
    for j in range(2):
        tmp=calc(tmp,int(s[2]),j)
        for k in range(2):
            tmp=calc(tmp,int(s[3]),k)
            if tmp==7:
                ret=[i,j,k]
for i in range(3):
    if ret[i]==0:
        ret[i]="+"
    else:
        ret[i]="-"
for i in range(3):
    print(s[i]+ret[i],sep="",end="")
print(s[3]+"=7")
Problem p03605 (python)

Fixed submission:
s=input()
if "9" in s:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
s=input()
if "9" in s:
    print("Yes")
else:
    print("No"
Problem p03695 (python)

Fixed submission:
n=int(input())
a=list(map(int, input().split()))
col=[0]*9
for i in range(n):
    j=min(8, a[i]//400)
    col[j]+=1
zero=0
cnt=0
for c in range(len(col)-1):
    if col[c]==0:
        zero+=1
    else:
        cnt+=1
m=max(cnt,1)
M=cnt+col[-1]
print(m,M)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int, input().split()))
col=[0]*9
for i in range(n):
    col[a[i]//400]+=1
zero=0
cnt=0
for c in range(len(col)-1):
    if col[c]==0:
        zero+=1
    else:
        cnt+=1
m=max(cnt,1)
M=cnt+min(zero,col[-1])
print(m,M)
Problem p02823 (python)

Fixed submission:
N, A, B = map(int, input().split())

dif = B-A
if dif%2 == 0:
  print(dif//2)
else:
  print(min(A-1, N-B)+1+dif//2)

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

dif = B-A
if dif%2 == 0:
  print(int(dif/2))
else:
  print(min(A-1, N-B)+1+int((dif//2))
Problem p03111 (python)

Fixed submission:
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9
def dfs(cur, a, b, c):
	if cur == N:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
	ret0 = dfs(cur + 1, a, b, c)
	ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
	ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
	ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
	return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))

Buggy submission (verdict: Runtime Error):
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9
def dfs(cur, a, b, c):
if cur == N:
	return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
ret0 = dfs(cur + 1, a, b, c)
ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))

Buggy submission (verdict: Runtime Error):
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9
def dfs(cur, a, b, c):
if cur == N:
return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
ret0 = dfs(cur + 1, a, b, c)
ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))
Problem p02576 (python)

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

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N,X,T=mi()
    print(T*math.ceil(N/X))





if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import os
f = open('/Users/yuigawada/Desktop/競プロ/Atcoder/input.txt', 'r')
sys.stdin = f


import itertools
import numpy as np
import fractions
from itertools import combinations
from functools import reduce
from functools import lru_cache
import math
from collections import deque
import decimal
import bisect
import heapq
# ---*- start -*--- #
import math
import sys
sys.setrecursionlimit(10**9)



def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def solve(N,X,T):
    print(T*math.ceil(N/X))
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    solve(N, X, T)



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

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

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    j = math.ceil((N+1)**0.5)

    ans = [0] * (N+1)
    for x in range(1,j+1):
        for y in range(1,j+1):
            for z in range(1,j+1):
                n = x**2+y**2+z**2+x*y+y*z+z*x
                if 1<=n<=N:
                    ans[n] += 1
            
        
    print(*ans[1:],sep="\n")

                


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    j = math.ceil((N+1)**0.5)

    ans = [0] * (N+1)
    for x in range(1,j+1):
        for y in range(1,j+1):
            for z in range(1,j+1):
                n = x**2+y**2+z**2+x*y+y*z+z*x
                if 1<=n<=N:
                    ans[n] += 1
            
        
    print(*ans[1:],sep="\n")

                


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

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

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    X=input()

    x=int(X,2)
    pop_X=bin(x).count("1")

    pm1 = x % (pop_X-1) if pop_X-1 else 0
    pp1 = x % (pop_X+1)
    
    for i in range(N):
        sign = 1
        pop_Xi = pop_X
        if X[i] == "1": 
            sign *= -1
            pop_Xi -= 1
            _x = pm1
        else:
            pop_Xi += 1
            _x = pp1
        
        if pop_Xi == 0:
            print(0)
            continue
        
        
        two = pow(2,N-1-i,pop_Xi)
        X_i = _x + sign * two
        X_i %= pop_Xi
        count = 1
        while X_i:
            pop_Xi = bin(X_i).count("1")
            X_i = X_i % pop_Xi
            count += 1

        print(count)



if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    X=input()

    x=int(X,2)
    pop_X=bin(x).count("1")

    pm1 = x % (pop_X-1)
    pp1 = x % (pop_X+1)
    
    for i in range(N):
        sign = 1
        pop_Xi = pop_X
        if X[i] == "1": 
            sign *= -1
            pop_Xi -= 1
            _x = pm1
        else:
            pop_Xi += 1
            _x = pp1
        
        if pop_Xi == 0:
            print(0)
            continue
        
        
        two = pow(2,N-1-i,pop_Xi)
        X_i = _x + sign * two
        X_i %= pop_Xi
        count = 1
        while X_i:
            pop_Xi = bin(X_i).count("1")
            X_i = X_i % pop_Xi
            count += 1

        print(count)



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

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

def main():
    S = input()
    T = input()

    if S == T[:-1] and len(T) == 1 + len(S):
        print("Yes")
        exit()

    print("No")




if __name__ == "__main__":
  main()

Buggy submission (verdict: Runtime Error):
import math
sys.setrecursionlimit(10**9)

def main():
    S = input()
    T = input()

    if S == T[:-1] and len(T) == 1 + len(S):
        print("Yes")
        exit()

    print("No")




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

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

def main():
    A,B,N = map(int,input().split())

    def f(x):
        return math.floor((A*x)/B) - A * math.floor(x/B)
	
    print(f(min(B-1,N)))


if __name__ == "__main__":
  main()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

def main():
    A,B,N = map(int,input().split())

    def f(x):
        return math.floor((A*x)/B) - A * math.floor(x/B)

    def bin(a):
        left = 0
        right = A+1

        while right-left > 1:
            x = (right+left) // 2
            # print(left,right)
            if f(x) < a:
                left = x
            else:
                right = x

        # print("____")
        # print(right)
        return right


    for _a in range(A+1):
        a = A - _a
        x = bin(a)
        # print(x,a)
        if 0<=x<=N and f(x) == a:
            print(a)
            exit()


if __name__ == "__main__":
  main()