Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q =int(input())
ten = 0
for _ in range(q):
    ls = tuple(map(str, input().split()))
    if len(ls)==1:
       ten +=1
    else:
        if ls[1] =='1':
            if ten%2 ==0:
                s = ls[2] +s
            else:
                s = s + ls[2]
        else:
            if ten%2 ==1:
                s = ls[2] +s
            else:
                s = s + ls[2]
if ten%2 ==1:
    s = s[::-1]
print(s)

Fixed submission:
s = input()
q =int(input())
ten = 0
r = []
l = []
for _ in range(q):
    ls = tuple(map(str, input().split()))
    if len(ls)==1:
       ten +=1
    else:
        if ls[1] =='1':
            if ten%2 ==0:
                l.append(ls[2])
            else:
                r.append(ls[2])
        else:
            if ten%2 ==1:
                l.append(ls[2])
            else:
                r.append(ls[2])
s = ''.join(reversed(l))+s+''.join(r)
if ten%2 ==1:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q =int(input())
ten = 0
for _ in range(q):
    ls = tuple(map(str, input().split()))
    if len(ls)==1:
       ten +=1
    else:
        if ls[1] =='1':
            if ten%2 ==0:
                s = ls[2] +s
            else:
                s = s + ls[2]
        else:
            if ten%2 ==1:
                s = ls[2] +s
            else:
                s = s + ls[2]
if ten%2 ==1:
    s = s[::-1]
print(s)

Fixed submission:
s = input()
q =int(input())
ten = 0
r = []
l = []
for _ in range(q):
    ls = tuple(map(str, input().split()))
    if len(ls)==1:
       ten +=1
    else:
        if ls[1] =='1':
            if ten%2 ==0:
                l.append(ls[2])
            else:
                r.append(ls[2])
        else:
            if ten%2 ==1:
                l.append(ls[2])
            else:
                r.append(ls[2])
s = ''.join(reversed(l))+s+''.join(r)
if ten%2 ==1:
    s = s[::-1]
print(s)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
ans = ['t'] * n

for _ in range(m):
    s, c = map(int, input().split())
    if ans[s-1] =='t' or ans[s-1] == str(c):
        ans[s-1]= str(c)
    else:
        print(-1)
        exit(0)
if ans[0] == 't':
    ans[0]=str(1)

ans = ''.join(ans).replace('t', str(0))
ans = int(ans)
l = str(ans)
if len(l) != n:
    print(-1)
else:
    print(ans)

Fixed submission:
n = int(input())

print(int(n//2+n%2))
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
ans = ['t'] * n

for _ in range(m):
    s, c = map(int, input().split())
    if ans[s-1] =='t' or ans[s-1] == str(c):
        ans[s-1]= str(c)
    else:
        print(-1)
        exit(0)
if ans[0] == 't':
    ans[0]=1
ans = ''.join(ans).replace('t', str(0))
ans = int(ans)
l = str(ans)
if len(l) != n:
    print(-1)
else:
    print(ans)

Fixed submission:
n, m = map(int, input().split())
ans = ['t'] * n

for _ in range(m):
    s, c = map(int, input().split())
    if ans[s-1] =='t' or ans[s-1] == str(c):
        ans[s-1]= str(c)
    else:
        print(-1)
        exit(0)
if ans[0] == 't' and n >1:
    ans[0]=str(1)

ans = ''.join(ans).replace('t', str(0))
ans = int(ans)
l = str(ans)
if len(l) != n:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
import math

n, k = map(int, input().split())

ans = math.ceil(math.log(n)/math.log(k))

print(ans)


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

if n >=10:
    print(r)
else:
    print(r+1000-100*n)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
import sys
an = list(map(int, sys.stdin.readline().split()))

for i in range(n):
    for j in range(i+1, n):
        if an[i] == an[j]:
            print('NO')
            exit(0)
print('YES')

Fixed submission:
n = int(input())
import sys
an = list(map(int, sys.stdin.readline().split()))

if len(set(an))==n:
    print('YES')
    exit(0)

print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
import sys
pn = list(map(int, sys.stdin.readline().split()))

ans = 1

for i in range(1, n):
    if min(pn[:i+1])==pn[i]:
        ans += 1

print(ans)

Fixed submission:
n = int(input())
import sys
pn = list(map(int, sys.stdin.readline().split()))

ans = 1
mini = pn[0]

for i in range(1, n):
    mini = min(mini, pn[i])
    if mini==pn[i]:
        ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
n= int(input())
s = input()
ans = 1
for i in range(n-1):
    if s[i]==s[i+1]:
        continue
    else:
        ans += 1

print(ans)

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

if b*2 >= a:
    print(0)
else:
    print(int(a-2*b))
Buggy python submission (verdict: Runtime Error):
import sys
n= int(input())
an = list(map(int, sys.stdin.readline().split()))
ans = [0]*n
for i in range(n):
    ans[an[i]-1] = i+1

print(' '.join(ans))

Fixed submission:
import sys
n= int(input())
an = list(map(int, sys.stdin.readline().split()))
ans = [0]*n
for i in range(n):
    ans[an[i]-1] = i+1

print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math

stdin = sys.stdin

nm = lambda: map(int, stdin.readline().split())

a, b = nm()

n = math.gcd(a,b)

count = 1 # 1
for i in range(2, n+1):
    if n%i ==0:
        count +=1
        while n%i == 0:
            n = n/i
    if n ==1:
        break

print(count)

Fixed submission:
import sys
import math

stdin = sys.stdin

nm = lambda: map(int, stdin.readline().split())

a, b = nm()

n = math.gcd(a,b)

count = 1 # 1
for i in range(2, int(n**(1/2))+1):
    if n%i ==0:
        count +=1
        while n%i == 0:
            n = n/i
    if n ==1:
        break
if n != 1:
    count += 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())

a, b = nm()

n = math.gcd(a,b)

m = int(n**(1/2))


count = 1 # 1
for i in range(2, n+1):
    if n%i ==0:
        count +=1
        while n%i == 0:
            n = n/i
    if n ==1:
        break

print(count)


Fixed submission:
import sys
import math

stdin = sys.stdin

nm = lambda: map(int, stdin.readline().split())

a, b = nm()

n = math.gcd(a,b)

count = 1 # 1
for i in range(2, int(n**(1/2))+1):
    if n%i ==0:
        count +=1
        while n%i == 0:
            n = n/i
    if n ==1:
        break
if n != 1:
    count += 1

print(count)
Buggy python submission (verdict: Runtime Error):
weathers = ['Sunny', 'Cloudy', 'Rainy' ]
s = str(input())
t = weathers.index(s)
print(weathers[t+1])


Fixed submission:
weathers = ['Sunny', 'Cloudy', 'Rainy' ]
s = str(input())
t = weathers.index(s)
print(weathers[t-2])
Buggy python submission (verdict: Runtime Error):
n = int(input())
hn =list(map(int, input().split()))
ls= [0]*(n-1)
ans = 0
for i in range(n-1):
    if hn[i+1] <= hn[i]:
        ls[i] = 1
    else:
        ls[i] = -sum(ls[:i])

import numpy as np
ans = max(np.cumsum(ls))

print(ans)

Fixed submission:
n = int(input())
hn =list(map(int, input().split()))
ls= [0]*(n-1)
ans = 0
count = 0
for i in range(n-1):
    if hn[i+1] <= hn[i]:
        ls[i] = 1
        count += 1
    else:
        ans = max(ans, count)
        count=0

ans = max(ans, count)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0
ls = []
for _ in range(n):
    s = ''.join(sorted(input()))
    for j in ls:
        if j == s:
            ans +=1
    ls.append(s)
print(ans)

Fixed submission:
n = int(input())
ans = 0
ls = {}
for _ in range(n):
    s = ''.join(sorted(input()))
    if s in ls:
        ans += ls[s]
        ls[s] += 1
    else:
        ls[s] = 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0
ls = []
for _ in range(n):
    s = input()
    ls2 = []
    for i in range(10):
        ls2.append(s[i])
    ls3 = sorted(ls2)
    for j in ls:
        if j == ls3:
            ans +=1
    ls.append(ls3)
print(ans)

Fixed submission:
n = int(input())
ans = 0
ls = {}
for _ in range(n):
    s = ''.join(sorted(input()))
    if s in ls:
        ans += ls[s]
        ls[s] += 1
    else:
        ls[s] = 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0
ls = []
for _ in range(n):
    s = input()
    ls2 = []
    for i in range(10):
        ls2.append(s[i])
    ls3 = ''.join(sorted(ls2))
    for j in ls:
        if j == ls3:
            ans +=1
    ls.append(ls3)
print(ans)

Fixed submission:
n = int(input())
ans = 0
ls = {}
for _ in range(n):
    s = ''.join(sorted(input()))
    if s in ls:
        ans += ls[s]
        ls[s] += 1
    else:
        ls[s] = 1
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, c,d = map(int, input().split())
import math
min = c*d/math.gcd(c,d)
def num(x):
    return x-x//c - x//d + x//min
print(int(num(b)-num(a-1)))

Fixed submission:
s = str(input())

if s[0]==s[1] or s[1]==s[2] or s[3]==s[2]:
    print('Bad')
else:
    print('Good')
Buggy python submission (verdict: Time Limit Exceeded):
a, b, c,d = map(int, input().split())

count = 0

for i in range(a, b+1):
    if i%c != 0 and i%d != 0:
        count +=1

print(count)

Fixed submission:
a, b, c,d = map(int, input().split())
import math
min = int(c*d/math.gcd(c,d))
x = b-b//c - b//d + b//min
y = a-1-(a-1)//c - (a-1)//d + (a-1)//min

print(int(x-y))
Buggy python submission (verdict: Runtime Error):
def main():
    n =  int(input())
    ls = []
    for _ in range(n):
        a, b = map(int, input().split())
        ls.append([b,a])
    ls = ls.sort()
    t=0
    for i in ls:
        t += i[1]
        if t > i[0]:
            print('No')
            exit(0)
    print('Yes')
if __name__ == '__main__':
    main()

Fixed submission:
n =  int(input())
ls = []
for _ in range(n):
    a, b = map(int, input().split())
    ls.append([b,a])
ls = sorted(ls)
t=0
for i in ls:
    t += i[1]
    if t > i[0]:
        print('No')
        exit(0)
print('Yes')

Buggy python submission (verdict: Runtime Error):
def main():
    n =  int(input())
    ls = []
    for _ in range(n):
        a, b = map(int, input().split())
        ls.append([b,a])
    ls = ls.sort()
    t=0
    for i in ls:
        t += i[1]
        if t > i[0]:
            print('No')
            exit(0)
    print('Yes')
if __name__ == '__main__':
    main()

Fixed submission:
n =  int(input())
ls = []
for _ in range(n):
    a, b = map(int, input().split())
    ls.append([b,a])
ls = sorted(ls)
t=0
for i in ls:
    t += i[1]
    if t > i[0]:
        print('No')
        exit(0)
print('Yes')
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
par = [i for i in range(n)]
diff = [0]*n

def find(x):
    if par[x] == x:
        return x, 0
    else:
        a, b = find(par[x])
        par[x] = a
        diff[x] += b
        return a, diff[x]


def unite(x,y,z):
    s, ws = find(x)
    t, wt = find(y)
    #print(ws, wt)
    if s==t:
        if ws - wt == z:
            pass
        else:
            print('No')
            exit(0)
    else:
        par[s] = t
        diff[s] = z

unites =[]
for _ in range(m):
    l,r,d = map(int, input().split())
    unites.append((l,r,d))
    unite(l-1,r-1,d)
for x, y, z in unites:
    unites(x-1, y-1, d)

print('Yes')

Fixed submission:
n, m = map(int, input().split())
par = [i for i in range(n)]
diff = [0] * n


def find(x):
    if par[x] == x:
        return x, 0
    else:
        a, b = find(par[x])
        par[x] = a
        diff[x] += b
        return a, diff[x]


def unite(x, y, z):
    s, ws = find(x)
    t, wt = find(y)
    # print(ws, wt)
    if s == t:
        if ws - wt == z:
            pass
        else:
            print('No')
            exit(0)
    else:
        if ws < z + wt:
            par[s] = t
            diff[s] = z + wt - ws
        else:
            par[t] = s
            diff[t] = ws - z - wt


for _ in range(m):
    l, r, d = map(int, input().split())
    unite(l - 1, r - 1, d)

print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
a = list(input().split())
count = 0
tmp = 1
check = []
for _ in range(n - k + 1):
    for i in range(k):
        tmp *= int(a[i + count])
    check.append(tmp)
    tmp = 1
    count += 1

for j in range(n - k):
    if check[j] < check[j + 1]:
        print("Yes")
    else:
        print("No")

Fixed submission:
n, k = input().split()
n = int(n)
k = int(k)
a = [int(s) for s in input().split()]
sums = []
K = k - 1
for i in range(K,n - 1):
    if(a[i - K] < a[i + 1]):
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
x,y = int(input().split())
if y % 2 == 1:
    print("No")
elif 2 * x <= y <= 4 * x:
    print("Yes")
else:
    print("No")

Fixed submission:
x,y = map(int, input().split())
if y % 2 == 1:
    print("No")
elif 2 * x <= y <= 4 * x:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,k = map(int,input().split())
card = []
for i in range(a):
    card.append(1)
for i in range(b):
    card.append(0)
for i in range(c):
    card.append(-1)
card.sort(key=int,reverse=True)
result = 0
for i in range(k):
    result += card[i]
print(result)

Fixed submission:
a,b,c,k = map(int,input().split())
if k < a:
    print(k)
elif a + b > k:
    print(a)
else:
    print(a - (k - a - b))
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
sunuke = []
for _ in range(int(input())):
    tmp = [int(s) for s in input().split()]
    for i in range(len(tmp)):
        sunuke.append(tmp[i])
print(n - len(set(sunuke)))

Fixed submission:
n,k = map(int,input().split())
sunuke = []
for _ in range(k):
    d = input()
    tmp = [int(s) for s in input().split()]
    for i in range(len(tmp)):
        sunuke.append(tmp[i])

print(n - len(set(sunuke)))
Buggy python submission (verdict: Time Limit Exceeded):
n,k,q = map(int,input().split())
point = [k]*(n)
for _ in range(q):
    a = int(input())
    for i in range(n):
        if a-1 == i:
            pass
        else:
            point[i] -= 1
for i in range(n):
    if point[i] > 0:
        print("Yes")
    else:
        print("No")

Fixed submission:
n,k,q = map(int,input().split())
point = [k]*(n)
for _ in range(q):
    a = int(input())
    point[a-1] += 1
for i in range(n):
    if point[i] - q > 0:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
for _ in range(n):a.append(int(input()))

for i in range(n):
    tmp = a[i]
    a[i] = 0
    print(max(a))
    a[i] = tmp

Fixed submission:
n = int(input())
a = []
for _ in range(n):a.append(int(input()))

max_ = max(a)
max2 = sorted(a)[-2]
for i in range(n):
    if a[i] != max_:
        print(max_)
    else:
        print(max2)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
for _ in range(n):a.append(int(input()))

for i in range(n):
    tmp = a[i]
    a[i] = 0
    print(max(a))
    a[i] = tmp

Fixed submission:
n = int(input())
a = []
for _ in range(n):a.append(int(input()))

max_ = max(a)
max2 = sorted(a)[-2]
for i in range(n):
    if a[i] != max_:
        print(max_)
    else:
        print(max2)
Buggy python submission (verdict: Runtime Error):
n,y = map(int,input().split())

for i in range(y // 10000 + 1):
    for j in range(y // 5000 + 1):
        k = n - i - j
        if 0 <= k and 10000 * i + 5000 * j + 1000 * k == y:
            print(i,j,k,sep=" ")
            exit()
print("-1 " + "-1" + " -1")

Fixed submission:
print("2018" + input()[4:])
Buggy python submission (verdict: Runtime Error):
s = input()
flag = 0
for i in range(len(s)):
    if s[i] == "A":
        if s[i + 1] == "C":
            flag = 1
if flag == 1:
    print("Yes")
else:
    print("No")

Fixed submission:
s = input()
flag = 0
for i in range(len(s) - 1):
    if s[i] == "A":
        if s[i + 1] == "C":
            flag = 1
if flag == 1:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
array = list(map(str, input().split()))
if array[0] == array[2]:
    print("Yes")
else:
    print("No")

Fixed submission:
array = list(map(str, input()))
if array[0] == array[2]:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
array = list(map(int, input().split()))
if array[0] == array[2]:
    print("Yes")
else:
    print("No")

Fixed submission:
array = list(map(str, input()))
if array[0] == array[2]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())

count = 0

for i in range(k + 1):
    for j in range(k + 1):
        for t in range(k + 1):
            if i + j + t == s:
                count += 1
print(count)

Fixed submission:
k,s = map(int,input().split())

count = 0

for x in range(k + 1):
    for y in range(k + 1):
        if 0 <= s - x - y <= k:
            count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
a,b = map(int,input().split())

count = 1

for i in range(a,b+1):
    count *= i

if count == 0:
    print("Zero")
elif count > 0:
    print("Positive")
else:
    print("Negative")

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

if 0 < a <= b:
    print("Positive")
elif a <= b < 0:
    if (b - a + 1) % 2 == 0:
        print("Positive")
    else:
        print("Negative")
else:
    print("Zero")
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
from fractions import gcd
N=int(sys.stdin.readline().strip())
A=map(int, sys.stdin.readline().split())

def factorization(n):
    arr=set()
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.add(i)

    if temp!=1:
        arr.add(temp)

    if arr==[]:
        arr.add(n)

    return arr

pairwise_coprime=True

SOINSU=defaultdict(lambda: 0)

setwise_coprime=None
for i,a in enumerate(A):
    #全ての数が互いに素か　pairwise coprime判定
    f=factorization(a)
    for x in f:
        if SOINSU[x]==1:
            pairwise_coprime=False
            break
        SOINSU[x]=1
    #GCDの累積を取る　setwise coprime判定
    if i==0:
        setwise_coprime=a
    else:
        setwise_coprime=gcd(setwise_coprime,a)

if pairwise_coprime==True:
    print "pairwise coprime"
elif setwise_coprime==1:
    print "setwise coprime"
else:
    print "not coprime"

Fixed submission:
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
from fractions import gcd
N=int(sys.stdin.readline().strip())
A=map(int, sys.stdin.readline().split())

def factorization(n):
    arr=set()
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.add(i)

    if temp!=1:
        arr.add(temp)

    if arr==[]:
        arr.add(n)

    return arr

pairwise_coprime=True

SOINSU=defaultdict(lambda: 0)

setwise_coprime=None
for i,a in enumerate(A):
    #全ての数が互いに素か　pairwise coprime判定
    if pairwise_coprime==False:
        pass
    else:
        f=factorization(a)
        for x in f:
            if SOINSU[x]==1:
                pairwise_coprime=False
                break
            SOINSU[x]=1
    #GCDの累積を取る　setwise coprime判定
    if i==0:
        setwise_coprime=a
    else:
        setwise_coprime=gcd(setwise_coprime,a)

if pairwise_coprime==True:
    print "pairwise coprime"
elif setwise_coprime==1:
    print "setwise coprime"
else:
    print "not coprime"
Buggy python submission (verdict: Time Limit Exceeded):
import sys
K=int(sys.stdin.readline().strip())
a=0
for i in range(10**7):
    a+=7*pow(10,i,K)
    a%=K
    if a==0:
        print i+1
        quit()
else:
    print -1

Fixed submission:
import sys
N=int(sys.stdin.readline().strip())

a=0
for i in range(10**6):
    a+=7*pow(10,i,N)
    if a%N==0:
        print i+1
        quit()
else:
    print -1
Buggy python submission (verdict: Runtime Error):
import sys
import itertools
import copy
ORG=map(int, sys.stdin.readline().split())
K=int(sys.stdin.readline().strip())
L=list( itertools.product(range(3), repeat=K) )

for x in L:
    ABC=copy.deepcopy(ORG)
    ABC[x[0]]*=2
    ABC[x[1]]*=2
    ABC[x[2]]*=2
    if ABC[0]<ABC[1]<ABC[2]:
        print "Yes"
        quit()
else:
    print "No"


Fixed submission:
import sys
import itertools
import copy
ORG=map(int, sys.stdin.readline().split())
K=int(sys.stdin.readline().strip())
L=list( itertools.product(range(3), repeat=K) )

for l in L:
    ABC=copy.deepcopy(ORG)
    for x in l:
        ABC[x]*=2
    if ABC[0]<ABC[1]<ABC[2]:
        print "Yes"
        quit()
else:
    print "No"
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
N=int(sys.stdin.readline().strip())
X=sys.stdin.readline().strip()

cnt_of_one=0
for x in X:
    if x=="1": cnt_of_one+=1

cnt_of_one_plus_one=cnt_of_one+1
cnt_of_one_minus_one=cnt_of_one-1

amari_cnt_of_one_plus_one=0
amari_cnt_of_one_minus_one=0
for i,x in enumerate(X[::-1]):
    if x=="1":    #その桁の値が1の時だけ数を足す
        amari_cnt_of_one_plus_one+=pow(2,i,cnt_of_one_plus_one)
        amari_cnt_of_one_plus_one%=cnt_of_one_plus_one
        amari_cnt_of_one_minus_one+=pow(2,i,cnt_of_one_minus_one)
        amari_cnt_of_one_minus_one%=cnt_of_one_minus_one

def popcount(n):
    ret=0
    while 0<n:
        ret+=n%2
        n/=2
    return ret

def f(n):
    ret=0   #余りが0になるまでの割った回数
    while 0<n:
        n%=popcount(n)
        ret+=1
    return ret

for i,x in enumerate(X):
    keta=N-i-1
    if x=="0":
        syoki_amari=(amari_cnt_of_one_plus_one+pow(2,keta,cnt_of_one_plus_one))%cnt_of_one_plus_one
        if syoki_amari==0:
            print 1
        else:
            print 1+f(syoki_amari)
    elif x=="1":
        syoki_amari=(amari_cnt_of_one_minus_one-pow(2,keta,cnt_of_one_minus_one))%cnt_of_one_minus_one
        if syoki_amari==0:
            print 1
        else:
            print 1+f(syoki_amari)

Fixed submission:
# -*- coding: utf-8 -*-
import sys
N=int(sys.stdin.readline().strip())
X=sys.stdin.readline().strip()

cnt_of_one=0
for x in X:
    if x=="1": cnt_of_one+=1

cnt_of_one_plus_one=cnt_of_one+1
cnt_of_one_minus_one=cnt_of_one-1

amari_cnt_of_one_plus_one=0
amari_cnt_of_one_minus_one=0
for i,x in enumerate(X[::-1]):
    if x=="1":    #その桁の値が1の時だけ数を足す
        amari_cnt_of_one_plus_one+=pow(2,i,cnt_of_one_plus_one)
        amari_cnt_of_one_plus_one%=cnt_of_one_plus_one
        if cnt_of_one_minus_one==0: #2進数の全ての桁が0の場合は、0で除算はできないので場合分け
            amari_cnt_of_one_minus_one=0
        else:
            amari_cnt_of_one_minus_one+=pow(2,i,cnt_of_one_minus_one)
            amari_cnt_of_one_minus_one%=cnt_of_one_minus_one

def popcount(n):
    ret=0
    while 0<n:
        ret+=n%2
        n/=2
    return ret

def f(n):
    ret=0   #余りが0になるまでの割った回数
    while 0<n:
        n%=popcount(n)
        ret+=1
    return ret

for i,x in enumerate(X):
    keta=N-i-1
    if x=="0":
        syoki_amari=(amari_cnt_of_one_plus_one+pow(2,keta,cnt_of_one_plus_one))%cnt_of_one_plus_one
        if syoki_amari==0:
            print 1
        else:
            print 1+f(syoki_amari)
    elif x=="1":
        if cnt_of_one_minus_one==0: #2進数の全ての桁が0という意味だから
            print 0 #値が0になるまでの操作回数は0回
        else:
            syoki_amari=(amari_cnt_of_one_minus_one-pow(2,keta,cnt_of_one_minus_one))%cnt_of_one_minus_one
            if syoki_amari==0:
                print 1
            else:
                print 1+f(syoki_amari)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
N=int(sys.stdin.readline().strip())
A=map(int, sys.stdin.readline().split())

ans=1
for a in A:
    ans*=a

if 10**18<ans:
    print -1
else:
    print ans


Fixed submission:
import sys
N=int(sys.stdin.readline().strip())
A=map(int, sys.stdin.readline().split())

ans=1
for a in A:
    if a==0:
        ans*=a
    elif ans==-1:
        pass
    else:
        ans*=a
        if 10**18<ans:
            ans=-1

if 10**18<ans:
    print -1
else:
    print ans