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

Fixed submission:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

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

import fractions
from functools import reduce
def calc_gcd(A):
    return reduce(fractions.gcd, A)

N,K = LI()
A = LI()

g = calc_gcd(A)
if K%g == 0 and K <= max(A):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

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

from functools import reduce
def calc_gcd(A):
    return reduce(math.gcd, A)

N,K = LI()
A = LI()

g = calc_gcd(A)
if K%g == 0 and K <= max(A):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
Problem p03086 (python)

Fixed submission:
S = input()
N = len(S)
ans = 0
for i in range(N):
    for j in range(i, N):
        if all('ACGT'.count(c) == 1 for c in S[i : j + 1]):
            ans = max(ans, j - i + 1)
print (ans)

Buggy submission (verdict: Runtime Error):
b = input()
c = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}
print (c[b])
Problem p03633 (python)

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

def lcm(a, b):
    return a * b // gcd(a, b)

n = int(input())
ans = 1
for i in range(n):
    t = int(input())
    ans = lcm(ans, t)

print (ans)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    if (a % b == 0):
        return b
    else:
        return gcd(b, a%b)

def lcm(a, b):
    return int(a / gcd(a, b)) * b

n = int(input())

time = 1
for i in range(n):
    t = int(input())
    time = lcm(time, t)

print (time)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    if (a % b == 0):
        return b
    else:
        return gcd(b, a%b)

def lcm(a, b):
    return int(a*b/gcd(a, b))

n = int(input())

time = 1
for i in range(n):
    t = int(input())
    time = lcm(time, t)

print (time)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    if (a % b == 0):
        return b
    else:
        return gcd(b, a%b)

def lcm(a, b):
    return int(a*b/gcd(a, b))

n = int(input())
t_list = []
for i in range(n):
    t_list.append(int(input()))

time = 1
for i in range(n):
    time = lcm(time, t_list[i])

print (time)
Problem p02548 (python)

Fixed submission:
N = int(input())

ans = 0
for i in range(1,N):
	ans += (N-1)//i
print(ans)

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

ans = 0
for i in range(1,N);
	ans += (N-1)//i
print(ans)

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

def f(x):
  i = 1
  count = 0
  while i**2 < x:
    if x % i == 0: count += 2
    i += 1
  if i**2 == x: count += 1
  return count
  

dp = [0]*N
for i in range(1,N):
  dp[i] = dp[i-1] + f[i+1]

print(dp[N-1])
Problem p02646 (python)

Fixed submission:
import numpy as np

A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if V <= W:
    print("NO")
elif np.abs(A - B) / (V - W) <= T: print("YES")
else:
    print("NO")

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

A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if V <= W: print("NO")
elif: np.abs(A-B)/(V-W) <= T: print("YES")
else: print("NO")
Problem p02657 (python)

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

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
print a*b
Problem p02658 (python)

Fixed submission:
N = int(input())
nums = list(map(int, input().split()))

cumul = 1
if 0 in nums:
    print(0)
else:
    for i in range(N):
        cumul *= nums[i]
        if cumul > 10 ** 18:
            print(-1)
            break
    if cumul <= 10 ** 18: print(cumul)

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

cumul = 1
if 0 in nums: print(0)
else:
	for i in range(N):
    	cumul *= nums[i]
		if cumul > 10 ** 18:
      		print(-1)
      		break
	if cumul <= 10 ** 18: print(cumul)

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

cumul = 1
for i in range(N):
    cumul *= nums[i]

if cumul > 10 ** 18: print(-1)
elif:print(cumul)

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

cumul = 1
for i in range(N):
  	cumul *= nums[i]
    if cumul > 10**18:
    	print(-1)
        break

if cumul < 10**18: print(cumul)
Problem p02660 (python)

Fixed submission:
import math

N = int(input())

p = 2
counter = 0
while N != 1:
 if p > math.sqrt(N):
  counter += 1
  break
 ind = 0
 n = -1
 while N % p == 0:
  N //= p
  ind += 1
 if ind == 0:
  p += 1
  continue
 while (n+1)*(n+2)//2 <= ind:
  n += 1
 counter += n
 p += 1

print(counter)

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

p = 2
counter = 0
while N != 1:
  ind = 0
  n = -1
  while N % p == 0:
    N //= p
    ind += 1
  while (n+1)(n+2)//2 <= ind:
    n += 1
  counter += n
  p += 1

print(counter)
Problem p02678 (python)

Fixed submission:
N, M = map(int, input().split())
adj = {}
for i in range(N):
    adj[i + 1] = []
for i in range(M):
    v1, v2 = map(int, input().split())
    adj[v1].append(v2)
    adj[v2].append(v1)

visited = {1}
parent = {1: None}
frontier = [1]
while frontier:
    nxt = []
    for u in frontier:
        for v in adj[u]:
            if v not in visited:
                parent[v] = u
                nxt.append(v)
                visited.add(v)
    frontier = nxt

if len(visited) < N:
    print("No")
else:
    print("Yes")
    for i in range(2, N + 1):
        print(parent[i])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
adj = {}
for i in range(N):
  adj[i+1] = []
for i in range(M):
  v1, v2 = map(int, input().split())
  adj[v1].append(v2)
  adj[v2].append(v1)

visited = {1}
parent = {1: None}
frontier = [1]
while frontier:
  nxt = []
  for u in frontier:
    for v in adj[u]:
      if v not in visited:
        parent[v] = u
        nxt.append[v]
        visited.add[v]
  frontier = nxt

if len(visited) < N: print("No")
else:
  print("Yes")
  for i in range(2,N+1):
    print(parent[i][0])
Problem p02657 (python)

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

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[int(z) for z in input().split()]
x=1
for i in a:
    x*=i
    if x>10**18:
        print("-1")
        break
if x<=10**18:
    print(x)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[int(z) for z in input().split()]
x=1
for i in a:
    x*=i
    if x>10**18:
        print("-1")
        break
print(x)
Problem p02658 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
 
mul=1
if 0 in A:print("0")
else:
    for i in range(N):
        mul*=A[i]
        if mul>pow(10,18):
            print("-1")
            break
        elif i==N-1:print(mul)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[input().split()]
x=1
for i in range(n):
    x*=int(a[i])
if x>10**18:
    print("-1")
else:
    print(x)
Problem p02681 (python)

Fixed submission:
S=input()
T=input()
ans=1
for i in range(len(S)):
    if S[i]!=T[i]:
        ans=0
        break
if ans==1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a,b,c,k=map(int,input().split())
ans=a
if k-a<=0:
    print(k)
    exit()
if k-a-b<=0:
    print(ans)
    exit()
if k-a-b-c<0:
    ans=ans+(k-a-b)*(-1)
    print(ans)
else:
    ans=ans-c
    print(ans)
Problem p02899 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache
import heapq

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

MOD = int(1e09) + 7

def main():
    N = cin.int()
    A = cin.mapInt()
    T = [0] * N
    for i in range(N): 
        T[A[i] - 1] = i + 1
    print(*T,sep =" ")
    return

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache
import heapq

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

MOD = int(1e09) + 7

def main():
    N = cin.int()
    A = cin.mapInt()
    T = [0] * N
    for i in range(N): 
        T[A[i] - 1] = i + 1
    print(*T," ")
    return

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

Fixed submission:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)

N,X = cin.mapInt()
A = cin.mapInt()
A.append(X)

def solve():
    A.sort()
    subs = [0] * (N)
    for i in range(N):
        subs[i] = A[i + 1] - A[i]
    ans = subs[0]
    for i in range(1,N):
        ans = Math.gcd(ans,subs[i])
    return ans
print(solve())

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x

N,X = cin.mapInt()
A = cin.mapInt()
A.append(X)

def solve():
    A.sort()
    subs = [0] * (N)
    for i in range(N):
        subs[i] = A[i + 1] - A[i]
    ans = subs[0]
    for i in range(1,N - 1):
        ans = math.gcd(ans,subs[i])
    return ans
print(solve())
Problem p03919 (python)

Fixed submission:
from sys import stdin

def readString() :
    return  stdin.readline().rstrip()

def solve() :
    H,W = [int(x) for x in stdin.readline().rstrip().split()]

    table = [stdin.readline().rstrip().split() for _ in range(H)]

    l = [chr(i) for i in range(65, 65+26)]
    for h in range(0,H) :
        for w in range(0,W) :
            if(table[h][w] == "snuke"):
                print(l[w] + "" + str(h + 1))
solve();

Buggy submission (verdict: Runtime Error):
from sys import stdin

def readString() :
    return  stdin.readline().rstrip()

def solve() :
    H,W = [int(x) for x in stdin.readline().rstrip().split()]

    table = [stdin.readline().rstrip().split() for _ in range(H)]

    l = [x for x in "ABCDEFGHIJK"]
    for h in range(0,H) :
        for w in range(0,W) :
            if(table[h][w] == "snuke"):
                print(l[w] + "" + str(h + 1))
solve();
Problem p04043 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    A = Scanner.map_int()
    d = defaultdict(int)
    for a in A:
        d[a] += 1
    print('YNEOS'[not (d[5] == 2 and d[7] == 1)::2])


if __name__ == "__main__":
    main()

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

if A[0] == 5 and A[1] == 5 and A[2] == 7:
    print("YES")
else:
    print("NO")
Problem p02584 (python)

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

x, k, d = map(int, input().split())
tmp = abs(x) // d

if k < tmp:
  result = abs(abs(x) - d*k)
elif tmp%2 == k%2:
  result = abs(abs(x) - d*tmp)
else:
  a = result = abs(abs(x) - d*tmp)
  result = abs(abs(a) - d)

print(result)

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

x, k, d = map(int, input().split())
dp = [None]*(1000000)
dp[0] = x

for i in range(1, k+1):
  x0, x1 = x+d, x-d
  if abs(x0) < abs(x1):
    x = x0
    dp[i] = x0
  else:
    x = x1
    dp[i] = x1
  if x == dp[i-2]:
    if i%2 != k%2:
      x = dp[i-1]
    break

print(abs(x))
Problem p02585 (python)

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

n, k = map(int, input().split())
parr = list(map(int, input().split()))
carr = list(map(int, input().split()))
scores = []

for i in range(n):
  cur = i
  # 1ループで通るノードの数とスコア
  roop_num = 0
  roop_score = 0
  while True:
    cur = parr[cur] - 1
    roop_num += 1
    roop_score += carr[cur]
    if cur == i:
      break
  tmp_max = -10**9
  # ループしたときにスコアが減るとき
  # kが1ループの回数より小さいとき
  if roop_score <= 0:
    score = 0
    max_iter = roop_num
  elif k <= roop_num:
    score = 0
    max_iter = k
  else:
    # ループする回数
    num = k // roop_num - 1
    score = roop_score*num
    max_iter = k - roop_num*num
  cur = i
  for _ in range(max_iter):
      cur = parr[cur] - 1
      score += carr[cur]
      if score > tmp_max:
        tmp_max = score
  scores += [tmp_max]

print(max(scores))

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

n, k = map(int, input().split())
parr = list(map(int, input().split()))
carr = list(map(int, input().split()))
scores = []

for i in range(n):
  cur = i
  # 1ループで通るノードの数とスコア
  roop_num = 0
  roop_score = 0
  while True:
    cur = parr[cur] - 1
    roop_num += 1
    roop_score += carr[cur]
    if cur == i:
      break
  tmp_max = -10**9
  # ループしたときにスコアが減るとき
  # kが1ループの回数より小さいとき
  if roop_score <= 0 or roop_num > k:
    score = 0
    max_iter = min(roop_num, k)
  else:
    # ループする回数
    n = k // roop_num
    score = roop_score*n
    max_iter = k - roop_num*n
  for _ in range(max_iter):
      cur = parr[cur] - 1
      score += carr[cur]
      if score > tmp_max:
        tmp_max = score
  scores += [tmp_max]

print(max(scores))

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

n, k = map(int, input().split())
parr = list(map(int, input().split()))
carr = list(map(int, input().split()))

dp = [[0]*n for _ in range(k+1)]
maximum = -10**9

for i in range(1, k+1):
    for j in range(n):
      tmp = dp[i-1][j] + carr[j]
      dp[i][parr[j]-1] = tmp
      if tmp > maximum:
        maximum = tmp

print(int(maximum))

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

n, k = map(int, input().split())
parr = list(map(int, input().split()))
carr = list(map(int, input().split()))

dp = np.zeros((k+1, n))
maximum = -10**9

for i in range(1, k+1):
    for j in range(n):
      tmp = dp[i-1][j] + carr[j]
      dp[i][parr[j]-1] = tmp
      if tmp > maximum:
        maximum = tmp

print(int(maximum))
Problem p02606 (python)

Fixed submission:
l, r, d = map(int, input().split())

count = 0
for i in range(l, r+1):
  if i % d == 0:
    count += 1

print(count)

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

for i in range(l, r+1):
  if i % d == 0:
    minimum = i
    break

for i in range(r, l-1, -1):
  if i % d == 0:
    maximum = i
    break

print(int((maximum - minimum) / d + 1))

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

for i in range(l, r+1):
  if i % d == 0:
    minimum = i
    break

for i in range(r, l-1, -1):
  if i % d == 0:
    maximum = i
    break

print(int((maximum - minimum) / d + 1))
Problem p02706 (python)

Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(m):
    n-=a[i]
if n>=0:
    print (n)
else:
    print (-1)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(m):
    m-=a[i]
if m>=0:
    print m
else:
    print -1
Problem p02609 (python)

Fixed submission:
n = int(input())
X = input()

def goes_to_zero(n):
  cnt = 0
  while(n > 0):
    n %= bin(n).count('1')
    cnt += 1
  return cnt
  
c1 = X.count('1')
xint = int(X,2)
xtp = xint % (c1 + 1)
if (c1 - 1) == 0:  
  xtm = 0
else:
  xtm = xint % (c1 - 1)
  
for i in range(n)  :
  if X[i] == '0':
    print(goes_to_zero( (xtp + pow(2,n-1-i,(c1+1))) % (c1+1) ) + 1)
  else:
    if (c1-1) == 0:
      print(0)
    else:
      print(goes_to_zero( (xtm - pow(2,n-1-i,(c1-1)) ) % (c1-1) ) +1)

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

def goes_to_zero(n):
  cnt = 0
  while(n > 0):
    n %= bin(n).count('1')
    cnt += 1
  return cnt
  
c1 = X.count('1')
xint = int(X,2)
xtp = xint % (c1 + 1)
if (c1 - 1) == 0:  
  xtm = 0
else:
  xtm = xint % (c1 - 1)
  
for i in range(n)  :
  if x[i] == '0':
    print(goes_to_zero( (xtp + pow(2,n-1-i,(c1+1))) % (c1+1) ) + 1)
  else:
    if (c1-1) == 0:
      print(0)
    else:
      print(goes_to_zero( (xtm - pow(2,n-1-i,(c1-1)) ) % (c1-1) ) +1)

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

x0 = int('0b'+x,0)

ceil = 2*10**5+2
ppc = [0]*(ceil)

def popcount(n):    
  if n == 0:
    return 0
  if ppc[n] != 0:
    return ppc[n]
    
  b = bin(n).count('1')  
  tmp = n%b
  ppc[n] = popcount(tmp) + 1
  return ppc[n]

c1 = bin(x0).count('1')  
for i in range(n):
  p = 2 ** (n - i - 1)
  if x[i] == '1':    
    tmp = x0 - p
    tmp2 = tmp % (c1 - 1)
  else:
    tmp = x0 + p  
    tmp2 = tmp % (c1 + 1)
    
  if tmp > ceil:      
    print(popcount(tmp2)+1)
  else:
    print(popcount(tmp))

Buggy submission (verdict: Runtime Error):

n = int(input())
x = input()

MAX = 2*10**5+1
ppc = [0]*MAX

def popcount(n):
  if ppc[n]>0:
    ppc[n]  
  if n == 0:
    return 0
  b = bin(n).count('1')  
  tmp = n%b
  ppc[n] = popcount(tmp) + 1
  return ppc[n]

for i in range(2*10**5):
  popcount(i+1)
  
bit = int('0b'+x,0)
bn = x.count('1')
for i in range(n,0,-1):
  tmp = bit ^ (1 << (i-1))
  if bit & (1 << (i-1)):
    bt = bn-1
  else:
    bt = bn+1    
  print(ppc[tmp%bt]+1)

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

MAX = 2*10**5+1
ppc = [0]*MAX

def popcount(n):
  if ppc[n]>0:
    ppc[n]  
  if n == 0:
    return 0
  b = bin(n).count('1')  
  tmp = n%b
  ppc[n] = popcount(tmp) + 1
  return ppc[n]

for i in range(2*10**5):
  popcount(i+1)
  
bit = int('0b'+x,0)

for i in range(n,0,-1):
  tmp = bit ^ (1 << (i-1))
  bn = bin(tmp).count('1')      
  print(ppc[tmp%bn]+1)
Problem p02621 (python)

Fixed submission:
a = int(input())
print(a + a**2 + a**3)

Buggy submission (verdict: Runtime Error):
a = input()
print(a + a**2 + a**3)
Problem p02665 (python)

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

L = [0]*(n+2)
R = [0]*(n+2)
L[n] = A[n]
R[n] = A[n]

for i in range(n,-1,-1):
  L[i] = A[i] + (L[i+1]+1)//2
  R[i] = A[i] + R[i+1]
  
if L[0]>1:
  print(-1)
else:
  tmp = 1
  ans = 0
  for i in range(n+1):
    ans += tmp
    tmp -= A[i]
    tmp = min(tmp*2,R[i+1])    
  print(ans)

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

L = [0]*(n+2)
R = [0]*(n+2)

for i in range(n,-1,-1):
  L[i] = A[i] + (L[i+1]+1)//2
  R[i] = A[i] + R[i+1]
  
if L[0] > 1:
  print(-1)
else:
  ans = 0
  tmp = 1
  for i in range(n+1):
    ans += tmp          
    tmp -= A[i]    
    tmp = min(tmp*2,R[i+1])
    
print(ans)