Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from numba import jit

n,k=map(int,input().split())
P=list(map(int,input().split()))
P=[p-1 for p in P]
C=list(map(int,input().split()))

@jit
def main():
  ans=-float('inf')
  for si in range(n):
    x=si
    S=[]
    tot=0
    while True:
      x=P[x]
      S.append(C[x])
      tot+=C[x]
      if x==si:
        break
    l=len(S)
    t=0
    for i in range(l):
      t+=S[i]
      if i+1>k:
        break
      now=t
      if tot>0:
        e=(k-i-1)//l
        now+=tot*e
      ans=max(ans,now)
  return ans      


print(main())

Fixed submission:
n,k=map(int,input().split())
P=list(map(int,input().split()))
P=[p-1 for p in P]
C=list(map(int,input().split()))

def main():
  ans=-float('inf')
  for si in range(n):
    x=si
    S=[]
    tot=0
    while True:
      x=P[x]
      S.append(C[x])
      tot+=C[x]
      if x==si:
        break
    l=len(S)
    t=0
    for i in range(l):
      t+=S[i]
      if i+1>k:
        break
      now=t
      if tot>0:
        e=(k-i-1)//l
        now+=tot*e
      ans=max(ans,now)
  return ans      


if __name__=='__main__':
  print(main())

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  ans=-float('inf')
  for si in range(n):
    x=si
    S=[]
    tot=0
    while True:
      x=P[x]
      S.append(C[x])
      tot+=C[x]
      if x==si:
        break
    l=len(S)
    t=0
    for i in range(l):
      t+=S[i]
      if i+1>k:
        break
      now=t
      if tot>0:
        e=(k-i-1)//l
        now+=tot*e
      ans=max(ans,now)
  return ans
        
      

n,k=map(int,input().split())
P=list(map(int,input().split()))
P=[p-1 for p in P]
C=list(map(int,input().split()))
flag=[0]*n


print(main())

Fixed submission:
n,k=map(int,input().split())
P=list(map(int,input().split()))
P=[p-1 for p in P]
C=list(map(int,input().split()))

def main():
  ans=-float('inf')
  for si in range(n):
    x=si
    S=[]
    tot=0
    while True:
      x=P[x]
      S.append(C[x])
      tot+=C[x]
      if x==si:
        break
    l=len(S)
    t=0
    for i in range(l):
      t+=S[i]
      if i+1>k:
        break
      now=t
      if tot>0:
        e=(k-i-1)//l
        now+=tot*e
      ans=max(ans,now)
  return ans      


if __name__=='__main__':
  print(main())
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
R,C,K=map(int,input().split())
vl=np.zeros((R,C), np.int64)
for _ in range(K):
  r,c,v=map(int,input().split())
  vl[r-1][c-1]=v
dp=np.zeros((R+1,C+1,4), np.int64)
for i in range(1,R+1):
  for j in range(1,C+1):
    for k in range(4):
      dp[i][j][k]=max(dp[i][j-1][k],dp[i-1][j][3])
    for k in range(3,0,-1):
      dp[i][j][k]=max(dp[i][j][k],dp[i][j][k-1]+vl[i-1][j-1])
print(dp[R][C][3])

Fixed submission:
import numpy as np
from numba import njit
R,C,K=map(int,input().split())
vl=np.zeros((R,C), np.int64)
for _ in range(K):
  r,c,v=map(int,input().split())
  vl[r-1][c-1]=v
@njit
def main():
  dp=np.zeros((R+1,C+1,4), np.int64)
  for i in range(1,R+1):
    for j in range(1,C+1):
      for k in range(4):
        dp[i][j][k]=max(dp[i][j-1][k],dp[i-1][j][3])
      for k in range(3,0,-1):
        dp[i][j][k]=max(dp[i][j][k],dp[i][j][k-1]+vl[i-1][j-1])
  return dp[R][C][3]
print(main())

Buggy python submission (verdict: Time Limit Exceeded):
R,C,K=map(int,input().split())
vl=[[0 for _c in range(C)] for _r in range(R)]
for _ in range(K):
  r,c,v=map(int,input().split())
  vl[r-1][c-1]=v
dp=[[[0 for _ in range(4)]for _ in range(C+1)]for _ in range(R+1)]
for i in range(1,R+1):
  for j in range(1,C+1):
    for k in range(4):
      dp[i][j][k]=max(dp[i][j-1][k],dp[i-1][j][3])
    for k in range(3,0,-1):
      dp[i][j][k]=max(dp[i][j][k],dp[i][j][k-1]+vl[i-1][j-1])
print(dp[R][C][3])

Fixed submission:
import numpy as np
from numba import njit
R,C,K=map(int,input().split())
vl=np.zeros((R,C), np.int64)
for _ in range(K):
  r,c,v=map(int,input().split())
  vl[r-1][c-1]=v
@njit
def main():
  dp=np.zeros((R+1,C+1,4), np.int64)
  for i in range(1,R+1):
    for j in range(1,C+1):
      for k in range(4):
        dp[i][j][k]=max(dp[i][j-1][k],dp[i-1][j][3])
      for k in range(3,0,-1):
        dp[i][j][k]=max(dp[i][j][k],dp[i][j][k-1]+vl[i-1][j-1])
  return dp[R][C][3]
print(main())
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
A=[]
for i in range(n):
  A.append(s[i])
ans=float('inf')
for i in range(n+1):
  w=A[:i].count('W')
  r=A[i:].count('R')
  ans=min(max(w,r),ans)

print(ans)   

Fixed submission:
n=int(input())
s=input()
A=[]
for i in range(n):
  A.append(s[i])
W=0
R=A.count('R')
ans=float('inf')
for i in range(n+1):
  if i!=0:
    if A[i-1]=='W':
      W+=1
    else:
      R-=1
  ans=min(max(W,R),ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
A=list(map(int,input().split()))

l=-1
r=max(A)+1
while r-l>1:
  m=(l+r)//2
  cut=0
  
  for i in range(n):
    cut+=((A[i]+m-1)//m)-1
  if cut>k:
    l=m
  else:
    r=m
print(r)
  

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

l=0
r=max(A)+1
while r-l>1:
  m=(l+r)//2
  cut=0
  
  for i in range(n):
    cut+=((A[i]+m-1)//m)-1
  if cut>k:
    l=m
  else:
    r=m
print(r)
Buggy python submission (verdict: Runtime Error):
n=input()
if n[0]=='7' or n[1]=='7' or n[2]=='7':
  print(Yes)
else:
   print('No')

Fixed submission:
n=input()
if n[0]=='7' or n[1]=='7' or n[2]=='7':
  print('Yes')
else:
   print('No')
Buggy python submission (verdict: Time Limit Exceeded):
from numba import jit

n=int(input())
s=input()
R=[]
G=[]
B=[]

@jit
def f():
  for i in range(n):
    if s[i]=="R":
      R.append(i)
    elif s[i]=="G":
      G.append(i)
    else:
      B.append(i)
  r=len(R)
  g=len(G)
  b=len(B)
  if r==0 or g==0 or b==0:
    return 0
  else:
    ans=r*g*b
    m=0
    for j in range(1,n-1):
      for k in range(1,min(j,n-1-j)+1):
        lt=s[j-k]
        md=s[j]
        rt=s[j+k]
        if lt!=md and md!=rt and rt!=lt:
          m+=1
    return ans-m
print(f())

Fixed submission:
n=int(input())
s=input()
R=[]
G=[]
B=[]
def f():
  for i in range(n):
    if s[i]=="R":
      R.append(i)
    elif s[i]=="G":
      G.append(i)
    else:
      B.append(i)
  r=len(R)
  g=len(G)
  b=len(B)
  if r==0 or g==0 or b==0:
    return 0
  else:
    ans=r*g*b
    m=0
    for j in range(1,n-1):
      for k in range(1,min(j,n-1-j)+1):
        lt=s[j-k]
        md=s[j]
        rt=s[j+k]
        if lt!=md and md!=rt and rt!=lt:
          m+=1
    return ans-m
print(f())
Buggy python submission (verdict: Runtime Error):
k=int(input())
L=[]
def f(d,now,L):
  L.append(now)
  
  if d==10:
    return
  
  for j in range(-1,2):
    v=now%10+j
    if 0<=v<=9:
      f(d+1,now*10+v,L)

f(0,0,L)
print(L[k-1])
      

Fixed submission:
k=int(input())
L=[]
def f(d,now,L):
  L.append(now)
  
  if d==10:
    return
  
  for j in range(-1,2):
    v=now%10+j
    if 0<=v<=9:
      f(d+1,now*10+v,L)

for l in range(1,10):
  f(1,l,L)
L.sort()
print(L[k-1])
Buggy python submission (verdict: Runtime Error):
r = input()
print(r**2)

Fixed submission:
r = int(input())
print(r**2)

Buggy python submission (verdict: Runtime Error):
print(r**2)

Fixed submission:
r = int(input())
print(r**2)
Buggy python submission (verdict: Runtime Error):
int(input())=n
input()=s
if s[0;n//2-1] == s[n//2;n-1]:
  print('Yes')
else:
  print('No')

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

if n%2:
  print('No')
else:
  if s[:n//2]==s[n//2:]:
    print('Yes')
  else:
    print('No')

Buggy python submission (verdict: Runtime Error):
n = int(input)
s = input()
if s[0;n//2-1] ==s[n//2;n-1]:
  print('Yes')
else:
  print('No')

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

if n%2:
  print('No')
else:
  if s[:n//2]==s[n//2:]:
    print('Yes')
  else:
    print('No')

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
if n % 2 = 0 and s[0 , n//2 - 1] =s[n//2 , n - 1]:
  print('Yes')
 else:
  print('No')


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

if n%2:
  print('No')
else:
  if s[:n//2]==s[n//2:]:
    print('Yes')
  else:
    print('No')
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=[0]*100
for i in range(1,10):
  for j in range(1,10):
    s[10*i+j]=i*j
p=81
for k in range(1,101):
  if s[k]==n:
    p=p-1
if p==81:
  print('No')
else:
  print('Yes')


Fixed submission:
n=int(input())
s=[0]*100
for i in range(1,10):
  for j in range(1,10):
    s[10*i+j]=i*j
p=81
for k in range(0,100):
  if s[k]==n:
    p=p-1
if p==81:
  print('No')
else:
  print('Yes')
Buggy python submission (verdict: Runtime Error):
N = int(input())
n = int((N**(1/2))//1)
s =[0]*n
for i in range(1,n+1):
  if N//i == 0:
    s[i] = i
maxs = s[0]
for j in range(1,n+1):
  if s[j] > maxs:
    maxs = s[j]
p = int(N/maxs)
walk = p + maxs - 2
print(walk)


Fixed submission:
N = int(input())
n = int((N**(1/2))//1)
s =[0]*(n+10)
for i in range(1,n+1):
  if N%i == 0:
    s[i] = i
maxs = s[0]
for j in range(1,n+1):
  if s[j] > maxs:
    maxs = s[j]
p = int(N/maxs)
walk = p + maxs - 2
print(walk)
Buggy python submission (verdict: Runtime Error):
a,b=int(input()).split()
c = 2*a-b
if c >=0:
  print(c)
else:
  print(0)

Fixed submission:
a,b =(int(x) for x in input().split())
c=a-b*2
if c>=0:
  print(c)
else:
  print(0)

Buggy python submission (verdict: Runtime Error):
int(input()) = A
int(input()) = B
c =2*A-B
if c>=0:
  print(c)
else:
  print(0)

Fixed submission:
a,b =(int(x) for x in input().split())
c=a-b*2
if c>=0:
  print(c)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
N =int(input())
s = [int(x) for x in range(0,N)]
for i in range(0,N):
  for j in range(i+1,N):
    m = [int(s[i]*s[j])]
leng = len(m)
sum = 0
for k in range(0,leng):
  sum = sum + m[k]
 print(sum)

  


Fixed submission:
from itertools import combinations

n=int(input())
D=list(map(int,input().split()))

ans=0
for a,b in combinations(range(n),2):
  ans+=D[a]*D[b]
  
print(ans)
Buggy python submission (verdict: Runtime Error):
a = input()
b = input()
for i in range(0,3):
  if a[i] == 'S':
    a[i] = '1'
  elif a[i] == 'C':
    a[i] = '2'
  else:
    a[i] = '3'
for j in range(0,3):
  if b[j] == 'S':
    b[j] = '1'
  elif b[j] == 'C':
    b[j] = '2'
  else:
    b[j] = '3'
out = 0
for k in range(0,3):
  if int(a[k])-int(b[k]) == 0:
    out = out + 1
print(out)


Fixed submission:
a = input()
b = input()
out=0
for i in range(0,3):
  if a[i] ==b[i]:
    out =out+1
print(out)

Buggy python submission (verdict: Runtime Error):
a = input()
b = input()
for i in range(0,3):
  if a[i] == 'S':
    a[i] = '1'
  elif a[i] == 'C':
    a[i] = '2'
  else:
    a[i] = '3'
for j in range(0,3):
  if b[j] == 'S':
    b[j] = '1'
  elif b[j] == 'C':
    b[j] = '2'
  else:
    b[j] = '3'
out = 0
for k in range(0,3):
  if int(a[k]-b[k]) == 0:
    out = out + 1
print(out)

Fixed submission:
a = input()
b = input()
out=0
for i in range(0,3):
  if a[i] ==b[i]:
    out =out+1
print(out)
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
V=list(map(int,input().split()))
if N<=K:
  W=sorted(V)
  h=sum(V)
  for i in range(K-N):
    if W[i]<0:
      h-=W[i]
    else:
      break
else:
  ans=[]
  for i in range(1,K):
    for j in range(i+1):
      l=V[0:i-j]+V[N-j:N]
      l.sort()
      H=sum(l)
      for k in range(min(i,K-i)):
        if l[k]<0:
          H-=l[k]
        else:
          break
      ans.append(H)
  h=max(ans)
print(h)

Fixed submission:
N,K=map(int,input().split())
V=list(map(int,input().split()))
if N<=K:
  W=sorted(V)
  h=sum(V)
  for i in range(K-N):
    if W[i]<0:
      h-=W[i]
    else:
      break
else:
  ans=[]
  for i in range(1,K+1):
    for j in range(i+1):
      l=V[0:i-j]+V[N-j:N]
      l.sort()
      H=sum(l)
      for k in range(min(i,K-i)):
        if l[k]<0:
          H-=l[k]
        else:
          break
      ans.append(H)
  h=max(ans)
print(h)

Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
V=list(map(int,input().split()))
if N<=K:
  W=sorted(V)
  h=sum(V)
  for i in range(K-N):
    a=W[i]
    if a<0:
      h-=a
    elif a>0:
      break
else:
  ans=[]
  for i in range(1,K):
    for j in range(i+1):
      l=V[0:i-j]+V[N-j:N]
      l.sort()
      H=sum(l)
      for k in range(min(i,K-i)):
        if l[k]<0:
          H-=l[k]
        elif l[k]>0:
          break
      ans.append(H)
  h=max(ans)
print(h)

Fixed submission:
N,K=map(int,input().split())
V=list(map(int,input().split()))
if N<=K:
  W=sorted(V)
  h=sum(V)
  for i in range(K-N):
    if W[i]<0:
      h-=W[i]
    else:
      break
else:
  ans=[]
  for i in range(1,K+1):
    for j in range(i+1):
      l=V[0:i-j]+V[N-j:N]
      l.sort()
      H=sum(l)
      for k in range(min(i,K-i)):
        if l[k]<0:
          H-=l[k]
        else:
          break
      ans.append(H)
  h=max(ans)
print(h)
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
LR=[]
for i in range(M):
  LR.append(list(map(int,input().split())))
ans=[i+1 for i in range(N)]
for i in range(M):
  for j in range(LR[i][0]):
    if j in ans:
      ans.remove(j)
  for k in range(LR[i][1]+1,N+1):
    if k in ans:
      ans.remove(k)
print(len(ans))

Fixed submission:
N,M=map(int,input().split())
LR=[]
for i in range(M):
  LR.append(list(map(int,input().split())))
l,r=LR[0][0],LR[0][1]
for i in range(M):
  if LR[i][1]<=r:
    r=LR[i][1]
  if l<=LR[i][0]:
    l=LR[i][0]
ans=r-l+1
if ans>0:
  print(ans)
else:
  print(0)
Buggy python submission (verdict: Time Limit Exceeded):
Q=int(input())
q=[]
a=[]
b=0
n=0
def dist(A,x,n):
  ret=0
  for i in range(n):
    ret+=abs(A[i]-x)
  return ret
for i in range(Q):
  q.append(list(map(int,input().split())))
  if q[i][0]==2:
    if len(a)%2==0:
      x=a[len(a)//2-1]
      fx=dist(a,x,n)+b
      print(x,fx)
    else:
      x=a[len(a)//2]
      fx=dist(a,x,n)+b
      print(x,fx)
  else:
    n+=1
    a.append(q[i][1])
    b+=q[i][2]
    a.sort()

Fixed submission:
import heapq
q=int(input())
L=[]
R=[]
heapq.heapify(L)
heapq.heapify(R)
fx=0
for i in range(q):
  Q=list(map(int,input().split()))
  if Q[0]==1:
    a,b=Q[1],Q[2]
    heapq.heappush(L,-a)
    heapq.heappush(R,a)
    l=-heapq.heappop(L)
    r=heapq.heappop(R)
    if l==a and r==a:
      heapq.heappush(L,-l)
      heapq.heappush(R,r)
    else:
      fx+=abs(r-l)
      heapq.heappush(L,-r)
      heapq.heappush(R,l)
    x=-L[0]
    fx+=b
  else:
    print(x,fx)

Buggy python submission (verdict: Time Limit Exceeded):
Q=int(input())
q=[]
a=[]
b=0
def dist(A,x):
  ret=0
  for i in range(len(A)):
    ret+=abs(A[i]-x)
  return ret
for i in range(Q):
  q.append(list(map(int,input().split())))
  if q[i][0]==2:
    if len(a)%2==0:
      x=a[len(a)//2-1]
      fx=dist(a,x)+b
      print(x,fx)
    else:
      x=a[len(a)//2]
      fx=dist(a,x)+b
      print(x,fx)
  else:
    a.append(q[i][1])
    b+=q[i][2]
    a.sort()

Fixed submission:
import heapq
q=int(input())
L=[]
R=[]
heapq.heapify(L)
heapq.heapify(R)
fx=0
for i in range(q):
  Q=list(map(int,input().split()))
  if Q[0]==1:
    a,b=Q[1],Q[2]
    heapq.heappush(L,-a)
    heapq.heappush(R,a)
    l=-heapq.heappop(L)
    r=heapq.heappop(R)
    if l==a and r==a:
      heapq.heappush(L,-l)
      heapq.heappush(R,r)
    else:
      fx+=abs(r-l)
      heapq.heappush(L,-r)
      heapq.heappush(R,l)
    x=-L[0]
    fx+=b
  else:
    print(x,fx)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B,C=[],[]
for i in range(N):
  if A[i]>=0:
    B.append(A[i])
  else:
    C.append(-A[i])
if len(C)%2==0:
  ans=sum(B)+sum(C)
else:
  ans=sum(B)+sum(C)
  B.sort()
  C.sort()
  a=min(B[0],C[0])
  ans-=2*a
print(ans)



Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B,C=[],[]
for i in range(N):
  if A[i]>=0:
    B.append(A[i])
  else:
    C.append(-A[i])
if len(C)%2==0:
  ans=sum(B)+sum(C)
else:
  ans=sum(B)+sum(C)
  B.sort()
  C.sort()
  if len(B)==0:
    b=10**12
  else:
    b=B[0]
  a=min(b,C[0])
  ans-=2*a
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
s0=''
s1=''
n=len(S)
for i in range(n):
  if i%2==0:
    s0+='0'
    s1+='1'
  else:
    s0+='1'
    s1+='0'
is0=bin(int(s0,2)^int(S,2))[2:]
is1=bin(int(s1,2)^int(S,2))[2:]
lis0=[]
lis1=[]
for i in range(len(is0)):
  lis0.append(is0[i])
for i in range(len(is1)):
  lis1.append(is1[i])
while '0' in lis0:
  lis0.remove('0')
while '0' in lis1:
  lis1.remove('0')
print(min(len(lis0),len(lis1)))

Fixed submission:
S=input()
c0=0
c1=0
for i in range(len(S)):
  if i%2==0:
    if S[i]=='0':
      c0+=1
  else:
    if S[i]=='1':
      c0+=1
for i in range(len(S)):
  if i%2==0:
    if S[i]=='1':
      c1+=1
  else:
    if S[i]=='0':
      c1+=1
print(min(c0,c1))
Buggy python submission (verdict: Runtime Error):
import heapq
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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
Q=[[-A[0]-B[0]-C[0],0,0,0]]
heapq.heapify(Q)
ans=[]
ijk={(0,0,0)}
while len(ans)<=K:
  abc,i,j,k=heapq.heappop(Q)
  if i+1<X and  not (i+1,j,k) in ijk:
    ijk.add((i+1,j,k))
    heapq.heappush(Q,[-A[i+1]-B[j]-C[k],i+1,j,k])
  if j+1<Y and  not (i,j+1,k) in ijk:
    ijk.add((i,j+1,k))
    heapq.heappush(Q,[-A[i]-B[j+1]-C[k],i,j+1,k])
  if k+1<Z and  not (i,j,k+1) in ijk:
    ijk.add((i,j,k+1))
    heapq.heappush(Q,[-A[i]-B[j]-C[k+1],i,j,k+1])
  ans.append(-abc)
for i in ans:
  print(i)

Fixed submission:
import heapq
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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
Q=[[-A[0]-B[0]-C[0],0,0,0]]
heapq.heapify(Q)
ans=[]
ijk={(0,0,0)}
while len(ans)<K:
  abc,i,j,k=heapq.heappop(Q)
  if i+1<X and  not (i+1,j,k) in ijk:
    ijk.add((i+1,j,k))
    heapq.heappush(Q,[-A[i+1]-B[j]-C[k],i+1,j,k])
  if j+1<Y and  not (i,j+1,k) in ijk:
    ijk.add((i,j+1,k))
    heapq.heappush(Q,[-A[i]-B[j+1]-C[k],i,j+1,k])
  if k+1<Z and  not (i,j,k+1) in ijk:
    ijk.add((i,j,k+1))
    heapq.heappush(Q,[-A[i]-B[j]-C[k+1],i,j,k+1])
  ans.append(-abc)
for i in ans:
  print(i)
Buggy python submission (verdict: Runtime Error):
import math
A,B=map(int,input().split())
a=int(math.log(A,2))+1
b=int(math.log(B,2))
if a>=b:
  ans=0
  for i in range(A,B+1):
    ans^=i
else:
  ans=0
  for i in range(A,2**a):
    ans^=i
  for j in range(2**b,B+1):
    ans^=j
print(ans)

Fixed submission:
A,B=map(int,input().split())
def f(X):
  if X%4==0:
    return X
  elif X%4==1:
    return 1
  elif X%4==2:
    return 1^X
  elif X%4==3:
    return 0
if A==0:
  ans=f(B)
else:
  ans=f(A-1)^f(B)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S=str(input())
s=[]
c1=0
c0=0
for i in range(len(S)):
  s.append(S[i])
  if S[i]=='0':
    c0+=1
  else:
    c1+=1
c=0
while min(c0,c1)>0:
  for i in range(len(s)-1):
    if s[i:i+2]==['1','0'] or s[i:i+2]==['0','1']:
      c0-=1
      c1-=1
      s.remove(s[i])
      s.remove(s[i])
      c+=1
      break
print(2*c)

Fixed submission:
S=str(input())
s=[]
c1=0
c0=0
for i in range(len(S)):
  s.append(S[i])
  if S[i]=='0':
    c0+=1
  else:
    c1+=1
print(2*min(c0,c1))

Buggy python submission (verdict: Time Limit Exceeded):
S=str(input())
s=[]
for i in range(len(S)):
  s.append(S[i])
c=0
f=True
while f:
  if s==['1']*len(s) or s==['0']*len(s) or s==[]:
    f=False
  else:
    for i in range(len(s)-1):
      if s[i:i+2]==['0','1'] or s[i:i+2]==['1','0']:
        s.remove(s[i])
        s.remove(s[i])
        c+=1
        break
print(2*c)

Fixed submission:
S=str(input())
s=[]
c1=0
c0=0
for i in range(len(S)):
  s.append(S[i])
  if S[i]=='0':
    c0+=1
  else:
    c1+=1
print(2*min(c0,c1))

Buggy python submission (verdict: Time Limit Exceeded):
S=str(input())
s=[]
for i in range(len(S)):
  s.append(S[i])
c=0
f=True
while f:
  if s==['1']*len(s) or s==['0']*len(s):
    f=False
  else:
    for i in range(len(s)-1):
      if s[i:i+2]==['0','1'] or s[i:i+2]==['1','0']:
        s.remove(s[i])
        s.remove(s[i])
        c+=1
        break
print(2*c)

Fixed submission:
S=str(input())
s=[]
c1=0
c0=0
for i in range(len(S)):
  s.append(S[i])
  if S[i]=='0':
    c0+=1
  else:
    c1+=1
print(2*min(c0,c1))
Buggy python submission (verdict: Runtime Error):
import heapq
INF=float('inf')

n,m=map(int,input().split())
adj=[[] for _ in range(n+1)]
for _ in range(m):
  x,y=map(int,input().split())
  adj[x].append(y)
  
dp=[-1 for _ in range(n+1)]

def f(k):
  if dp[k]!=-1:
    return dp[k]
  
  dp[k]=0
  if adj[k]:
    for v in adj[k]:
      dp[k]=max(dp[k],f(v)+1)
  return dp[k]

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

ans=-INF  
for i in range(1,n+1):
  ans=max(ans,f(i))

print(ans)



Fixed submission:
import sys

sys.setrecursionlimit(10**9)
INF=float('inf')

n,m=map(int,input().split())
adj=[[] for _ in range(n+1)]
for _ in range(m):
  x,y=map(int,input().split())
  adj[x].append(y)
  
dp=[-1 for _ in range(n+1)]

def f(k):
  if dp[k]!=-1:
    return dp[k]
  
  dp[k]=0
  if adj[k]:
    for v in adj[k]:
      dp[k]=max(dp[k],f(v)+1)
  return dp[k]

ans=-INF  
for i in range(1,n+1):
  ans=max(ans,f(i))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
INF=float('inf')

n,m=map(int,input().split())
adj=[[] for _ in range(n)]
for _ in range(m):
  x,y=map(int,input().split())
  x-=1
  y-=1
  adj[x].append(y)

ans=-INF
for i in range(n):
  dist=[-INF for _ in range(n)]
  Q=[(0,i)]
  dist[i]=0
  heapq.heapify(Q)
  while Q:
    d,v=heapq.heappop(Q)
    for nv in adj[v]:
      if dist[nv]<dist[v]+1:
        dist[nv]=dist[v]+1
        heapq.heappush(Q,(dist[nv],nv))
  ans=max(ans,max(dist))
  
print(ans)

Fixed submission:
import sys

sys.setrecursionlimit(10**9)
INF=float('inf')

n,m=map(int,input().split())
adj=[[] for _ in range(n+1)]
for _ in range(m):
  x,y=map(int,input().split())
  adj[x].append(y)
  
dp=[-1 for _ in range(n+1)]

def f(k):
  if dp[k]!=-1:
    return dp[k]
  
  dp[k]=0
  if adj[k]:
    for v in adj[k]:
      dp[k]=max(dp[k],f(v)+1)
  return dp[k]

ans=-INF  
for i in range(1,n+1):
  ans=max(ans,f(i))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
INF=float('inf')
import numpy as np

n=int(input())
P=list(map(float,input().split()))#0

dp=np.zeros([n+1,n+1], dtype='float128')

for i in range(n+1):
  if i==0:
    dp[0][0]=1
  else:
    dp[i][0]=(1-P[i-1])*dp[i-1][0]

    
for j in range(1,n+1):
  for i in range(1,n+1):
    if i<j:
      continue
    dp[i][j]=P[i-1]*(dp[i-1][j-1])+(1-P[i-1])*(dp[i-1][j])

ans=0
for i in range(1,n+1):
  if i>=(n+1)//2:
    ans+=dp[n][i]
    
print(ans)

Fixed submission:
INF=float('inf')

n=int(input())
P=list(map(float,input().split()))#0

dp=[[0 for i in range(n+1)] for j in range(n+1)]

for i in range(n+1):
  if i==0:
    dp[0][0]=1
  else:
    dp[i][0]=(1-P[i-1])*dp[i-1][0]

    
for j in range(1,n+1):
  for i in range(1,n+1):
    if i<j:
      continue
    dp[i][j]=P[i-1]*(dp[i-1][j-1])+(1-P[i-1])*(dp[i-1][j])

ans=0
for i in range(1,n+1):
  if i>=(n+1)//2:
    ans+=dp[n][i]
    
print(ans)

Buggy python submission (verdict: Runtime Error):
INF=float('inf')
import numpy as np

n=int(input())
P=list(map(float,input().split()))#0

dp=np.zeros([n+1,n+1], dtype='float128')

for i in range(n+1):
  if i==0:
    dp[0][0]=1
  else:
    dp[i][0]=(1-P[i-1])*dp[i-1][0]

    
for j in range(1,n+1):
  for i in range(1,n+1):
    if i<j:
      continue
    dp[i][j]=P[i-1]*(dp[i-1][j-1])+(1-P[i-1])*(dp[i-1][j])

ans=0
for i in range(1,n+1):
  if i>=(n+1)//2:
    ans+=dp[n][i]
    
print(ans)

Fixed submission:
INF=float('inf')

n=int(input())
P=list(map(float,input().split()))#0

dp=[[0 for i in range(n+1)] for j in range(n+1)]

for i in range(n+1):
  if i==0:
    dp[0][0]=1
  else:
    dp[i][0]=(1-P[i-1])*dp[i-1][0]

    
for j in range(1,n+1):
  for i in range(1,n+1):
    if i<j:
      continue
    dp[i][j]=P[i-1]*(dp[i-1][j-1])+(1-P[i-1])*(dp[i-1][j])

ans=0
for i in range(1,n+1):
  if i>=(n+1)//2:
    ans+=dp[n][i]
    
print(ans)