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

Fixed submission:
S = input()

A = 'gp' * (len(S)//2)
if len(S) % 2 == 1:
  A += 'g'
ans = 0
for i in range(len(S)):
  if S[i] == 'p' and A[i] == 'g':
    ans -= 1
  elif S[i] == 'g' and A[i] == 'p':
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()

def dfs(p,a):
  if p == len(S):
    return 0
  if a > 0 and S[p] == 'g':
    return max(1+dfs(p+1,a-1),dfs(p+1,a+1))
  elif a > 0 and S[p] == 'p':
    return max(dfs(p+1,a-1),-1+dfs(p+1,a+1))
  elif a == 0 and S[p]  == 'g':
    return dfs(p+1,a+1)
  else:
    return -1+dfs(p+1,a+1)

print(dfs(0,0))
Problem p03999 (python)

Fixed submission:
S = input()

if len(S) == 1:
  print(int(S))
else:
  ans = 0
  for i in range(1<<(len(S)-1)):
    SP = []
    for j in range(len(S)-1):
      if (i>>j)&1 == 1:
        SP.append(j)
    SP += [len(S)-1]
    #print(SP)
    idx = 0
    for sp in SP:
      ans += int(S[idx:sp+1])
      idx = sp+1
  print(ans)

Buggy submission (verdict: Runtime Error):
S = input()

if len(S) == 1:
  print(int(S))
else:
  ans = 0
  for i in range(1<<(len(S)-1)):
    SP = []
    for j in range(len(S)-1):
      if (i>>j)&1 == 1:
        SP.append(j)
    SP += [len(S)-1]
    #print(SP)
    idx = 0
    for sp in SP:
      ans += int(S[idx:sp+1])
      idx = sp+1
print(ans)
Problem p04015 (python)

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

MAXSUM = sum(X)+5
dp = [[[0 for _ in range(MAXSUM)] for _ in range(N+5)] for _ in range(N+5)]
for i in range(N):
  dp[i+1][1][X[i]] += 1
  for k in range(N):
    for j in range(MAXSUM):
      dp[i+1][k][j] += dp[i][k][j]
      if X[i]+j < MAXSUM:
        dp[i+1][k+1][X[i]+j] += dp[i][k][j]
#print(dp)
ans = 0
for i in range(N):
  if A*(i+1) < MAXSUM:
    ans += dp[N][i+1][A*(i+1)]
print(ans)

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

MAXSUM = sum(X)+5
dp = [[[0 for _ in range(MAXSUM)] for _ in range(N+5)] for _ in range(N+5)]
for i in range(N):
  dp[i+1][1][X[i]] += 1
  for k in range(N):
    for j in range(MAXSUM):
      dp[i+1][k][j] += dp[i][k][j]
      if X[i]+j < MAXSUM:
        dp[i+1][k+1][X[i]+j] += dp[i][k][j]
#print(dp)
ans = 0
for i in range(N):
  ans += dp[N][i+1][A*(i+1)]
print(ans)
Problem p02573 (python)

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):

        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]


if __name__ == "__main__":
    N, M = map(int, input().split()) 
    union_find = UnionFind(N)
    for _ in range(M):
        A, B = map(int, input().split())
        A -= 1
        B -= 1
        union_find.union(A, B)

    answer = 0
    for i in range(N):
        answer = max(answer, union_find.size(i))

    print(answer)

Buggy submission (verdict: Runtime Error):
class UnionFind(): 
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):

        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]


if __name__ == "__main__":
    N, M = map(int, input().split()) 
    union_find = UnionFind(N)
    for _ in range(M):
        A, B = map(int, input().split())
        A -= 1
        B -= 1
        union_find.union(A, B)

    answer = 0
    for i in range(N):
        answer = max(answer, union_find.size(i))

    print(answer)
Problem p02681 (python)

Fixed submission:
s = input()
t = input()
t2 = t[:-1]

if s == t2:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
s = input()
t = input()

print(t2)
if s == t2:
    print("Yes")
else:
    print("No")
Problem p02705 (python)

Fixed submission:
print(float(input())*2*3.14)

Buggy submission (verdict: Runtime Error):
print(float(input())*2*3.14
Problem p02768 (python)

Fixed submission:
import sys
readline = sys.stdin.readline
read = sys.stdin.read
n,a,b = [int(i) for i in read().split()]

MOD = 10**9+7
ans = pow(2,n,MOD)-1

# 全部の場合から、aとbの場合を引き算する
def choose(n,r):
    res = 1
    fac = 1
    for i in range(r):
        res *= n-i
        res %= MOD
        fac *= i+1
        fac %= MOD
    return res*pow(fac,MOD-2,MOD)%MOD        

ans -= choose(n,a)
ans -= choose(n,b)
print(ans%MOD)

Buggy submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline
read = sys.stdin.read
n,a,b = [int(i) for i in read().split()]
MOD = 10**9+7
ans = pow(2,n,MOD)-1

def choose(n,r):
    res = 1
    fac = 1
    for i in range(r):
        res *= n-i
        res %= MOD
        fac *= i+1
        fac %= MOD
    return res*pow(fac,MOD-2,MOD)%MOD        

  ans -= choose(n,a)
ans -= choose(n,b)
print(ans%MOD)
Problem p02936 (python)

Fixed submission:
# 解説動画から累積和ポイント。 
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
N,Q = map(int,input().split())
ABList = [list(map(int,list(input().split()))) for i in range(N-1)]  
PXList = [list(map(int,list(input().split()))) for i in range(Q)]  
 
# N+1 にしているのは、dfs関数でparentsを使う時に合わせるため 
graph=[[] for _ in range(N+1)]
values=[0]*(N+1)
 
for a,b in ABList:
    graph[a].append(b)
    graph[b].append(a)
    # aとbを入れ替えて
    # graphは例１の時、[[], [2], [1, 3, 4], [2], [2]] になる
    # 頂点がどことつながっているか 
for p,x in PXList:
    values[p]+=x
    # p をキーにしているのでNの昇順ｘにしている
    # 例１であれば[0, 100, 10, 1, 0]　累積和する前の値をもつ
 
def dfs(x,parent,add):
    # 累積和をvaluesに計算していく
    values[x]+=add
    for i in graph[x]:
        # continueはループの残りを飛ばして次の反復へ
        # 親と子判定
        if i==parent:
            continue
        dfs(i,x,values[x])
 
dfs(1,0,0)
 
print(' '.join(map(str,values[1:])))
# 難しい。graph[x]の使い方の理解がまだまだ

Buggy submission (verdict: Runtime Error):
# 解説動画から累積和ポイント。 
N,Q = map(int,input().split())
ABList = [list(map(int,list(input().split()))) for i in range(N-1)]  
PXList = [list(map(int,list(input().split()))) for i in range(Q)]  
 
# N+1 にしているのは、dfs関数でparentsを使う時に合わせるため 
graph=[[] for _ in range(N+1)]
values=[0]*(N+1)
 
for a,b in ABList:
    graph[a].append(b)
    graph[b].append(a)
    # aとbを入れ替えて
    # graphは例１の時、[[], [2], [1, 3, 4], [2], [2]] になる
    # 頂点がどことつながっているか 
for p,x in PXList:
    values[p]+=x
    # p をキーにしているのでNの昇順ｘにしている
    # 例１であれば[0, 100, 10, 1, 0]　累積和する前の値をもつ
 
def dfs(x,parent,add):
    # 累積和をvaluesに計算していく
    values[x]+=add
    for i in graph[x]:
        # continueはループの残りを飛ばして次の反復へ
        # 親と子判定
        if i==parent:
            continue
        dfs(i,x,values[x])
 
dfs(1,0,0)
 
print(' '.join(map(str,values[1:])))
# 難しい。graph[x]の使い方の理解がまだまだ
Problem p02534 (python)

Fixed submission:
K = int(input())

if K == 1:
    print("ACL")
elif K == 2:
    print("ACLACL")
elif K == 3:
    print("ACLACLACL")
elif K == 4:
    print("ACLACLACLACL")
else:
    print("ACLACLACLACLACL")

Buggy submission (verdict: Runtime Error):
K = input()

if K == 1:
    print("ACL"):
elif K == 2:
    print("ACLACL"):
elif K == 3:
    print("ACLACLACL"):
elif K == 4:
    print("ACLACLACLACL"):
else:
    print("ACLACLACLACLACL"):

Buggy submission (verdict: Runtime Error):
K = input()

if K == 1:
  print("ACL"):
elif K == 2:
  print("ACLACL"):
elif K == 3:
  print("ACLACLACL"):
elif K == 4:
  print("ACLACLACLACL"):
else:
  print("ACLACLACLACLACL"):

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

if K == 1:
    print("ACL"):
elif K == 2:
    print("ACLACL"):
elif K == 3:
    print("ACLACLACL"):
elif K == 4:
    print("ACLACLACLACL"):
else:
    print("ACLACLACLACLACL"):

Buggy submission (verdict: Runtime Error):
K = input()

if K == 1:
  print("ACL"):
elif K == 2:
  print("ACLACL"):
elif K == 3:
  print("ACLACLACL"):
elif K == 4:
  print("ACLACLACLACL"):
else:
  print("ACLACLACLACLACL"):

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

if K == 1:
  print("ACL"):
elif K == 2:
  print("ACLACL"):
elif K == 3:
  print("ACLACLACL"):
elif K == 4:
  print("ACLACLACLACL"):
else:
  print("ACLACLACLACLACL"):

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

if n == 1:
  print("ACL"):
elif n == 2:
  print("ACLACL"):
elif n == 3:
  print("ACLACLACL"):
elif n == 4:
  print("ACLACLACLACL"):
else:
  print("ACLACLACLACLACL"):

Buggy submission (verdict: Runtime Error):
s = input()

if s == 1:
  print("ACL"):
elif s == 2:
  print("ACLACL"):
elif s == 3:
  print("ACLACLACL"):
elif s == 4:
  print("ACLACLACLACL"):
else:
  print("ACLACLACLACLACL"):

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

if s == 1:
  print("ACL"):
elif s == 2:
  print("ACLACL"):
elif s == 3:
  print("ACLACLACL"):
elif s == 4:
  print("ACLACLACLACL"):
else:
  peint("ACLACLACLACLACL"):
Problem p02536 (python)

Fixed submission:
n,m=map(int,input().split())
par=[-1 for _ in range(n)]
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x]) #経路圧縮
        return par[x]

def unite(x,y):
    x = find(x)
    y = find(y)

    if x != y:
        x,y=y,x
    else:
        return
    par[x]+=par[y]

    par[y] = x
for _ in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    unite(a,b)

ans=0
for i in par:
    if i<0:
        ans+=1
print(ans-1)

Buggy submission (verdict: Runtime Error):
m,n=map(int,input().split())
par=[i for i in range(m)]
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x]) #経路圧縮
        return par[x]
def same(x,y):
    return find(x) == find(y)
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    par[x] = y
for i in range(n):
    a,b=map(int,input().split())
    unite(a,b)

print(len(set(par))-1)
Problem p02713 (python)

Fixed submission:
k=int(input())
from math import gcd
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for s in range(1,k+1):
            ans+=gcd(gcd(i,j),s)
print(ans)

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

ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        an=fractions.gcd(i,j)
        for s in range(1,k+1):
            anse=fractions.gcd(s,an)
            ans+=anse
print(ans)
Problem p02731 (python)

Fixed submission:
l=int(input())
print(l**3/27)

Buggy submission (verdict: Runtime Error):
l=int(input())
print(L**3/27)
Problem p03361 (python)

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

s=[list(str(input())) for _ in range(n)]

di=[1,-1,0,0]
dj=[0,0,1,-1]
for i in range(n):
    for j in range(m):
        if s[i][j]=='#':
            found=False
            for k in range(4):
                i2=i+di[k]
                j2=j+dj[k]
                if 0<=i2 and i2<n and 0<=j2 and j2<m:
                    if s[i2][j2]=='#':
                        found=True
            if not found:
                print('No')
                exit()

print('Yes')

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

s=[list(str(input())) for _ in range(n)]

di=[1,-1,0,0]
dj=[0,0,1,-1]
for i in range(1,n-1):
    for j in range(1,m-1):
        if s[i][j]=='#':
            found=False
            for k in range(4):
                i2=i+di[k]
                j2=j+dj[k]
                if 0<=i2 and i2<n and 0<=j2 and j2<m:
                    if s[i2][j2]=='#':
                        found=True
            if not found:
                print('No')
                sys.exit()

print('Yes')

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

s=[list(str(input())) for _ in range(n)]

ans=True
di=[1,-1,0,0]
dj=[0,0,1,-1]
for i in range(n):
    for j in range(m):
        if s[i][j]=='#':
            found=False
            for k in range(4):
                i2=i+di[k]
                j2=j+dj[k]
                if 0<=i2 and i2<n and 0<=j2 and j2<m:
                    if s[i2][j2]=='#':
                        found=True
            if not found:
                print('No')
                sys.exit()

print('Yes')
Problem p03575 (python)

Fixed submission:
#Nはノード数、Mはエッジ数
n,m = map(int, input().split())

ab = [list(map(int, input().split())) for i in range(m)]

cnt=0

for x in ab:
  ls=list(range(n))
  for y in ab:
    if y !=x:
      for i in range(n):
        ls=[ls[y[0]-1] if ls[i]==ls[y[1]-1] else ls[i] for i in range(n)] #bの値を根っこ（低い方a）にする
  if len(set(ls)) !=1:
    cnt+=1

print(cnt)

Buggy submission (verdict: Runtime Error):
#Nはノード数、Mはエッジ数
n,m = map(int, input().split())

ab = [list(map(int, input().split())) for i in range(m)]

cnt=0

for x in ab:
  ls=list(range(n))
  for y in ab:
    if y !=x:
      for i in range(n)
        ls=[ls[y[0]-1] if ls[i]==ls[y[1]-1] else ls[i] for i in range(n)] #bの値を根っこ（低い方a）にする
  if len(set(ls)) !=1:
    cnt+=1

print(cnt)
Problem p03721 (python)

Fixed submission:
n,k=map(int,input().split());i=0;a=sorted(list(map(int,input().split()))for _ in[0]*n)
while k>0:k-=a[i][1];i+=1
print(a[~-i][0])

Buggy submission (verdict: Runtime Error):
import sys
n,k=map(int, input().split()) #a1 a2 a3

com = [list(map(int, input().split())) for _ in range(n)]

i=0

while k>0:
  k-=com[i][1]
  i+=1

print(com[~i][0]) #~i -i-1

Buggy submission (verdict: Runtime Error):
import sys
n,k=map(int, input().split()) #a1 a2 a3

com = [list(map(int, input().split())) for _ in range(n)]

i=0

while k>0:
  k-=com[i][0]
  i+=1

print(com[~i][0]) #~i -i-1
Problem p03836 (python)

Fixed submission:
sx,sy,tx,ty=map(int, input().split()) #a1 a2 a3

m1=(tx-sx)*"R"+(ty-sy)*"U"
m2=(tx-sx)*"L"+(ty-sy)*"D"


print(m1+m2+"DR"+m1+"ULUL"+m2+"DR")

Buggy submission (verdict: Runtime Error):
sx,sy,tx,ty=map(int, input().split()) #a1 a2 a3

m1=(tx-sx)*"R"+(ty-sy)*"U"
m2=(tx-sx)*"L"+(ty-sy)+"D"


print(m1+m2+"DR"+a+"ULUL"+m2+"DR")
Problem p04030 (python)

Fixed submission:
s=list(str(input()))

ans=[]
for i in s:
  if i=='1':
    ans.append('1')
  elif i=='0':
    ans.append('0')
  else:
    if ans:
      ans.pop(-1)
    else:
      continue

print(''.join(ans))

Buggy submission (verdict: Runtime Error):
s=list(str(input()))

ans=[]
for i in s:
  if i=='1':
    ans.append('1')
  elif i=='0':
    ans.append(0,'0')
  else:
    if ans:
      ans.pop(-1)
    else:
      continue

print(''.join(ans))

Buggy submission (verdict: Runtime Error):
s=list(str(input()))

ans=[]
for i in s:
  if i=='1':
    ans.append('1')
  elif i=='0':
    ans.insert(0,'0')
  else:
    ans.pop(-1)

print(''.join(ans))
Problem p04044 (python)

Fixed submission:
n,l=map(int, input().split()) #a1 a2 a3

s = [input() for i in range(n)] 

s.sort()


print(''.join(s))

Buggy submission (verdict: Runtime Error):
n,l=map(int, input().split()) #a1 a2 a3
s = [i for i in range(n)] 

s.sort()


print(''.join(s))

Buggy submission (verdict: Runtime Error):
n,l=map(int, input().split()) #a1 a2 a3
s = [i for i in range(q)] 

s.sort()

print(''.join(s))
Problem p02574 (python)

Fixed submission:
from sys import exit
from math import gcd
n = int(input())
a = list(map(int, input().split()))
g = gcd(a[0], a[1])
for i in range(2, n):
	g = gcd(g, a[i])
if g > 1:
	print("not coprime")
	exit()

MAX = 1000001
nxt = [i for i in range(MAX)]
for i in range(2, MAX):
	if nxt[i] < i:
		continue
	for j in range(i, MAX, i):
		nxt[j] = min(nxt[j], i)

fac = set()
ok = True
for x in a:
	tmp = set()
	while x > 1:
		tmp.add(nxt[x])
		x //= nxt[x]
	for p in tmp:
		if p in fac:
			ok = False
			break
		fac.add(p)
	if not ok:
		break
print("pairwise coprime" if ok else "setwise coprime")

Buggy submission (verdict: Runtime Error):
from sys import exit
from math import gcd
n = int(input())
a = list(map(int, input().split()))
g = gcd(a[0], a[1])
for i in range(2, n):
	g = gcd(g, a[i])
if g > 1:
	print("not coprime")
	exit()

MAX = 32
nxt = [i for i in range(MAX)]
for i in range(2, MAX):
	if nxt[i] < i:
		continue
	for j in range(i, MAX, i):
		nxt[j] = min(nxt[j], i)

fac = set()
ok = True
for x in a:
	tmp = set()
	while x > 1:
		tmp.add(nxt[x])
		x //= nxt[x]
	for p in tmp:
		if p in fac:
			ok = False
			break
		fac.add(p)
	if not ok:
		break
print("pairwise coprime" if ok else "setwise coprime")
Problem p02609 (python)

Fixed submission:
n = int(input())
s = input()
x = int(s, 2)
p = s.count("1")
if p > 1:
	pre0 = x%(p-1)
pre1 = x%(p+1)

nxt = [i for i in range(n+10)]
for i in range(1, n+10):
	nxt[i] %= bin(i).count("1")

for i in range(n):
	if x == 1<<(n-1-i):
		print(0)
		continue
	if s[i] == "0":
		tmp = (pre1 + pow(2, n-1-i, p+1)) % (p+1)
	else:
		tmp = (pre0 - pow(2, n-1-i, p-1)) % (p-1)
	ans = 1
	while tmp > 0:
		ans += 1
		tmp = nxt[tmp]
	print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
x = int(s, 2)
p = s.count("1")
if p > 2:
	pre0 = x%(p-1)
pre1 = x%(p+1)

nxt = [i for i in range(n+10)]
for i in range(1, n+10):
	nxt[i] %= bin(i).count("1")

for i in range(n):
	if x == 1<<(n-1-i):
		print(0)
		continue
	if s[i] == "0":
		tmp = (pre1 + pow(2, n-1-i, p+1)) % (p+1)
	else:
		tmp = (pre0 - pow(2, n-1-i, p-1)) % (p-1)
	ans = 1
	while tmp > 0:
		ans += 1
		tmp = nxt[tmp]
	print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
x = int(s, 2)
p = s.count("1")
pre0, pre1 = x%(p-1), x%(p+1)

nxt = [i for i in range(n+10)]
for i in range(1, n+10):
	nxt[i] %= bin(i).count("1")

for i in range(n):
	if x == 1<<(n-1-i):
		print(0)
		continue
	if s[i] == "0":
		tmp = (pre1 + pow(2, n-1-i, p+1)) % (p+1)
	else:
		tmp = (pre0 - pow(2, n-1-i, p-1)) % (p-1)
	ans = 1
	while tmp > 0:
		ans += 1
		tmp = nxt[tmp]
	print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
x = int(s, 2)
p = s.count("1")
pre0, pre1 = x%(p-1), x%(p+1)

nxt = [i for i in range(n+1)]
for i in range(1, n):
	nxt[i] %= bin(i).count("1")

for i in range(n):
	if x == 1<<(n-1-i):
		print(0)
		continue
	if s[i] == "0":
		tmp = (pre1 + pow(2, n-1-i, p+1)) % (p+1)
	else:
		tmp = (pre0 - pow(2, n-1-i, p-1)) % (p-1)
	ans = 1
	while tmp > 0:
		ans += 1
		tmp = nxt[tmp]
	print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
x = int(s, 2)
p = s.count("1")
pre0, pre1 = x%(p-1), x%(p+1)

nxt = [i for i in range(n+1)]
for i in range(1, n):
	nxt[i] %= bin(i).count("1")

for i in range(n):
	if x == 1<<(n-1-i):
		print(0)
		continue
	if s[i] == "0":
		tmp = (pre1 + pow(2, n-1-i, p+1)) % (p+1)
	else:
		tmp = (pre0 + pow(2, n-1-i, p-1)) % (p-1)
	ans = 1
	while tmp > 0:
		ans += 1
		tmp = nxt[tmp]
	print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
x = int(s, 2)
p = popcount(x)

def popcount(x):
	'''xの立っているビット数をカウントする関数
	(xは64bit整数)'''

	# 2bitごとの組に分け、立っているビット数を2bitで表現する
	x = x - ((x >> 1) & 0x5555555555555555)

	# 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
	x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

	x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitごと
	x = x + (x >> 8) # 16bitごと
	x = x + (x >> 16) # 32bitごと
	x = x + (x >> 32) # 64bitごと = 全部の合計
	return x & 0x0000007f

nxt = [i for i in range(n+1)]
for i in range(1, n):
	nxt[i] %= popcount(i)

for i in range(n):
	ans = 0
	tmp = x ^ (1 << (n-1-i))
	if tmp == 0:
		print(0)
		continue
	if tmp > x:
		ans = 1
		tmp %= p+1
	else:
		ans = 1
		tmp %= p-1
	while tmp > 0:
		ans += 1
		tmp = nxt[tmp]
	print(ans)
Problem p02616 (python)

Fixed submission:
from sys import exit
from random import randrange
MOD = 10**9+7
n, k = map(int, input().split())
b = list(map(int, input().split()))
a = []
if n == k:
	ans = 1
	for x in b:
		ans *= x
		ans %= MOD
	print(ans)
	exit()
for x in b:
	if x != 0:
		a.append(x)
if len(a) < k:
	print(0)
	exit()

a.sort(key=lambda x: -abs(x))
#print(a)
ans = 1
minus = 0
for i in range(k):
	ans *= a[i]
	ans %= MOD
	if a[i] < 0:
		minus += 1

if minus%2 == 0:
	print(ans)
	exit()

if len(a) == k:
	if len(a) < n:
		print(0)
		exit()

for i in range(k, len(a)):
	if a[i] < 0:
		minus += 1

if minus == len(a):
	if len(a) < n:
		print(0)
		exit()
	ans = 1
	for i in range(k):
		ans *= a[-i-1]
		ans %= MOD
	print(ans)
	exit()

flg1 = False
for i in range(k-1, -1, -1):
	if a[i] * a[k] < 0:
		p, q = a[i], a[k]
		flg1 = True
		break

flg2 = False
for i in range(k, len(a)):
	if a[k-1] * a[i] < 0:
		r, s = a[k-1], a[i]
		flg2 = True
		break

if flg1 and flg2:
	if abs(q*r) >= abs(p*s):
		ans *= pow(p, MOD-2, MOD)
		ans *= q
		print(ans%MOD)
	else:
		ans *= pow(r, MOD-2, MOD)
		ans *= s
		print(ans%MOD)

elif flg1:
	ans *= pow(p, MOD-2, MOD)
	ans *= q
	print(ans%MOD)

elif flg2:
	ans *= pow(r, MOD-2, MOD)
	ans *= s
	print(ans%MOD)

else:
	print("コーナーケース多すぎん？")

Buggy submission (verdict: Runtime Error):
from sys import exit
from random import randrange
MOD = 10**9+7
n, k = map(int, input().split())
b = list(map(int, input().split()))
a = []
if n == k:
	ans = 1
	for x in b:
		ans *= x
		ans %= MOD
	print(ans)
	exit()
for x in b:
	if x != 0:
		a.append(x)
if len(a) < k:
	print(0)
	exit()

a.sort(key=lambda x: -abs(x))
#print(a)
ans = 1
minus = 0
for i in range(k):
	ans *= a[i]
	ans %= MOD
	if a[i] < 0:
		minus += 1

if minus%2 == 0:
	print(ans)
	exit()

if len(a) == k:
	if len(a) < n:
		print(0)
		exit()

for i in range(k, len(a)):
	if a[i] < 0:
		minus += 1

if minus == len(a):
	if len(a) < n:
		print(0)
		exit()
	ans = 1
	for i in range(k):
		ans *= a[-i-1]
		ans %= MOD
	print(ans)
	exit()

for i in range(k-1, -1, -1):
	if a[i] * a[k] < 0:
		p, q = a[i], a[k]
		break
for i in range(k, len(a)):
	if a[k-1] * a[i] < 0:
		r, s = a[k-1], a[i]
		break
if abs(q*r) >= abs(p*s):
	ans *= pow(p, MOD-2, MOD)
	ans *= q
	print(ans%MOD)
else:
	ans *= pow(r, MOD-2, MOD)
	ans *= s
	print(ans%MOD)