Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ai = list(map(int, input().split()))

#print(ai)
dai={}
dbi={}
for i in range(1, n+1):
    dai.setdefault(i, ai[i-1])
    dbi.setdefault(i, 0)

#print(dai)
#print(dbi)

anssum=0
ans=[]
for i in range(1, n+1)[::-1]:
    #print(i)
    tmp=0
    for j in range(2, n+1):
        check=i*j
        if check <= n:
            tmp = tmp + dbi[check]
    tmp = tmp%2
    #print(str(tmp) + ", " + str(dai[i]))
    if tmp != dai[i]:
        dbi[i]=1
        anssum=anssum+1
        ans.append(i)

#print(dbi)
print(anssum)
if anssum != 0:
    print(" ".join(map(str, reversed(ans))))

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

#print(ai)
dai={}
dbi={}
for i in range(1, n+1):
    dai.setdefault(i, ai[i-1])
    dbi.setdefault(i, 0)

#print(dai)
#print(dbi)

anssum=0
ans=[]
for i in range(1, n+1)[::-1]:
    #print(i)
    tmp=0
    for j in range(2, n+1):
        check=i*j
        if check <= n:
            tmp = tmp + dbi[check]
        else:
            break
    tmp = tmp%2
    #print(str(tmp) + ", " + str(dai[i]))
    if tmp != dai[i]:
        dbi[i]=1
        anssum=anssum+1
        ans.append(i)

#print(dbi)
print(anssum)
if anssum != 0:
    print(" ".join(map(str, reversed(ans))))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ai = list(map(int, input().split()))

#print(ai)
dai={}
dbi={}
for i in range(1, n+1):
    dai.setdefault(i, ai[i-1])
    dbi.setdefault(i, 0)

#print(dai)
#print(dbi)

anssum=0
ans=[]
for i in range(1, n+1)[::-1]:
    #print(i)
    tmp=0
    for j in range(2, n+1):
        check=i*j
        if check <= n:
            tmp = tmp + dbi[check]
    tmp = tmp%2
    #print(str(tmp) + ", " + str(dai[i]))
    if tmp != dai[i]:
        dbi[i]=1
        anssum=anssum+1
        ans.append(i)

#print(dbi)
print(anssum)
if anssum != 0:
    print(" ".join(map(str, reversed(ans))))

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

#print(ai)
dai={}
dbi={}
for i in range(1, n+1):
    dai.setdefault(i, ai[i-1])
    dbi.setdefault(i, 0)

#print(dai)
#print(dbi)

anssum=0
ans=[]
for i in range(1, n+1)[::-1]:
    #print(i)
    tmp=0
    for j in range(2, n+1):
        check=i*j
        if check <= n:
            tmp = tmp + dbi[check]
        else:
            break
    tmp = tmp%2
    #print(str(tmp) + ", " + str(dai[i]))
    if tmp != dai[i]:
        dbi[i]=1
        anssum=anssum+1
        ans.append(i)

#print(dbi)
print(anssum)
if anssum != 0:
    print(" ".join(map(str, reversed(ans))))
Buggy python submission (verdict: Runtime Error):

from math import factorial
import sys
sys.setrecursionlimit(10000000)

N, K = map(int, input().split())
MOD=10**9+7

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    #if (n,r) in nCr: return nCr[(n,r)]
    #nCr[(n,r)] = cmb(n-1,r)%MOD + cmb(n-1,r-1)%MOD
    #return nCr[(n,r)]
    a = factorial(n)%MOD / factorial(r)%MOD / factorial(n - r)%MOD
    return int(a)

presum=0
for i in range(1,K+1):
    tmp=cmb(N-K+i, i)%MOD
    ans=(tmp-presum)*cmb(K-1, i-1)%MOD
    presum += ans
    print(ans)

Fixed submission:

N, K = map(int, input().split())
MOD=10**9+7

def cmb(n, r):
    if n < r: return 0 #date added
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

for i in range(1,K+1):
    ans=cmb(N-K+1, i)%MOD*cmb(K-1, i-1)%MOD
    # cmb(N-K+i, i) -> cmb(N-K+1, i)
    #if N==K and 1 < i: ans=0
    print(int(ans%MOD))
Buggy python submission (verdict: Time Limit Exceeded):

mod=10**9+7
n, m = map(int, input().split())
ai=[]

for i in range(m):
    ai.append(int(input()))
#print(ai)

dp=[]
for i in range(n+1):
    dp.append(0)

dp[0]=1
if 1 in ai:
    dp[1]=0
else:
    dp[1]=1

for i in range(2,n+1):
    if i in ai:
        continue
    dp[i]=(dp[i-1]+dp[i-2])%mod

#print(dp)
print(dp[n])


Fixed submission:

mod=10**9+7
n, m = map(int, input().split())
ai={}

for i in range(m):
    ai.setdefault(int(input()), 0)
#print(ai)

dp={}
for i in range(n+1):
    dp.setdefault(i, 0)

dp[0]=1
if 1 in ai:
    dp[1]=0
else:
    dp[1]=1

for i in range(2,n+1):
    if i in ai:
        continue
    dp[i]=(dp[i-1]+dp[i-2])%mod

#print(dp)
print(dp[n])
Buggy python submission (verdict: Runtime Error):
n = int(input())
tree = [[] for i in range(n+1)]

for i in range(1,n):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

c = list(map(int,input().split()))
#print(c)
#cs = sorted(c, reverse=True)
#print(cs)
cs = sorted(c)
#print(cs)

ansd=[0]*(n)
score=0

stack = deque()
stack.append(1)
ansd[0]=cs.pop()
visitted=[]

while stack:
    cur = stack.popleft()
    visitted.append(cur)
    for v in tree[cur]:
        if v in visitted:
            continue
        stack.append(v)
        ansd[v-1]=cs.pop()
        score += min(ansd[cur-1], ansd[v-1])

print(score)
print(*ansd, sep=' ')
#print(visitted)

Fixed submission:

from collections import deque

n = int(input())
tree = [[] for i in range(n+1)]

for i in range(1,n):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

c = list(map(int,input().split()))
#print(c)
#cs = sorted(c, reverse=True)
#print(cs)
cs = sorted(c)
#print(cs)

ansd=[0]*(n)
score=0

stack = deque()
stack.append(1)
ansd[0]=cs.pop()
visitted=[]

while stack:
    cur = stack.popleft()
    visitted.append(cur)
    for v in tree[cur]:
        if v in visitted:
            continue
        stack.append(v)
        ansd[v-1]=cs.pop()
        score += min(ansd[cur-1], ansd[v-1])

print(score)
print(*ansd, sep=' ')
#print(visitted)
Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n = map(int,input().split())

res=0
tmp=n
tmp1=0
re=n//r+1
ge=n//g+1

for i in range(re):
	tmp = tmp - i*r
	tmp1 = tmp
	for j in range(ge):
		tmp1 = tmp - j*g
		if tmp1 >= 0 and tmp1%b==0:
			res = res + 1
			#print(i, j, int(tmp1/t2[2]))
		tmp1 = tmp
	tmp=n

print(res)

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

res=0
tmp=n
tmp1=0
re=n//r+1
ge=n//g+1

for i in range(re):
	tmp = tmp - i*r
	tmp1 = tmp
	for j in range(ge):
		tmp1 = tmp - j*g
		if tmp1 >= 0 and tmp1%b==0:
			res = res + 1
			#print(i, j, int(tmp1/t2[2]))
		tmp1 = tmp
	tmp=n

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n = map(int,input().split())

res=0
tmp=n
tmp1=0

for i in range(n//r+1):
	tmp = tmp - i*r
	tmp1 = tmp
	for j in range(n//g+1):
		tmp1 = tmp - j*g
		if tmp1 >= 0 and tmp1%b==0:
			res = res + 1
			#print(i, j, int(tmp1/t2[2]))
		tmp1 = tmp
	tmp=n

print(res)

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

res=0
tmp=n
tmp1=0
re=n//r+1
ge=n//g+1

for i in range(re):
	tmp = tmp - i*r
	tmp1 = tmp
	for j in range(ge):
		tmp1 = tmp - j*g
		if tmp1 >= 0 and tmp1%b==0:
			res = res + 1
			#print(i, j, int(tmp1/t2[2]))
		tmp1 = tmp
	tmp=n

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n = map(int,input().split())

res=0
tmp=n
tmp1=0

for i in range(n//r+1):
	tmp -= i*r
	tmp1 = tmp
	for j in range(n//g+1):
		tmp1 -= j*g
		if tmp1 >= 0 and tmp1%b==0:
			res+=1
			#print(i, j, int(tmp1/t2[2]))
		tmp1 = tmp
	tmp=n

print(res)

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

res=0
tmp=n
tmp1=0
re=n//r+1
ge=n//g+1

for i in range(re):
	tmp = tmp - i*r
	tmp1 = tmp
	for j in range(ge):
		tmp1 = tmp - j*g
		if tmp1 >= 0 and tmp1%b==0:
			res = res + 1
			#print(i, j, int(tmp1/t2[2]))
		tmp1 = tmp
	tmp=n

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n = map(int,input().split())

res=0
tmp=n
tmp1=0
t1 = [r,g,b]
t2 = sorted(t1, reverse=True)
#print(t2)

for i in range(n//t2[0]+1):
	tmp -= i*t2[0]
	tmp1 = tmp
	for j in range(n//t2[1]+1):
		tmp1 -= j*t2[1]
		if tmp1 >= 0 and tmp1%t2[2]==0:
			res+=1
			#print(i, j, int(tmp1/t2[2]))
		tmp1 = tmp
	tmp=n

print(res)

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

res=0
tmp=n
tmp1=0
re=n//r+1
ge=n//g+1

for i in range(re):
	tmp = tmp - i*r
	tmp1 = tmp
	for j in range(ge):
		tmp1 = tmp - j*g
		if tmp1 >= 0 and tmp1%b==0:
			res = res + 1
			#print(i, j, int(tmp1/t2[2]))
		tmp1 = tmp
	tmp=n

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ai = list(map(int,input().split()))

def gcd(a, b):
  while b:
    a, b = b, a%b
  return a

resmax = 0
for j in range(n):
	if j == 0:
		res = ai[1]
		for i in range(2,n):
			res = gcd(ai[i],res)
	else:
		res = ai[0]
		for i in range(1,n):
			if i == j:
				continue
			else:
				res = gcd(ai[i],res)
	if res > resmax:
		resmax = res

#print(resi)
print(resmax)


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

def gcd(a, b):
  while b:
    a, b = b, a%b
  return a

r=[]
l=[]
resr = ai[0]
resl = ai[n-1]
r.append(ai[0])
l.append(ai[n-1])
for i in range(1,n):
	resr=gcd(resr,ai[i])
	r.append(resr)
	resl=gcd(resl,ai[n-1-i])
	l.append(resl)

#print(r)
#print(l)

resmax = 1
for i in range(n):
	if i == 0:
		res = l[n-1-1]
	elif i == n-1:
		res = r[n-1-1]
	else:
		res = gcd(r[i-1], l[n-1-i-1])
	if res > resmax:
		resmax = res

print(int(resmax))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ai = list(map(int,input().split()))

def gcd(a, b):
  while b:
    a, b = b, a%b
  return a

resi = []
for j in range(n):
	if j == 0:
		res = ai[1]
		for i in range(2,n):
			res = gcd(ai[i],res)
	else:
		res = ai[0]
		for i in range(1,n):
			if i == j:
				continue
			else:
				res = gcd(ai[i],res)
	resi.append(res)

#print(resi)
print(max(resi))


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

def gcd(a, b):
  while b:
    a, b = b, a%b
  return a

r=[]
l=[]
resr = ai[0]
resl = ai[n-1]
r.append(ai[0])
l.append(ai[n-1])
for i in range(1,n):
	resr=gcd(resr,ai[i])
	r.append(resr)
	resl=gcd(resl,ai[n-1-i])
	l.append(resl)

#print(r)
#print(l)

resmax = 1
for i in range(n):
	if i == 0:
		res = l[n-1-1]
	elif i == n-1:
		res = r[n-1-1]
	else:
		res = gcd(r[i-1], l[n-1-i-1])
	if res > resmax:
		resmax = res

print(int(resmax))
Buggy python submission (verdict: Runtime Error):
n = int(input())
ai = list(map(int,input().split()))

def dp(i, j):
	if i==0 and j==0:
		return 0
	elif i == 0 and j==1:
		return -10**9
	elif j==0:
		return max(dp(i-1,0)+ai[i-1], dp(i-1,1)-ai[i-1])
	else:
		return max(dp(i-1,0)-ai[i-1], dp(i-1,1)+ai[i-1])

print(dp(n,0))

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

dp =[[0, -10**9]]
#print(dp[0][0])

for i in range(1,n+1):
	dp.append([max(dp[i-1][0]+ai[i-1], dp[i-1][1]-ai[i-1]), \
			max(dp[i-1][0]-ai[i-1], dp[i-1][1]+ai[i-1])])
	#print(dp)
    
print(dp[n][0])

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

dp = [[]]

def dp(i, j):
	if i==0 and j==0:
		return 0
	elif i == 0 and j==1:
		return -10**11
	elif j ==0:
		return max(dp(i-1,0)+ai[i-1], dp(i-1,1)-ai[i-1])
	else:
		return max(dp(i-1,0)-ai[i-1], dp(i-1,1)+ai[i-1])

print(dp(n,0))

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

dp =[[0, -10**9]]
#print(dp[0][0])

for i in range(1,n+1):
	dp.append([max(dp[i-1][0]+ai[i-1], dp[i-1][1]-ai[i-1]), \
			max(dp[i-1][0]-ai[i-1], dp[i-1][1]+ai[i-1])])
	#print(dp)
    
print(dp[n][0])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
sl=list(s)

c=0
b=0
w=0
res=2*10^5
for i in range(n-1):
	b = sl[:i].count("#")
	w = sl[i+1:].count(".")
	c = b + w
	#print(c)
	if c < res:
		res = c

if sl.count("#")==n or sl.count(".")==n:
	res = 0

print(res)

Fixed submission:
n=int(input())
sl=list(input())

bi=0
wi=0
b=[]
w=[]
for i in range(n):
	if sl[i] == "#":
		bi = bi+1
	else:
		wi = wi+1
	b.append(bi)
	w.append(wi)

c=0
res=2*10**6
for i in range(n-1):
	if (sl[i]=="#" and sl[i+1]==".") or (sl[i]=="." and sl[i+1]=="#") :
		c = b[i] + w[n-1]-w[i]
		if c < res:
			res = c

w0=w[n-1]
b0=b[n-1]
if w[0]==1:
	for i in range(n-1):
		if w[i]==w[i+1]:
			w0=w[n-1]-w[i]
			break
if b[n-1]-b[n-2]==1:
	for i in range(n-1):
		if b[n-1-i]==b[n-1-i-1]:
			b0=b[n-1-i]
			break

if w0<res:
	res=w0
if b0<res:
	res=b0

print(res)

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
sl=list(s)

res=0
for i in range(n):
	if sl[i]=="#" and sl[i+1]==".":
		res= res + 1
        
print(res)


Fixed submission:
n=int(input())
sl=list(input())

bi=0
wi=0
b=[]
w=[]
for i in range(n):
	if sl[i] == "#":
		bi = bi+1
	else:
		wi = wi+1
	b.append(bi)
	w.append(wi)

c=0
res=2*10**6
for i in range(n-1):
	if (sl[i]=="#" and sl[i+1]==".") or (sl[i]=="." and sl[i+1]=="#") :
		c = b[i] + w[n-1]-w[i]
		if c < res:
			res = c

w0=w[n-1]
b0=b[n-1]
if w[0]==1:
	for i in range(n-1):
		if w[i]==w[i+1]:
			w0=w[n-1]-w[i]
			break
if b[n-1]-b[n-2]==1:
	for i in range(n-1):
		if b[n-1-i]==b[n-1-i-1]:
			b0=b[n-1-i]
			break

if w0<res:
	res=w0
if b0<res:
	res=b0

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

x,y,z,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

Ai= sorted(A, reverse=True)
Bi= sorted(B, reverse=True)
Ci= sorted(C, reverse=True)

def su(a,b,c):
	return(Ai[a]+Bi[b]+Ci[c])

a=0
b=0
c=0

pq=[[su(a,b,c),a,b,c]]
ck=[[su(a,b,c),a,b,c]]

dl=0
for i in range(k):
	dl=pq.index(max(pq))
	res=pq.pop(dl)
	print(res[0])
	#print(pq)
	
	a=res[1]
	b=res[2]
	c=res[3]
	if a+1<=x-1 and (not [su(a+1,b,c),a+1,b,c] in ck):
		pq.append([su(a+1,b,c),a+1,b,c])
		ck.append([su(a+1,b,c),a+1,b,c])
	if b+1<=y-1 and (not [su(a,b+1,c),a,b+1,c] in ck):
		pq.append([su(a,b+1,c),a,b+1,c])
		ck.append([su(a,b+1,c),a,b+1,c])
	if c+1<=z-1 and (not [su(a,b,c+1),a,b,c+1] in ck):
		pq.append([su(a,b,c+1),a,b,c+1])
		ck.append([su(a,b,c+1),a,b,c+1])

Fixed submission:
import math

x,y,z,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

Ai= sorted(A, reverse=True)
Bi= sorted(B, reverse=True)
Ci= sorted(C, reverse=True)

def su(a,b,c):
	return(Ai[a]+Bi[b]+Ci[c])

a=0
b=0
c=0

pq=[[su(a,b,c),a,b,c]]
ck=[a,b,c]

dl=0
for i in range(k):
	dl=pq.index(max(pq))
	res=pq.pop(dl)
	print(res[0])

	a=res[1]
	b=res[2]
	c=res[3]
	if a+1<=x-1 and (not [a+1,b,c] in ck):
		pq.append([su(a+1,b,c),a+1,b,c])
		ck.append([a+1,b,c])
	if b+1<=y-1 and (not [a,b+1,c] in ck):
		pq.append([su(a,b+1,c),a,b+1,c])
		ck.append([a,b+1,c])
	if c+1<=z-1 and (not [a,b,c+1] in ck):
		pq.append([su(a,b,c+1),a,b,c+1])
		ck.append([a,b,c+1])
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int,input().split())
s = list(input())

count=[]
for i in range(len(s)):
	count.append(0)

for i in range(len(s)-1):
	if s[i] == "A" and s[i+1] == "C":
		count[i]=count[i]+1
		#count[i+1]=count[i+1]+1
#print(count)

result=0
for i in range(Q):
	l, r = map(int,input().split())
	for i in count[l-1:r-1]:
		#if count[i]==1 and count[i+1]==0:
 			result = result+i
	print(result)
	result=0

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

count=[]
num=0
count.append(num)
for i in range(len(s)-1):
	if s[i] == "A" and s[i+1] == "C":
		num=num+1
		count.append(num)
	else:
		count.append(num)

for i in range(Q):
	l, r = map(int,input().split())
	print(count[r-1]-count[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int,input().split())
s = list(input())

# print(s)

result=0
for i in range(Q):
	l, r = map(int,input().split())
	for i in range(l-1,r-1):
		if s[i]== "A" and s[i+1]== "C":
 			result = result+1
	print(result)
	result=0


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

count=[]
num=0
count.append(num)
for i in range(len(s)-1):
	if s[i] == "A" and s[i+1] == "C":
		num=num+1
		count.append(num)
	else:
		count.append(num)

for i in range(Q):
	l, r = map(int,input().split())
	print(count[r-1]-count[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
A,B = map(int,input().split())

Result = []
for i in range(0,40):
	Result.append(0)

for i in range(A,B+1):
	li=list(bin(i))
	#print(li)
	li.reverse()
	for j in range(len(li)):
		if li[j] == "1":
			Result[j]=Result[j]+1

#print(Result)
R2 = list(map(lambda x: str(x%2),Result))

#for k in R2[::-1]:
#	if k == "0":
#		R2.pop()
#	else:
#		break

R2.reverse()
#print(R2)
print(int("0b"+"".join(R2),2))

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

def f(x):
	if x == 0:
		return 0
	elif x%2==0:
		return int(x/2)%2 ^ x
	else:
		return int((x-1)/2)%2 ^ x-1 ^ x

if A==B:
	print(B)
elif A == 0:
	print(0^f(B))
else:
	print(f(A-1)^f(B))

Buggy python submission (verdict: Time Limit Exceeded):
A,B = map(int,input().split())

# k = bin(A)
k = A
for i in range(A+1,B+1):
	#print(i)
	k= k^i

# print(bin(k))
print(int(k))

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

def f(x):
	if x == 0:
		return 0
	elif x%2==0:
		return int(x/2)%2 ^ x
	else:
		return int((x-1)/2)%2 ^ x-1 ^ x

if A==B:
	print(B)
elif A == 0:
	print(0^f(B))
else:
	print(f(A-1)^f(B))
Buggy python submission (verdict: Runtime Error):
n = 0
X = 0
while X<1:
	# print(L)
	K = len(L)-1
	# print(K)
	for i in range(K):
		if L[i]+L[i+1]==1:
			L.pop(i)
			L.pop(i)
			n=n+1
			break
		elif i == K-1:
			X=1

# print(L)
print(n*2)


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

print(min(int(B/A), C))
Buggy python submission (verdict: Time Limit Exceeded):
S =list(input())
L =list(map(int,S))

n = 0
X = 0
while X<1:
	# print(L)
	K = len(L)-1
	# print(K)
	for i in range(K):
		if L[i]+L[i+1]==1:
			L.pop(i)
			L.pop(i)
			n=n+1
			break
		elif i == K-1:
			X=1

# print(L)
print(n*2)

Fixed submission:
S =list(input())
L =list(map(int,S))

print(min(L.count(0),L.count(1))*2)

Buggy python submission (verdict: Runtime Error):
n = 0
X = 0
while X<1:
	# print(L)
	K = len(L)-1
	# print(K)
	for i in range(K):
		if L[i]+L[i+1]==1:
			L.pop(i)
			L.pop(i)
			n=n+1
			break
		elif i == K-1:
			X=1

# print(L)
print(n*2)


Fixed submission:
S =list(input())
L =list(map(int,S))

print(min(L.count(0),L.count(1))*2)

Buggy python submission (verdict: Time Limit Exceeded):
S =list(input())
L =list(map(int,S))

n = 0
X = 0
while X<1:
	K = len(L)-1
	for i in range(K):
		if L[i]+L[i+1]==1:
			L.pop(i)
			L.pop(i)
			n=n+1
			break
		elif i == K-1:
			X=1

print(n*2)

Fixed submission:
S =list(input())
L =list(map(int,S))

print(min(L.count(0),L.count(1))*2)

Buggy python submission (verdict: Time Limit Exceeded):
S =list(input())
L =list(map(int,S))

n = 0
X = 0
while X<1:
	# print(L)
	K = len(L)-1
	# print(K)
	for i in range(K):
		if L[i]+L[i+1]==1:
			L.pop(i)
			L.pop(i)
			n=n+1
			break
		elif i == K-1:
			X=1

# print(L)
print(n*2)

Fixed submission:
S =list(input())
L =list(map(int,S))

print(min(L.count(0),L.count(1))*2)
Buggy python submission (verdict: Time Limit Exceeded):
dp,dp2,mod = [1]+[0]*12,[0]*13,10**9+7
for i in input():
    if i=="?":
        for k in range(10):
            for j in range(13): dp2[(j*10+k)%13] = (dp2[(j*10+k)%13]+dp[j])%mod
    else:
        for j in range(13): dp2[(j*10+int(i))%13] = (dp2[(j*10+int(i))%13]+dp[j])%mod
    dp,dp2 = dp2,[0]*13
print(dp[5])

Fixed submission:
s = input()
ans,mod = [0]*13,10**9+7
if s[0]=="?": ans = [1]*10+[0]*3
else: ans[int(s[0])] = 1
for i in s[1:]:
    dp = [0]*13
    for j in range(13): dp[j*10%13] = ans[j]%mod
    dp+=dp
    if i=="?":
        for j in range(13): ans[j] = sum(dp[j+4:j+14])
    else:
        for j in range(13): ans[j] = dp[j+13-int(i)]
print(ans[5]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
dp,dp2,mod = [1]+[0]*12,[0]*13,10**9+7
for i in input():
    if i=="?":
        for k in range(10):
            for j in range(13): dp2[(j*10+k)%13]+=dp[j]
    else:
        for j in range(13): dp2[(j*10+int(i))%13]+=dp[j]
    for j in range(13): dp2[j]%=mod
    dp,dp2 = dp2,[0]*13
print(dp[5])

Fixed submission:
s = input()
ans,mod = [0]*13,10**9+7
if s[0]=="?": ans = [1]*10+[0]*3
else: ans[int(s[0])] = 1
for i in s[1:]:
    dp = [0]*13
    for j in range(13): dp[j*10%13] = ans[j]%mod
    dp+=dp
    if i=="?":
        for j in range(13): ans[j] = sum(dp[j+4:j+14])
    else:
        for j in range(13): ans[j] = dp[j+13-int(i)]
print(ans[5]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
dp,dp2,mod = [0]*13,[0]*13,10**9+7
dp[0] = 1
for i in range(len(s)):
    if s[i]=="?":
        for k in range(10):
            for j in range(13): dp2[(j*10+k)%13]+=dp[j]
    else:
        for j in range(13): dp2[(j*10+int(s[i]))%13]+=dp[j]
    for j in range(13): dp2[j]%=mod
    dp,dp2 = dp2,[0]*13
print(dp[5])

Fixed submission:
s = input()
ans,mod = [0]*13,10**9+7
if s[0]=="?": ans = [1]*10+[0]*3
else: ans[int(s[0])] = 1
for i in s[1:]:
    dp = [0]*13
    for j in range(13): dp[j*10%13] = ans[j]%mod
    dp+=dp
    if i=="?":
        for j in range(13): ans[j] = sum(dp[j+4:j+14])
    else:
        for j in range(13): ans[j] = dp[j+13-int(i)]
print(ans[5]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
dp,mod = [[0]*13 for i in range(len(s)+1)],10**9+7
dp[0][0],x = 1,[0,4,8,12,3,7,11,2,6,10,1,5,9]
for i in range(len(s)):
    if s[i]=="?":
        for k in range(10):
            for j in range(13): dp[i+1][j] = (dp[i+1][j]+dp[i][x[j-k]])%mod
    else:
        for j in range(13): dp[i+1][j] = dp[i][x[j-int(s[i])]]
print(dp[-1][5])

Fixed submission:
s = input()
ans,mod = [0]*13,10**9+7
if s[0]=="?": ans = [1]*10+[0]*3
else: ans[int(s[0])] = 1
for i in s[1:]:
    dp = [0]*13
    for j in range(13): dp[j*10%13] = ans[j]%mod
    dp+=dp
    if i=="?":
        for j in range(13): ans[j] = sum(dp[j+4:j+14])
    else:
        for j in range(13): ans[j] = dp[j+13-int(i)]
print(ans[5]%mod)
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop,heappush
n = int(input())
a = [-int(input()) for i in range(n)]
x = [a[0]]
for i in range(1,n):
    if max(x)<=a[i]:
        heappush(x,a[i])
    else:
        p = heappop(x)
        y = [p]
        while p<=a[i]:
            p = heappop(x)
            y.append(p)
        heappush(x,a[i])
        for i in range(len(y)-1): heappush(x,y[i])
print(len(x))

Fixed submission:
from bisect import bisect
n = int(input())
a = [-int(input()) for i in range(n)]
x = [a[0]]
for i in range(1,n):
    if x[-1]<=a[i]: x.append(a[i])
    else: x[bisect(x,a[i])] = a[i]
print(len(x))
Buggy python submission (verdict: Runtime Error):
n,l = (int(I) for i in input().split())
d = (l-1)*n+(n+1)*n//2
if l<1: print(d+1-l-min(n,1-l))
else: print(d-l)

Fixed submission:
n,l = (int(i) for i in input().split())
d = (l-1)*n+(n+1)*n//2
if l<1: print(d+1-l-min(n,1-l))
else: print(d-l)
Buggy python submission (verdict: Runtime Error):
a,b,c = (int(i) for i in input().split())
if (a-c)(b-c)<0: print("Yes")
else: print("No")

Fixed submission:
a,b,c = (int(i) for i in input().split())
if (a-c)*(b-c)<0: print("Yes")
else: print("No")
Buggy python submission (verdict: Runtime Error):
n,k = (int(i) for i in input().split())
s = input()
x,y,f,num,ans = [],[],1,0,0
for i in range(n):
    if f and s[i]=="1":
        f = 0
        x.append(i)
    elif 1-f and s[i]=="0":
        f,num = 1,num+1
        y.append(i-1)
if x[0]: num+=1
if int(s[-1]): y.append(n-1)
if num<=k: print(n)
else:
    if x[0]: ans = y[k-1]+1
    for i in range(len(y)-k):
        if x[i]+1: ans = max(y[i+k]-x[i]+1,ans)
        else: ans = max(y[i+k]-x[i],ans)
    print(ans)

Fixed submission:
n,k = (int(i) for i in input().split())
s = input()
x,y,f,num,ans = [],[],1,0,0
for i in range(n):
    if f and s[i]=="1":
        f = 0
        x.append(i)
    elif 1-f and s[i]=="0":
        f,num = 1,num+1
        y.append(i-1)
if x and x[0]: num+=1
if int(s[-1]): y.append(n-1)
if num<=k: print(n)
else:
    if x[0]: ans = y[k-1]+1
    if s[-1]=="0": ans = max(ans,n-x[-k])
    for i in range(len(y)-k): ans = max(y[i+k]-x[i]+1,ans)
    print(ans)