qyliang/CodeNanoFix huggingface dataset:
Buggy code:
 = list(input())
count = 0
n = len(s)
if n % 2 == 0:
    for i in range(0,int((n/2)-1)):
        if s[(2*i)+1] == "0":
            count = count + 1
    for i in range(0,int((n/2)-1)):
        if s[2*i] == "1":
            count = count + 1
else:
    for i in range(0,int((n-1)/2)):
        if s[2*i] == "0":
            count = count + 1
    for i in range(0,int(((n-1)/2)-1)):
        if s[2*i + 1] == "1":
            count = count + 1
count2 = n - count
print(min(count,count2))

Fixed code:
s = list(input())
count = 0
n = len(s)
if n % 2 == 0:
    for i in range(0,int(n/2)):
        if s[(2*i)+1] == "0":
            count = count + 1
    for j in range(0,int(n/2)):
        if s[2*j] == "1":
            count = count + 1
else:
    for i in range(0,int((n-1)/2)+1):
        if s[2*i] == "0":
            count = count + 1
    for j in range(0,int(((n-1)/2))):
        if s[2*j + 1] == "1":
            count = count + 1
count2 = n - count
print(min(count,count2))
Buggy code:
S = input()
cnt = [[0,0],[0,0]]
for i, s in enumerate(S):
    x = int(i) % 2
    y = int(s)
    cnt[x][y] += 1
print(cnt)
if cnt[0][0] >= cnt[1][0]:
    print(cnt[0][1] + cnt[1][0])
else:
    print(cnt[0][0] + cnt[1][1])

Fixed code:
S = input()
cnt = [[0,0],[0,0]]
for i, s in enumerate(S):
    x = int(i) % 2
    y = int(s)
    cnt[x][y] += 1
if cnt[0][0] > cnt[1][0]:
    print(cnt[0][1] + cnt[1][0])
else:
    print(cnt[0][0] + cnt[1][1])
Buggy code:

#input S
S=input()

count=0
l=len(S)

for i in range(1,len(S)):
    iS=int(S[i])
    if S[i]==S[i-1]:
        if S[i]=='0':
            S=S[:i-1]+'1'+S[i:]
        else:
            S=S[:i-1]+'0'+S[i:]
        count=count+1

print(count)



Fixed code:

#input S
S=input()

count=0
for i in range(1,len(S)):
    if S[i]==S[i-1]:
        if S[i]=='0':
            S=S[:i]+'1'+S[i+1:]
        else:
            S=S[:i]+'0'+S[i+1:]
        count=count+1

print(count)
Buggy code:
from collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

S = input()[:-1]
N = len(S)
if len(S) == -1:
    C1 = Counter(S[::2])
    C2 = Counter(S[1::2])

    odd = C1['0']+C2['1']
    even = C1['1']+C2['0']
    print(N-max(odd, even))
else:
    print(0)


Fixed code:
from collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

S = input()[:-1]
N = len(S)
if len(S) != 1:
    C1 = Counter(S[::2])
    C2 = Counter(S[1::2])

    odd = C1['0']+C2['1']
    even = C1['1']+C2['0']
    print(N-max(odd, even))
else:
    print(0)
Buggy code:
#!/usr/bin/env python3

import re

a = input()

preans1 = 0
preans2 = 0
if(a[0] == "0"):
    for i in range(1,len(a)):
        if(i%2 == 0):
            if(a[i] != "1"):
                preans1 += 1
        elif(i%2 == 1):
            if(a[i] != "0"):
                preans1 += 1
    if(a[-1] == "1"):
        for i in range(2,len(a)+1):
            if(i%2 == 0):
                if(a[-i] != "0"):
                    preans2 += 1
            elif(i%2 == 1):
                if(a[-i] != "1"):
                    preans2 += 1
elif(a[0] == "1"):
    for i in range(1,len(a)):
        if(i%2 == 1):
            if(a[i] != "0"):
                preans1 += 1
        elif(i%2 == 0):
            if(a[i] != "1"):
                preans1 += 1
    if(a[-1] == "0"):
        for i in range(2,len(a)+1):
            if(i%2 == 0):
                if(a[-i] != "1"):
                    preans2 += 1
            elif(i%2 == 1):
                if(a[-i] != "0"):
                    preans2 += 1
print(min(preans1,preans2))

Fixed code:
#!/usr/bin/env python3

import re

a = input()

preans1 = 0
preans2 = 1000000
if(a[0] == "0"):
    for i in range(len(a)):
        if(i%2 == 0):
            if(a[i] != "0"):
                preans1 += 1
        elif(i%2 == 1):
            if(a[i] != "1"):
                preans1 += 1
    if(a[-1] == "1"):
        preans2 = 0
        for i in range(2,len(a)+1):
            if(i%2 == 0):
                if(a[-i] != "0"):
                    preans2 += 1
            elif(i%2 == 1):
                if(a[-i] != "1"):
                    preans2 += 1
elif(a[0] == "1"):
    for i in range(len(a)):
        if(i%2 == 1):
            if(a[i] != "0"):
                preans1 += 1
        elif(i%2 == 0):
            if(a[i] != "1"):
                preans1 += 1
    if(a[-1] == "0"):
        preans2 = 0
        for i in range(2,len(a)+1):
            if(i%2 == 0):
                if(a[-i] != "1"):
                    preans2 += 1
            elif(i%2 == 1):
                if(a[-i] != "0"):
                    preans2 += 1
print(min(preans1,preans2))
Buggy code:
S = list(str(input()))

ans = 0
last_str = ''
for s in S:
  if last_str == '':
    last_str = s
  elif (last_str == s) and s == '0':
    ans += 1
    last_str = '1'
  elif (last_str == s) and s == '1':
    ans += 1
    last_str = '0'
  else:
    pass
print(ans)

Fixed code:
S = list(str(input()))

ans = 0
last_str = ''
for s in S:
  if (last_str == s) and s == '0':
    ans += 1
    last_str = '1'
  elif (last_str == s) and s == '1':
    ans += 1
    last_str = '0'
  else:
    last_str = s
print(ans)
Buggy code:
S = '0b' + input()
s1 = '0b' + '10' * (len(S) // 2) + '1' * (len(S) % 2)
s2 = '0b' + '01' * (len(S) // 2) + '0' * (len(S) % 2)
Ss1 = bin(int(S, 2) ^ int(s1, 2))[2:]
Ss2 = bin(int(S, 2) ^ int(s2, 2))[2:]
print(min(sum([1 for x in Ss1 if int(x)]), sum([1 for x in Ss2 if int(x)])))

Fixed code:
S = '0b' + input()
s1 = '0b' + '10' * (len(S) // 2 - 1) + '1' * (len(S) % 2)
s2 = '0b' + '01' * (len(S) // 2 - 1) + '0' * (len(S) % 2)
Ss1 = bin(int(S, 2) ^ int(s1, 2))[2:]
Ss2 = bin(int(S, 2) ^ int(s2, 2))[2:]
print(min(sum([1 for x in Ss1 if int(x)]), sum([1 for x in Ss2 if int(x)])))
Buggy code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
S=input()

a=[S[::2].count(l) for l in "01"]
b=[S[1:][::2].count(k) for k in "01"]

print(a,b)
print(min(a[0]+b[1],a[1]+b[0]))

Fixed code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
S=input()

a=[S[::2].count(l) for l in "01"]
b=[S[1:][::2].count(k) for k in "01"]

print(min(a[0]+b[1],a[1]+b[0]))
Buggy code:
s = input()
cnt, cnt_ = 0, 0
a = "10" * (len(s)//2+1)
print(a)
for i in range(len(s)):
    if s[i] != a[i]:
        cnt += 1
    if s[i] != a[i + 1]:
        cnt_ += 1
print(min(cnt, cnt_))

Fixed code:
s = input()
cnt, cnt_ = 0, 0
a = "10" * (len(s)//2+1)
for i in range(len(s)):
    if s[i] != a[i]:
        cnt += 1
    if s[i] != a[i + 1]:
        cnt_ += 1
print(min(cnt, cnt_))
Buggy code:
S = list(input())
S1 = []
S2 = []
if i in range(len(S)):
    if i % 2 ==0 :
        S1.append('0')
        S2.append('0')
    else :
        S1.append('1')
        S2.append('2')
min1 = 0
for i in range(len(S)):
    if S[i] != S1[i]:
        min1 += 1
min2 = 0
for i in range(len(S)):
    if S[i] != S1[i]:
        min2 += 1 
print(min(min1,min2))

Fixed code:
S = input()
S1 = ''
S2 = ''
for i in range(len(S)):
    if i % 2 ==0 :
        S1 += '0'
        S2 += '1'
    else :
        S1 += '1'
        S2 += '0'
min1 = 0
for i in range(len(S)):
    if S[i] != S1[i]:
        min1 += 1
min2 = 0
for i in range(len(S)):
    if S[i] != S2[i]:
        min2 += 1 
print(min(min1,min2))
Buggy code:
s = input()
n = len(s)
zero = ""
one = ""
for i in range(n):
  if i%2 == 0:
    zero += "0"
    one += "1"
  else:
    zero += "1"
    one += "0"
z = 0
o = 0
for i in range(n):
  tmp = s[i]
  if tmp != zero[i]:
    z += 1
  if tmp != one[i]:
    o += 1
if z < o:
  print(z)
else:
  print(0)


Fixed code:
s = input()
n = len(s)
zero = ""
one = ""
for i in range(n):
  if i%2 == 0:
    zero += "0"
    one += "1"
  else:
    zero += "1"
    one += "0"
z = 0
o = 0
for i in range(n):
  tmp = s[i]
  if tmp != zero[i]:
    z += 1
  if tmp != one[i]:
    o += 1
if z < o:
  print(z)
else:
  print(o)
Buggy code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n = str(input())
print(n)
l1 = []
for c in n:
	l1.append(c)

z, o = '0', '1'

one, zero = [], []

for i in range(len(l1)):
	if i%2 == 0:
		one.append(o)
		zero.append(z)
	else:
		one.append(z)
		zero.append(o)

c1, c2 = 0,0
for i in range(len(l1)):
	if l[i] == one[i]:
		c1 += 1
	if l[i] == zero[i]:
		c2 += 1

ans = min(c1, c2)
print(ans)

Fixed code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n = str(input())
l1 = []
for c in n:
	l1.append(c)

z, o = '0', '1'

one, zero = [], []

for i in range(len(l1)):
	if i%2 == 0:
		one.append(o)
		zero.append(z)
	else:
		one.append(z)
		zero.append(o)

c1, c2 = 0,0
for i in range(len(l1)):
	if l1[i] == one[i]:
		c1 += 1
	if l1[i] == zero[i]:
		c2 += 1

ans = min(c1, c2)
print(ans)
Buggy code:
def f(s,a):
    ans=0
    for i in range(len(s)):
        if i%2==0:
            if s[i]!=a:
                ans+=1
                print(1)
        else:
            if s[i]==a:
                ans+=1
    return ans


s=list(input())
print(min(f(s,'0'),f(s,'1')))

Fixed code:
def f(s,a):
    ans=0
    for i in range(len(s)):
        if i%2==0:
            if s[i]!=a:
                ans+=1
        else:
            if s[i]==a:
                ans+=1
    return ans


s=list(input())
print(min(f(s,'0'),f(s,'1')))
Buggy code:
a = input()
x = 0
y = 0
for t in range(0,len(a)):
    if t%2 == 0 and a[t] == "1":
        x = x+1
    if a[t] == "0" and t%2 == 0:
        x = x+1
        
for t in range(0,len(a)):
    if t%2 == 0 and a[t] == "0":
        y = y+1
    if  t%2 == 1 and a[t] == "1":
        y= y+1
        
print (min(y,x))
    
        
        
        
        

Fixed code:
a = input()
x = 0
y = 0
for t in range(0,len(a)):
    if t%2 == 0 and a[t] == "1":
        x = x+1
    if a[t] == "0" and t%2 == 1:
        x = x+1
        
for t in range(0,len(a)):
    if t%2 == 0 and a[t] == "0":
        y = y+1
    if  t%2 == 1 and a[t] == "1":
        y= y+1
        
print (min(y,x))
Buggy code:
s = raw_input()
n = len(s)
a = 0
b = 0
for i in range(n):
	if ((i%2 == 0) and (s[i] == '0')):
		a += 1
	if ((i%2 == 1) and (s[i] == '1')):
		a += 1
	if ((i%2 == 0) and (s[i] == '1')):
		b += 1
	if ((i%2 == 1) and (s[i] == '0')):
		b += 1
print(min(a,b))


Fixed code:
s = input()
n = len(s)
a = 0
b = 0
for i in range(n):
	if ((i%2 == 0) and (s[i] == '0')):
		a += 1
	if ((i%2 == 1) and (s[i] == '1')):
		a += 1
	if ((i%2 == 0) and (s[i] == '1')):
		b += 1
	if ((i%2 == 1) and (s[i] == '0')):
		b += 1
print(min(a,b))
Buggy code:
s = str(input())
c1 = 0
c2 = 0
x = 1
def hen(n):
  if n == 1:
    return 0
  else:
    return 1
for i in range(len(s)):
  si = int(s[i])
  if si == x:
    c1 += 1
  else:
    c2 + = 1
  x = hen(x)
print(min(c1,c2))

Fixed code:
s = str(input())
c1 = 0
c2 = 0
x = 1
def hen(n):
  if n == 1:
    return 0
  else:
    return 1
for i in range(len(s)):
  si = int(s[i])
  if si == x:
    c1 += 1
  else:
    c2 += 1
  x = hen(x)
print(min(c1,c2))
Buggy code:
s = input()
x = [s[j] for j in range(0,len(s10))]
x.insert(0,'2')
count = 0
for j in range(1,len(x)):
    if x[j] == '0' and x[j] == x[j-1]:
        x[j] = '1'
        count = count + 1
    elif x[j] == '1' and x[j] == x[j-1]:
        x[j] = '0' 
        count = count + 1
print(count)


Fixed code:
s = input()
x = [s[j] for j in range(0,len(s))]
x.insert(0,'2')
count = 0
for j in range(1,len(x)):
    if x[j] == '0' and x[j] == x[j-1]:
        x[j] = '1'
        count = count + 1
    elif x[j] == '1' and x[j] == x[j-1]:
        x[j] = '0' 
        count = count + 1
print(count)
Buggy code:
s=input()
print(min(s[::2].count("1")+s[1::2].count("0"),s[::2].count("0")+s[::1].count("0")))

Fixed code:
s=input()
print(min(s[::2].count("1")+s[1::2].count("0"),s[::2].count("0")+s[1::2].count("1")))
Buggy code:
s=input()
n=len(s)
s = bin(int(s, 2))
s_10 = '1' * (n % 2) + '01' * (n // 2)
s_01 = '0' * (n % 2) + '10' * (n // 2)
s_10 = bin(int(s_10, 2))
s_01 = bin(int(s_01, 2))
r = s ^ s_01
l = s ^ s_10
print(min(r.count('1'), l.count('1')))

Fixed code:
s=input()
n=len(s)
s = int(s, 2)
s_10 = '1' * (n % 2) + '01' * (n // 2)
s_01 = '0' * (n % 2) + '10' * (n // 2)
s_10 = int(s_10, 2)
s_01 = int(s_01, 2)
r = bin(s ^ s_01)
l = bin(s ^ s_10)
print(min(r.count('1'), l.count('1')))
Buggy code:
S = input().rstrip()
s = list(S)
print(s)
N = len(S)
c = 0
if N == 1:
  print(0)
else:
  for i in range(1,N)
  	if S[i-1] == '0' and S[i] == '0':
      S[i] = 1
      c +=1
    elif S[i-1] == '1' and S[i] == '1':
      S[i] = 0
      c +=1
print(c)

Fixed code:
S = input().rstrip()
s = list(S)
N = len(S)
c = 0
v = [None] * N
v[0] = s[0]
if N == 1:
  print(c)
else:
  for i in range(1,N):
    
    if s[i]=='0' and v[i-1] =='0':
      v[i] = '1'
      c +=1
    elif s[i] =='1' and v[i-1] == '1':
      v[i] = '0'
      c +=1
    elif s[i] =='1' and v[i-1] == '0':
      v[i] = '1'
    elif s[i] =='0' and v[i-1] == '1':
      v[i] = '0'
    

  print(c)
Buggy code:
n=input()
def check(n,st_num):
    count=0
    dic={1:1,0:2}
    for i in range(1,-(-len(n)//2)):
        try:
            if n[2*i]+n[2*i+1]==st_num:
                count+=0
            else:
                count+=dic[abs(int(n[2*i])+int(n[2*i+1])-1)]
        except:
            if n[2*i]!=st_num[0]:
                count+=1
    
    return count
    
if '1' not in n:
    print(n//2)
if n[:2]=="10":
    print(check(n,"10"))
elif n[:2]=="01":
    print(check(n,"01"))
else:
    print(0 if len(n)==1 else check(n,"10")+1)

Fixed code:
#124
n=input()
def check(n,st_num):
    count=0
    dic={1:1,0:2}
    for i in range(1,-(-len(n)//2)):
        try:
            if n[2*i]+n[2*i+1]==st_num:
                count+=0
            else:
                count+=dic[abs(int(n[2*i])+int(n[2*i+1])-1)]
        except:
            if n[2*i]!=st_num[0]:
                count+=1
    
    return count
    
if '1' not in n:
    print(len(n)//2)
    exit()
if n[:2]=="10":
    print(check(n,"10"))
elif n[:2]=="01":
    print(check(n,"01"))
else:
    print(0 if len(n)==1 else min([check(n,"10")+1,check(n,"01")+1]))
Buggy code:
n=input()
s,a="",""
sd,ad=0,0
for i in range(len(n)):
  if i%2:
    s+="1"
    a+="0"
  else:
    s+="0"
    a+="1"
for i in range(n):
  if n[i]!=a[i]:ad+=1
  if n[i]!=s[i]:sd+=1
print(min(ad,sd))

Fixed code:
n=input()
s=""
a=""
sd,ad=0,0
for i in range(len(n)):
  if i%2:
    s+="1"
    a+="0"
  else:
    s+="0"
    a+="1"
for i in range(len(n)):
  if n[i]!=a[i]:ad+=1
  if n[i]!=s[i]:sd+=1
print(min(ad,sd))
Buggy code:
cnt=0
cnt_2=0
s = str(input())
for i in range(len(s)):
    if s[i]=='0' and i%2==0:
        cnt+=1
    else:
        cnt_2+=1
    if s[i]=='1' and i%2!=0:
        cnt+=1
    else:
        cnt_2+=1
print(min(cnt,cnt_2))

Fixed code:
cnt=0
cnt_2=0
s = str(input())
for i in range(len(s)):
    if s[i]=='0' and i%2==0:
        cnt+=1
    if s[i]=='1' and i%2==0:
        cnt_2+=1
    if s[i]=='1' and i%2!=0:
        cnt+=1
    if s[i]=='0' and i%2!=0:
        cnt_2+=1
print(min(cnt,cnt_2))
Buggy code:
S = [i for i in input()]

def henkan(a):
    if a == "0":
        a = "1"
    else:
        a = "0"
    return a
    
ans = 0
a = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        a = henkan(S[i+1])
        ans += 1
        print("a", a)
        S[i+1] = a
        print(S)
print(ans)

Fixed code:
S = [i for i in input()]

def henkan(a):
    if a == "0":
        a = "1"
    else:
        a = "0"
    return a
    
ans = 0
a = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        a = henkan(S[i+1])
        ans += 1
        S[i+1] = a
print(ans)
Buggy code:
s=input()
l=len(s)
a=[]
b=[]
i=0
for _ in range(l//2):
  a.append(s[i])
  b.append(s[i+1])
  i+=2
if l%2==1:
  a.append(s[l-1])
a0=a.count(0)
a1=a.count(1)
b0=b.count(0)
b1=b.count(1)
x=max(a0+b1,a1+b0)
print(l-x)

Fixed code:
s=input()
l=len(s)
a=[]
b=[]
i=0
for _ in range(l//2):
  a.append(s[i])
  b.append(s[i+1])
  i+=2
if l%2==1:
  a.append(s[l-1])
a0=a.count('0')
a1=a.count('1')
b0=b.count('0')
b1=b.count('1')
x=max(a0+b1,a1+b0)
print(l-x)
Buggy code:
color = [int(i) for i in input()]
n = len(color)
ans = 0

if n%2==1:
    arfa = [10]*n//2 + [1]
    beta = [01]*n//2 + [0]
else:
    arfa = [10]*n//2
    beta = [01]*n//2

ansa=0;ansb=0
for i in range(n):
    if color[i]!=arfa[i]:
        ansa += 1
    if color[i]!=beta[i]:
        ansb += 1
print(min([ansa,ansb]))


Fixed code:
color = [int(i) for i in input()]
n = len(color)
ans = 0

if n%2==1:
    arfa = [1,0]*(n//2) + [1]
    beta = [0,1]*(n//2) + [0]
else:
    arfa = [1,0]*(n//2)
    beta = [0,1]*(n//2)

ansa=0;ansb=0
for i in range(n):
    if color[i]!=arfa[i]:
        ansa += 1
    if color[i]!=beta[i]:
        ansb += 1
print(min([ansa,ansb]))
Buggy code:
s = input()
c0 = 0
c1 = 0
for i in range(s):
  if i % 2 == 0:
    if s[i] != '0':
      c0 += 1
    if s[i] != '1':
      c1 += 1
  else:
    if s[i] != '1':
      c0 += 1
    if s[i] != '0':
      c1 += 1
print(min(c0, c1))

Fixed code:
s = input()
c0 = 0
c1 = 0
for i in range(len(s)):
  if i % 2 == 0:
    if s[i] != '0':
      c0 += 1
    if s[i] != '1':
      c1 += 1
  else:
    if s[i] != '1':
      c0 += 1
    if s[i] != '0':
      c1 += 1
print(min(c0, c1))
Buggy code:
tiles = map(int, input())
# inputs = "10010010"
# tiles = list(map(int, inputs))


def count_repaint_tiles(tiles):
    if len(tiles) == 0:
        return 0
    counts = 0
    color = tiles[0]
    for tile in tiles[1:]:
        counts = counts + 1 if tile != color else 0
        color = 1 - color
    return counts


print(count_repaint_tiles(tiles))


Fixed code:
tiles = list(map(int, input()))
# inputs = "10010010"
# tiles = list(map(int, inputs))


def count_repaint_tiles(tiles):
    if len(tiles) == 0:
        return 0
    counts = 0
    color = tiles[0]
    for tile in tiles[1:]:
        if tile == color:
            counts = counts + 1
        color = 1 - color
    return counts


print(count_repaint_tiles(tiles))
Buggy code:
import numpy as np
S = input()
N = len(S)
if N // 2 == 0:
  even = np.array([S[2*k] for k in range(N // 2)])
  odd = np.array([S[2*k + 1] for k in range(N // 2)])
  even_1 = even.sum()
  odd_1 = odd.sum()
  if even_1 > odd_1:
    print(N//2 - even_1 + odd_1)
  else:
    print(N//2 + even_1 - odd_1)
else:
  even = np.array([S[2*k] for k in range( (N+1) // 2)])
  odd = np.array([S[2*k + 1] for k in range(N // 2)])
  even_1 = even.sum()
  odd_1 = odd.sum()
  if even_1 <= odd_1:
    print(even_1 + N//2 - odd_1)
  else:
    print(odd_1 + (N+1)//2 - even_1)

Fixed code:
import numpy as np
S = input()
N = len(S)
if N // 2 == 0:
  even = np.array([int(S[2*k]) for k in range(N // 2)])
  odd = np.array([int(S[2*k + 1]) for k in range(N // 2)])
  even_1 = even.sum()
  odd_1 = odd.sum()
  if even_1 > odd_1:
    print(int(N//2 - even_1 + odd_1))
  else:
    print(int(N//2 + even_1 - odd_1))
else:
  even = np.array([int(S[2*k]) for k in range( (N+1) // 2)])
  odd = np.array([int(S[2*k + 1]) for k in range(N // 2)])
  even_1 = even.sum()
  odd_1 = odd.sum()
  if even_1 <= odd_1:
    print(int(even_1 + N//2 - odd_1))
  else:
    print(int(odd_1 + (N+1)//2 - even_1))
Buggy code:
import math
import os
import random
import re
import sys
from collections import defaultdict

sys.stdin = open('input.in', 'r')
sys.stdout = open('output.out', 'w') 

def onezero(a):
	count = 0
	for i in range(0, len(a), 2):
		if a[i] == 0:
			count += 1
	for i in range(1, len(a), 2):
		if a[i] == 1:
			count += 1
	return count

def zeroone(a):
	count = 0
	for i in range(0, len(a), 2):
		if a[i] == 1:
			count += 1
	for i in range(1, len(a), 2):
		if a[i] == 0:
			count += 1
	return count


def count(n):
	return min(onezero(n),zeroone(n))

if __name__ == '__main__':
	N = [int(d) for d in input()]
	print(count(N))

Fixed code:
import math
import os
import random
import re
import sys
from collections import defaultdict

# sys.stdin = open('input.in', 'r')
# sys.stdout = open('output.out', 'w') 

def onezero(a):
	count = 0
	for i in range(0, len(a), 2):
		if a[i] == 0:
			count += 1
	for i in range(1, len(a), 2):
		if a[i] == 1:
			count += 1
	return count

def zeroone(a):
	count = 0
	for i in range(0, len(a), 2):
		if a[i] == 1:
			count += 1
	for i in range(1, len(a), 2):
		if a[i] == 0:
			count += 1
	return count


def count(n):
	return min(onezero(n),zeroone(n))

if __name__ == '__main__':
	N = [int(d) for d in input()]
	print(count(N))
Buggy code:
S = [int(i) for i in input()]

ans = 0
for i in range(2):
    cnt = 0
    for j, s_j in enumerate(S):
        if j % 2 == 0 ^ s_j != i:
            cnt += 1
    ans = min(ans, cnt)

print(ans)

Fixed code:
S = [int(i) for i in input()]

ans = 99999999
for i in range(2):
    cnt = 0
    for j, s_j in enumerate(S):
        if (j % 2 == 0) ^ (s_j != i):
            cnt += 1
    ans = min(ans, cnt)

print(ans)
Buggy code:
a = input()
n = len(a)
count0 = 0    #start from 0
count1 = 0    #start from 1
for i in range(n):
    if i % 2 == 0 and int(a[i]) ==1:
        count0 = count0 +1
        print(count0)
    elif i % 2 == 0 and int(a[i]) ==0:
        count1 = count1 +1
    elif i % 2 == 1 and int(a[i]) ==1:
        count1 = count1 +1
    elif i % 2 == 1 and int(a[i]) ==0:
        count0 = count0 +1

print(min(count0, count1))


Fixed code:
a = input()
n = len(a)
count0 = 0    #start from 0
count1 = 0    #start from 1
for i in range(n):
    if i % 2 == 0 and int(a[i]) ==1:
        count0 = count0 +1
    elif i % 2 == 0 and int(a[i]) ==0:
        count1 = count1 +1
    elif i % 2 == 1 and int(a[i]) ==1:
        count1 = count1 +1
    elif i % 2 == 1 and int(a[i]) ==0:
        count0 = count0 +1

print(min(count0, count1))
Buggy code:
S=int(input())
Sstr=str(S)
s=len(Sstr)
Sk=[]
Sg=[]
for i in range(0,s,2):
    Sk.append(Sstr[i])
for i in range(1,s,2):
    Sg.append(Sstr[i])
Sk0=Sk.count('0')
Sk1=Sk.count('1')
Sg0=Sg.count('0')
Sg1=Sg.count('1')
Stotal=[Sk0,Sk1,Sg0,Sg1]
if Sk0+Sg1<Sk1+Sg0:
    print(Sk0+Sg1)
else:
    print(Sk1+Sg0)

Fixed code:
S=str(input())
s=len(S)
Sk=[]
Sg=[]
for i in range(0,s,2):
    Sk.append(S[i])
for i in range(1,s,2):
    Sg.append(S[i])
Sk0=Sk.count('0')
Sk1=Sk.count('1')
Sg0=Sg.count('0')
Sg1=Sg.count('1')
Stotal=[Sk0,Sk1,Sg0,Sg1]
if Sk0+Sg1<Sk1+Sg0:
    print(Sk0+Sg1)
else:
    print(Sk1+Sg0)
Buggy code:
def ret(a,b,c):
  global c2,c3
  if a == b:
    if b == "0":
      return "1"
   	else:
      return "0"
    if c == 2:
      c2 += 1
    else:
      c3 += 1
  else:
    return b
S = input()
S2,S3 = list(S),list(S)
c2,c3 = 0,0
default = S2[0]
for j,k in enumerate(S2):
  if j == 0:
    continue
  S2[j] = ret(S2[j-1],k,2)
for j,k in enumerate(S3):
  if j == 0:
    S3[0] = ret(default,S3[0])
  S3[j] = ret(S3[j-1],k,3)
print(c2 if c2 >= c3 else c3)

Fixed code:
c2,c3 = 0,0
def ret(a,b,c):
  global c2,c3
  if a == b:
    if c == 2:
      c2 += 1
    else:
      c3 += 1
    if b == "0":
      return "1"
    else:
      return "0"
  else:
    return b
S = input()
S2,S3 = list(S),list(S)
default = S2[0]
for j,k in enumerate(S2):
  if j == 0:
    continue
  S2[j] = ret(S2[j-1],k,2)
for j,k in enumerate(S3):
  if j == 0:
    S3[0] = ret(default,S3[0],3)
  S3[j] = ret(S3[j-1],k,3)
print(c2 if c2 <= c3 else c3)
Buggy code:
a = input()
l1 = a[::2]
l2 = a[1::2]
x, y = 0, 0
for i in range(len(l1)):
  if l1[i] =='1':
    x +=1
if i in range(len(l2)):
  if l2[i] =='0':
    y +=1
print(min(x +y,len(l1)-x + len(l2)-y))

Fixed code:
a = input()
l1 = a[::2]
l2 = a[1::2]
x, y = 0, 0
for i in range(len(l1)):
  if l1[i] =='1':
    x +=1
for i in range(len(l2)):
  if l2[i] =='0':
    y +=1
print(min(x +y,len(l1)-x + len(l2)-y))
Buggy code:
string = str(input())
lis = []

for s in string:
  lis.append(int(s))
  
ans = 0
itr = 0
j = 0
for i in lis:
  if len(lis) == 1:
    print(ans)
    
  if itr == 0:
    itr += 1
    j = i
    continue
    
  if  j == i:
    ans += 1
    if i == 1:
      j = 0
    else:
      j = 1
  else:
    j = i
    continue

print(ans)
    
  


Fixed code:
string = str(input())
lis = []

for s in string:
  lis.append(int(s))
  
ans = 0
itr = 0
j = 0
for i in lis:
  if len(lis) == 1:
    break
    
  if itr == 0:
    itr += 1
    j = i
    continue
    
  if  j == i:
    ans += 1
    if i == 1:
      j = 0
    else:
      j = 1
  else:
    j = i
    continue

print(ans)