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

Fixed submission:
from collections import Counter


S = input()
C = Counter(S)
vs = sorted(list(C.values()))
if len(vs) == 1:
    print("YES") if vs[0] == 1 else print("NO")
elif len(vs) == 2:
    print("YES") if vs[0] == vs[1] and vs[0] == 1 else print("NO")
else:
    print("YES") if vs[2] - 1 <= vs[0] and vs[2] - 1 <= vs[1] else print("NO")

Buggy submission (verdict: Runtime Error):
s = input()
K = int(input())
s_dic = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
for i, c in enumerate(s):
    s_dic[c].append(i)
substrings = set()
for lc in "abcdefghijklmnopqrstuvwxyz":
    for i in s_dic[lc]:
        for j in range(i + 1, len(s) + 1):
            substrings.add(s[i:j])
    if len(substrings) >= K:
        break
print(sorted(list(substrings))[K - 1])
Problem p03569 (python)

Fixed submission:
def is_valid():
    x_removed_S = S.replace("x", "")
    M = len(x_removed_S)
    for i in range(M // 2):
        if x_removed_S[i] != x_removed_S[M - i - 1]:
            return False
    return True


S = input()
N = len(S)
if is_valid():
    ans = 0
    left, right = 0, N - 1
    while left < right:
        if S[left] == S[right]:
            left += 1
            right -= 1
            continue
        elif S[left] == "x":
            ans += 1
            left += 1
        else:
            ans += 1
            right -= 1
    print(ans)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
def is_valid():
    x_removed_S = S.replace("x", "")
    M = len(x_removed_S)
    for i in range(M // 2):
        if x_removed_S[i] != x_removed_S[M - i - 1]:
            return False
    return True


S = input()
N = len(S)
if is_valid():
    ans = 0
    left, right = 0, N - 1
    while left != right:
        if S[left] == S[right]:
            left += 1
            right -= 1
            continue
        elif S[left] == "x":
            ans += 1
            left += 1
        else:
            ans += 1
            right -= 1
    print(ans)
else:
    print(-1)
Problem p03627 (python)

Fixed submission:
from collections import Counter


N = int(input())
c = Counter(map(int, input().split()))
usables = sorted([(k, v) for k, v in c.items() if v >= 2])
if len(usables) <= 1:
    print(0)
else:
    if usables[-1][1] >= 4:
        print(usables[-1][0] ** 2)
    else:
        print(usables[-1][0] * usables[-2][0])

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


N = int(input())
c = Counter(map(int, input().split()))
usables = sorted([(k, v) for k, v in c.items() if v >= 2])
if len(usables) <= 1:
    print(0)
else:
    if usables[-1][2] >= 4:
        print(usables[-1][1] ** 2)
    else:
        print(usables[-1][1] * usables[-2][1])
Problem p03639 (python)

Fixed submission:
from collections import defaultdict


N = int(input())
counter = defaultdict(int)
for a in map(int, input().split()):
    if a % 4 == 0:
        counter[2] += 1
    elif a % 2 == 0:
        counter[1] += 1
    else:
        counter[0] += 1
if counter[1] == 0:
    print('Yes') if counter[0] <= counter[2] + 1 else print('No')
else:
    print('Yes') if counter[0] <= counter[2] else print('No')

Buggy submission (verdict: Runtime Error):
N = int(input())
counter = {}
for a in map(int, input().split()):
    if a % 4 == 0:
        counter[2] = counter.get(2, 0) + 1
    elif a % 2 == 0:
        counter[1] = counter.get(1, 0) + 1
    else:
        counter[0] = counter.get(0, 0) + 1
print('Yes') if counter[0] <= counter[2] else print('No')
Problem p03786 (python)

Fixed submission:
from bisect import bisect_right
from itertools import accumulate


N = int(input())
A = sorted(map(int, input().split()))
acc_A = list(accumulate(A))
ans = 0
for i in range(N):
    prev = i
    while True:
        idx = bisect_right(A, 2 * acc_A[prev]) - 1
        if idx == N - 1:
            ans += 1
            break
        if idx == prev:
            break
        prev = idx
print(ans)

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


N, K = map(int, input().split())
A = list(map(int, input().split()))
g = reduce(gcd, A)
if K <= max(A) and K % g == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Problem p03944 (python)

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

ans=[0,0,w,h]
for i in range(n):
    if xya[i][2] == 1:
        if xya[i][0] >= ans[0]:
            ans[0] = xya[i][0]
    elif xya[i][2] == 2:
        if xya[i][0] <= ans[2]:
            ans[2] = xya[i][0]
    elif xya[i][2] == 3:
        if xya[i][1] >= ans[1]:
            ans[1] = xya[i][1]
    elif xya[i][2] == 4:
        if xya[i][1] <= ans[3]:
            ans[3] = xya[i][1]

print(0 if ans[2]-ans[0] <= 0 or ans[3]-ans[1] <= 0 else (ans[2]-ans[0])*(ans[3]-ans[1]))

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

ans=[0,0,w,h]
for i in range(n):
    if xya[i][2] == 1:
        if xya[i][0] >= ans[0]:
            ans[0] = xya[i][0]
    elif xya[i][2] == 2:
        if xya[i][0] <= ans[2]:
            ans[2] = xya[i][0]
    elif xya[i][2] == 3:
        if xya[i][1] >= ans[1]:
            ans[1] = xya[i][1]
    elif xya[i][2] == 4:
        if xya[i][1] <= ans[3]:
            ans[3] = xya[i][1]

print(0 if ans[2]-ans[0] <= 0 || ans[3]-ans[1] <= 0 else (ans[2]-ans[0])*(ans[3]-ans[1]))
Problem p03944 (python)

Fixed submission:
w,h,n=[int(i) for i in input().split(' ')]
x1,x2,y1,y2=0,w,0,h
for i in range(n):
  x,y,a=[int(i) for i in input().split(' ')]
  if a==1:
    x1=max(x1,x)
  if a==2:
    x2=min(x2,x)
  if a==3:
    y1=max(y1,y)
  if a==4:
    y2=min(y2,y)
    
if y2<=y1 or x2 <= x1:
  print(0)
else:
  print(max(0,(y2-y1)*(x2-x1)))

Buggy submission (verdict: Runtime Error):
w,h,n=[int(i) for i in input().split(' ')]
x1,x2,y1,y2=0,w,0,h
for i in range(n):
  x,y,a=[int(i) for i in input().split(' ')]
  if a==1:
    x1=max(x1,x)
  if a==2:
    x2=min(x2,x)
  if a==3:
    y1=max(y1,y)
  if a==4:
    y2=min(y2,y)
print(max(0,(y2-y1)*(x2-x1))
Problem p02588 (python)

Fixed submission:
N = int(input())
a = [[0 for j in range(19)] for i in range(19)]
ans=0
for _ in range(N):
    A=input()
    if A.find('.') > 0:
        count2 = 10 - len(A) + A.find('.')
        count5 = 10 - len(A) + A.find('.')
    else:
        count2 = 9
        count5 = 9
    tmp = int(A.replace('.', ''))
    while count2 < 18:
        if tmp % 2 == 0:
            count2 += 1
            tmp //= 2
        else:
            break
    while count5 < 18:
        if tmp % 5 == 0:
            count5 += 1
            tmp //= 5
        else:
            break
    for i in range(18-count2,19):
        for j in range(18-count5,19):
            ans += a[i][j]
    a[count2][count5] += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = [[0 for j in range(19)] for i in range(19)]
for i in range(N):
    A=input()
    tmp = int(A.replace('.', ''))
    count2 = 0
    count5 = 0
    for _ in range(18):
        if tmp % 2 == 0:
            count2 += 1
            tmp //= 2
        else:
            break
    for _ in range(18):
        if tmp % 5 == 0:
            count5 += 1
            tmp //= 5
        else:
            break
    if A.find('.') > 0:
        count2 = count2 + 10 - len(A) + A.find('.')
        count5 = count5 + 10 - len(A) + A.find('.')
    else:
        count2 += 9
        count5 += 9
    a[count2][count5] += 1
ans=0
for i in range(19):
    for i2 in range(19):
        for j in range(19):
            for j2 in range(19):
                if i + i2 >= 18 and j + j2 >= 18 and ( i < i2 or i == i2 and j <= j2) and a[i][j] >0 and a[i2][j2] > 0:
                    if i == i2 and j == j2:
                        ans += a[i][j] * (a[i][j]-1) // 2
                    else:
                        ans += a[i][j] * a[i2][j2]
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = [[0 for j in range(19)] for i in range(19)]
for i in range(N):
    A=input()
    # tmp = int(float(A) * 10**9)
    tmp = int(A.replace('.', ''))
    count2 = 0
    count5 = 0
    for _ in range(18):
        if tmp % 2 == 0:
            count2 += 1
            tmp /= 2
        else:
            break
    for _ in range(18):
        if tmp % 5 == 0:
            count5 += 1
            tmp /= 5
        else:
            break
    if A.find('.') > 0:
        count2 = count2 + 10 - len(A) + A.find('.')
        count5 = count5 + 10 - len(A) + A.find('.')
    else:
        count2 += 9
        count5 += 9
    a[count2][count5] += 1
ans=0
for i in range(19):
    for i2 in range(19):
        for j in range(19):
            for j2 in range(19):
                if i + i2 >= 18 and j + j2 >= 18 and ( i < i2 or i == i2 and j <= j2) and a[i][j] >0 and a[i2][j2] > 0:
                    if i == i2 and j == j2:
                        ans += a[i][j] * (a[i][j]-1) // 2
                    else:
                        ans += a[i][j] * a[i2][j2]
print(ans)
Problem p02603 (python)

Fixed submission:
N=int(input())
A=list(map(int, input().split()))
B=[]
B.append(A[0])
for i in range(1,N):
    if A[i]!=B[-1]: B.append(A[i])
i=1
length=len(B)
while i<length-1:
    if B[i]>B[i-1] and B[i]<B[i+1] or B[i]<B[i-1] and B[i]>B[i+1]:
        B.pop(i)
        length-=1
    else:
        i+=1
yen=1000
kabu=0
for i in range(len(B)):
    if len(B)>=2 and B[0]<B[1]:
        if i%2==0 and i<len(B)-1:
            kabu=yen//B[i]
            yen=yen%B[i]
        elif i%2==1:
            yen=yen+kabu*B[i]
    else:
        if i%2==1 and i<len(B)-1:
            kabu=yen//B[i]
            yen=yen%B[i]
        elif i%2==0:
            yen=yen+kabu*B[i]
print(yen)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int, input().split()))
B=[]
B.append(A[0])
for i in range(1,N):
    if A[i]!=B[-1]: B.append(A[i])
i=1
length=len(B)
while i<length-1:
    if B[i]>B[i-1] and B[i]<B[i+1] or B[i]<B[i-1] and B[i]>B[i+1]:
        B.pop(i)
        length-=1
    else:
        i+=1
yen=1000
kabu=0
for i in range(len(B)):
    if B[0]<B[1]:
        if i%2==0 and i<len(B)-1:
            kabu=yen//B[i]
            yen=yen%B[i]
        elif i%2==1:
            yen=yen+kabu*B[i]
    else:
        if i%2==1 and i<len(B)-1:
            kabu=yen//B[i]
            yen=yen%B[i]
        elif i%2==0:
            yen=yen+kabu*B[i]
print(yen)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int, input().split()))
B=[]
B.append(A[0])
for i in range(1,N):
    if A[i]!=B[-1]: B.append(A[i])
i=1
length=len(B)
while i<length-1:
    if B[i]>B[i-1] and B[i]<B[i+1] or B[i]<B[i-1] and B[i]>B[i+1]:
        B.pop(i)
        length-=1
    else:
        i+=1
yen=1000
kabu=0
for i in range(len(B)):
    if B[0]<B[1]:
        if i%2==0 and i<len(B)-1:
            kabu=yen//B[i]
            yen=yen%B[i]
        else:
            yen=yen+kabu*B[i]
    else:
        if i%2==1 and i<len(B)-1:
            kabu=yen//B[i]
            yen=yen%B[i]
        else:
            yen=yen+kabu*B[i]
print(yen)
Problem p02609 (python)

Fixed submission:
N=int(input())
X=input()
popcount=X.count('1')
bi1=[]
bi0=[]
Xnum1 = 0
Xnum0 = 0
if popcount != 1:
    for i in range(N):
        if i==0: bi1.append(1)
        else: bi1.append(bi1[i-1]*2%(popcount-1))
        Xnum1 = (Xnum1 + int(X[N-i-1])*bi1[i])%(popcount-1)
for i in range(N):
    if i==0: bi0.append(1)
    else: bi0.append(bi0[i-1]*2%(popcount+1))
    Xnum0 = (Xnum0 + int(X[N-i-1])*bi0[i])%(popcount+1)
for i in range(N):
    if popcount==1 and X[i]=='1':
        print(0)
        continue
    if X[i]=='1':
        Xi = (Xnum1 - bi1[N-i-1])%(popcount-1)
    else:
        Xi = (Xnum0 + bi0[N-i-1])%(popcount+1)
    ans = 1
    while Xi!=0:
        Xi = Xi % bin(Xi).count('1')
        ans += 1
    print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
X=input()
Xnum=int(X,2)
popcount=X.count('1')
if popcount != 1:
    Xnum1=Xnum%(popcount-1)
Xnum0=Xnum%(popcount+1)
for i in range(N):
    if popcount==1 and X[i]=='1':
        print(0)
    if X[i]=='1':
        Xi = (Xnum1 - (2**(N-i-1)%(popcount-1)))%(popcount-1)
    else:
        Xi = (Xnum0 + (2**(N-i-1)%(popcount+1)))%(popcount+1)
    ans = 1
    while Xi!=0:
        Xi = Xi % bin(Xi).count('1')
        ans += 1
    print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
X=input()
Xnum=int(X,2)
popcount=X.count('1')
Xnum1=Xnum%(popcount-1)
Xnum0=Xnum%(popcount+1)
for i in range(N):
    if popcount==1 and X[i]=='1':
        print(0)
    if X[i]=='1':
        Xi = (Xnum1 - (2**(N-i-1)%(popcount-1)))%(popcount-1)
    else:
        Xi = (Xnum0 + (2**(N-i-1)%(popcount+1)))%(popcount+1)
    ans = 1
    while Xi!=0:
        Xi = Xi % bin(Xi).count('1')
        ans += 1
    print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
X=input()
Xnum=int(X,2)
popcount=X.count('1')
for i in range(N):
    if X[i]=='1':
        Xi = Xnum - 2**(N-i-1)
        popcount2=popcount-1
    else:
        Xi = Xnum + 2**(N-i-1)
        popcount2=popcount+1
    if popcount2==0: print(0)
    else:
        ans = 0
        while Xi!=0:
            Xi = Xi % popcount2
            popcount2 = bin(Xi).count('1')
            ans += 1
    print(ans)
Problem p02613 (python)

Fixed submission:
n=int(input())
ac=0
wa=0
tle=0
re=0
for i in range(n):
    m=input()
    if m=='AC': ac+=1
    elif m=='WA': wa+=1
    elif m=='TLE': tle+=1
    elif m=='RE': re+=1
print('AC x '+str(ac))
print('WA x '+str(wa))
print('TLE x '+str(tle))
print('RE x '+str(re))

Buggy submission (verdict: Runtime Error):
n=int(input())
s=[input() for in range(n)]
for v in ['AC', 'WA', 'TLE', 'RE']:
    print('{0} x {1}'.format(v, s.count(v)))
Problem p02866 (python)

Fixed submission:
N,*D=map(int,open(0).read().split())
c=[0]*N
for i in D:c[i]+=1
m=max(D)
if D[0]>0 or c[0]>1:print(0);exit()
a=1
for i in range(m):a*=c[i]**c[i+1]
print(a%998244353)

Buggy submission (verdict: Runtime Error):
N,*D=map(int,open(0).read().split())
c=[0]*N
for i in D:c[i]+=1
if D[0]>0 or c[0]>1:print(0);exit()
a=1
for i in range(max(D)+1):a*=c[i]**c[i+1]
print(a)
Problem p03196 (python)

Fixed submission:
import math
def factrization_prime(number):
    factor = {}
    div = 2
    s = math.sqrt(number)
    while div < s:
        div_cnt = 0
        while number % div == 0:
            div_cnt += 1
            number //= div
        if div_cnt != 0:
            factor[div] = div_cnt
        div += 1
    if number > 1:
        factor[number] = 1
    return factor
N, P = map(int, input().split())
d = factrization_prime(P)
a = 1
for p in d:
    a *= p**(d[p]//N)
print(a)

Buggy submission (verdict: Runtime Error):
import math
N,P=map(int,input().split())
i=math.ceil(P**(1/N))
while 1:
    if P%(i**N)==0:print(i);exit()
    i-=1

Buggy submission (verdict: Runtime Error):
N,P=map(int,input().split())
i=1
while i**N<=P:
    if P%i**N==0:a=i
    i+=1
print(a)
Problem p03380 (python)

Fixed submission:
n,*a=map(int,open(0).read().split())
m=max(a)
b=m//2
o=min(a)
for A in a:
 if abs(A-b)<abs(o-b):o=A
print(m,o)

Buggy submission (verdict: Runtime Error):
def g(n,r):return f[n]//f[n-r]//f[r]
n,*a=map(int,open(0).read().split())
m=max(a)
f=[1]*-~m
for i in range(m):f[i+1]=f[i]*-~i
o=min(a)
for A in a:
 if g(m,A)>g(m,o):o=A
print(m,o)

Buggy submission (verdict: Runtime Error):
n,*a=map(int,open(0).read().split())
m=max(a)
f=[1]*-~m
for i in range(m):f[i+1]=f[i]*-~i
def g(n,r):return f[n]//f[n-r]//f[r]
o=min(a)
for A in a:
 if g(m,A)>g(m,o):o=A
print(m,o)
Problem p03565 (python)

Fixed submission:
import re
S,T=open(0)
S=S.replace('?','.')
T=T[:-1]
s=len(S)
t=len(T)
for i in range(s-t,-1,-1):
 if re.match(S[i:i+t],T):print((S[:i]+T+S[i+t:]).replace('.','a'));exit()
print('UNRESTORABLE')

Buggy submission (verdict: Runtime Error):
import re
S,T=open(0)
S=S.replace('?','.')
s=len(S)
t=len(T)
B='z'*s
c=0
for i in range(s-t+1):
 if re.search(S[i:i+t],T):A=min(A,(S[:i]+T+S[i+t:]).replace('.','a'));c=1
print(A if c else 'UNRESTORABLE')
Problem p03910 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def is_ok(m, n):
    return m*(m+1)//2>=n
def meguru_bisect(ng, ok, n):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid, n):
            ok = mid
        else:
            ng = mid
    return ok
def f(n):
    if n>0:
        m = meguru_bisect(0,10**7, n)
        print(m)
        f(n-m)
N = int(input())
f(N)

Buggy submission (verdict: Runtime Error):
def is_ok(m, n):
    return m*(m+1)//2>=n
def meguru_bisect(ng, ok, n):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid, n):
            ok = mid
        else:
            ng = mid
    return ok
def f(n):
    if n>0:
        m = meguru_bisect(0,10**7, n)
        print(m)
        f(n-m)
N = int(input())
f(N)

Buggy submission (verdict: Runtime Error):
def is_ok(n):
    global N
    return n*(n+1)//2>=N
def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok
N = int(input())
n = meguru_bisect(0,10**7)
s = list(range(1, n+1))
d = n-2
while sum(s) != N:
    s.pop(d)
    d -= 1
for i in s:
    print(i)
Problem p02555 (python)

Fixed submission:
import sys
amount = int(input())

lst1 = [3,4,5]
if amount in lst1:
    print(1)
    sys.exit()
elif amount < 6:
    print(0)
    sys.exit()

coins = [x for x in range(3,amount+1)]

lst = [amount+1 for x in range(amount+1)]

lst[0] = 1
lst[1] = 0
lst[2] = 0
lst[3] = 1
lst[4] = 1
lst[5] = 1


for i in range(6,amount+1):
    counter = 0
    for coin in coins:
        change = i - coin

        if change >= 0:
            counter += lst[change]
    lst[i] = counter

print(lst[-1] % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
import sys
amount = int(input())

if amount < 3:
    print(0)
    sys.exit()

coins = [x for x in range(3,amount+1)]

lst = [amount+1 for x in range(amount+1)]

lst[0] = 1
lst[1] = 0
lst[2] = 0
lst[3] = 1
lst[4] = 1
lst[5] = 1



for i in range(6,amount+1):
    counter = 0
    for coin in coins:
        change = i - coin

        if change >= 0:
            counter += lst[change]
    lst[i] = counter

print(lst[-1] % (10**9 + 7))

Buggy submission (verdict: Runtime Error):

amount = int(input())

coins = [x for x in range(3,amount+1)]

lst = [amount+1 for x in range(amount+1)]

lst[0] = 1
lst[1] = 0
lst[2] = 0
lst[3] = 1
lst[4] = 1
lst[5] = 1


for i in range(6,amount+1):
    counter = 0
    for coin in coins:
        change = i - coin

        if change >= 0:
            counter += lst[change]
    lst[i] = counter

print(lst[-1] % (10**9 + 7))
Problem p02582 (python)

Fixed submission:
S = input()

l = len(S)
count = 0

for i in range(l):
    if "R" not in S:
        break
    cur_count = 1

    for j in range(i+1,l):
        if S[i] == "S":
            break
        if (S[i] != S[j]):
            break
        cur_count += 1
    if cur_count > count:
        count = cur_count

print(count)

Buggy submission (verdict: Runtime Error):
max = 0
for letter in S:
    if letter == "R":
        max += 1
    if letter == "S":
        break 
print(max)
Problem p02657 (python)

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

Buggy submission (verdict: Runtime Error):
if __name__ == '__main__':
    n = int(input())
    arr = list(map(int, input().split()))
    product = arr[0]
    if 0 in arr:
        product = 0
    else:
        for i in range(1, n):
            product *= arr[i]
            if product > (10**18):
                product = -1
                break
    print(product)
Problem p03503 (python)

Fixed submission:
#from collections import Counter
N=int(input())
F=list(list(map(int,input().split())) for i in range(N))
P=list(list(map(int,input().split())) for i in range(N))
ans=-(1<<40)
for bit in range(1,1<<10):
    tmp = 0
    for i in range(N):
        c=0
        for j in range(10):
            if bit&(1<<j) and F[i][j]:
                c+=1
        tmp+=P[i][c]
    ans = max(ans,tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
#from collections import Counter
N=int(input())
"""F=list(list(map(int,input().split())) for i in range(N))
P=list(list(map(int,input().split())) for i in range(N))"""
F=[int(input().replace(' ',''),2)for _ in[0]*N]
P=[list(map(int,input().split()))for _ in[0]*N]
ans=-(1<<40)
for bit in range(1,1<<10):
    tmp = 0
    for i in range(N):
        c=0
        for j in range(10):
            if bit&(1<<j) and F[i][j]:
                c+=1
        tmp+=P[i][c]
    ans = max(ans,tmp)
print(ans)
Problem p03545 (python)

Fixed submission:
A = input()
for bit in range(1 << 4):
    ans = int(A[0])
    res = [A[0]]
    for i in range(3):
        if bit & (1 << i):
            ans += int(A[i + 1])
            res.append("+")
            res.append(A[i+1])
        else:
            ans -= int(A[i + 1])
            res.append("-")
            res.append(A[i+1])
    if ans == 7:
        for i in range(7):
            print(res[i], end='')
        print("=7")
        break

Buggy submission (verdict: Runtime Error):
A = input()
op = ["+", "-"]
for bit in range(1 << 3):
    ans = A[0]
    for i in range(3):
        ans += op[bit & (1 << i)]+A[i+1]
    if eval(ans) == 7:
        print(ans+"=7")
        break

Buggy submission (verdict: Runtime Error):
A = input()
op = ["+", "-"]
for bit in range(1 << 4):
    ans = A[0]
    for i in range(3):
        ans += op[bit & (1 << i)]+A[i+1]
    if eval(ans) == 7:
        print(ans+"=7")
        break
Problem p02609 (python)

Fixed submission:
N = int(input())
X = input()
X_i = int(X, 2)
X_b = bin(X_i)
sum_X = X_b.count("1")
Xp = X_i % (sum_X + 1)
Xm = X_i % (sum_X - 1) if sum_X - 1 > 0 else -1


def f(n, p):
    count = 1
    n %= p
    while n != 0:
        p = bin(n).count("1")
        n %= p
        count += 1
    return count


for i in range(1, N + 1):
    if X[i - 1] == "1":
        if sum_X - 1 <= 0:
            print(0)
            continue
        nm = pow(2, N - i, sum_X - 1)
        print(f(Xm - nm, sum_X - 1))
    else:
        np = pow(2, N - i, sum_X + 1)
        print(f(Xp + np, sum_X + 1))

Buggy submission (verdict: Runtime Error):
N = int(input())
X = [i for i in input()]
sum_X = X.count("1")


def f(n, p):
    count = 1
    while True:
        n = int(n, 2) % p
        if n == 0:
            break
        n = format(n, "b")
        p = n.count("1")
        count += 1
    return count


for i in range(0, N):
    tempX = ""
    count = sum_X
    if X[i] == "0":
        count += 1
        X[i] = "1"
        tempX = "".join(X)
        X[i] = "0"
    else:
        count -= 1
        X[i] = "0"
        tempX = "".join(X)
        X[i] = "1"

    print(f(tempX, count))

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

N = int(input())
X = [i for i in input()]
sum_X = X.count("1")


def division_binary_shift(a, b):
    """
    a // b

    :param a: dividend
    :param b: divisor
    :return: quotient
    """
    if a < b:
        return 0
    if b == 0:
        raise ZeroDivisionError

    q = 0
    sq = 1
    ori_b = b
    while a >= b:
        b <<= 1
        if a >= b:
            sq <<= 1
        else:
            b >>= 1
            a -= b
            q += sq
            sq = 1
            b = ori_b

    return a


def f(n, p):
    res = division_binary_shift(int(n, 2), p)
    if res != 0:
        temp2 = format(res, "b")
        return f(temp2, temp2.count("1")) + 1
    return 1


for i in range(0, N):
    tempX = ""
    count = sum_X
    if X[i] == "0":
        count += 1
        X[i] = "1"
        tempX = "".join(X)
        X[i] = "0"
    else:
        count -= 1
        X[i] = "0"
        tempX = "".join(X)
        X[i] = "1"

    print(f(tempX, count))

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

N = int(input())
X = [i for i in input()]
sum_X = X.count("1")


def f(n, p):
    res = int(n, 2) % p
    if res != 0:
        temp2 = format(res, "b")
        return f(temp2, temp2.count("1")) + 1
    return 1


for i in range(0, N):
    tempX = ""
    count = sum_X
    if X[i] == "0":
        count += 1
        X[i] = "1"
        tempX = "".join(X)
        X[i] = "0"
    else:
        count -= 1
        X[i] = "0"
        tempX = "".join(X)
        X[i] = "1"

    print(f(tempX, count))