qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N = int(input())
if N == 0:
    print("0")
a = []
#N = abs(N)
for i in range(1000000000):
    if N == 0:
        break
    else:
        if abs(N) % pow(2,i+1) != 0:
            a.append(1)
            N -= pow(-2,i)
        else:
            a.append(0)
        #print(N)
#print(a)
s = 0
for i in range(len(a)):
    s += a[i] * pow(10,i)
print(s)

Fixed code:
N = int(input())
if N == 0:
    print("0")
    exit()
a = []
#N = abs(N)
for i in range(1000000000):
    if N == 0:
        break
    else:
        if abs(N) % pow(2,i+1) != 0:
            a.append(1)
            N -= pow(-2,i)
        else:
            a.append(0)
        #print(N)
#print(a)
s = 0
for i in range(len(a)):
    s += a[i] * pow(10,i)
print(s)
Buggy code:
n = int(input())
s = ''

if n == 0:
    print(0)
    exit()

i = 0
while n != 0:
    if n % (2 ** (i+1)) != 0:
        s += '1'
        n -= (-2) ** i
    else:
        s += '0'
    print(s)
    i += 1
print(s[::-1])

Fixed code:
n = int(input())
s = ''
 
if n == 0:
    print(0)
    exit()
 
i = 0
while n != 0:
    if n % (2 ** (i+1)) != 0:
        s += '1'
        n -= (-2) ** i
    else:
        s += '0'
    i += 1
print(s[::-1])
Buggy code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    n = int(input())
    ans, m = "", 1
    while n != 0:
        m *= (-2)
        if abs(n) % abs(m) > 0:
            ans += "1"
            n -= m // (-2)
        else:
            ans += "0"
    print(ans if ans else 0)

if __name__=="__main__":
    solve()

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

def solve():
    n = int(input())
    ans, m = "", 1
    while n != 0:
        m *= (-2)
        if abs(n) % abs(m) > 0:
            ans += "1"
            n -= m // (-2)
        else:
            ans += "0"
    print(ans[::-1] if ans else 0)

if __name__=="__main__":
    solve()
Buggy code:
num=[]
n=int(input())
while n!=0:
    if n%2==1:
        num.append("1")
        n=(n-1)//(-2)
    else:
        num.append("0")
        n=n//(-2)
print("".join(num))

Fixed code:
num=[]
n=int(input())
while n!=0:
    if abs(n)%2==1:
        num.append("1")
        n=(n-1)//(-2)
    else:
        num.append("0")
        n=n//(-2)
if len(num)==0:
    num=["0"]
print("".join(num[::-1]))
Buggy code:
n = int(input())

ans = ''

while n != 0:
    r = n % 2 
    print(r)

    if r < 0:
        r = r + 2
    
    n = (n-r) / (-2)

    ans = ans + str(int(r))

ans = list(ans)    
print(ans)
ans.reverse()
print(''.join(ans))

Fixed code:
n = int(input())

ans = ''

if n == 0:
    print('0')

while n != 0:
    r = n % 2 

    if r < 0:
        r = r + 2
    
    n = (n-r) / (-2)

    ans = ans + str(int(r))

ans = list(ans)    
ans.reverse()
print(''.join(ans))
Buggy code:
n=int(input())
result=''
while True:
    if n==0:
        break
    if n%2==0:
        n=n/(-2)
        result='0'+result
    else:
        n=(n-1)/(-2)
        result='1'+result
print(int(result))

Fixed code:
n=int(input())
result=''
if n==0:
    result='0'
while True:
    if n==0:
        break
    if n%2==0:
        n=n/(-2)
        result='0'+result
    else:
        n=(n-1)/(-2)
        result='1'+result
print(int(result))
Buggy code:
# encoding: utf-8
N = int(input())

# define L

# adjust
ans = ""
while N != 0:
    # print(N, ans)
    if N % 4 == 0:
        ans = "00" + ans
        N -= 0
    elif N % 4 == 1:
        ans = "01" + ans
        N -= 1
    elif N % 4 == 2:
        ans = "10" + ans
        N -= -2
    else:
        ans = "11" + ans
        N -= -1
    N = int(N / 4)
    
for i in range(len(ans)):
    if ans[i] != "0":
        print(ans[i:])
        break


Fixed code:
# encoding: utf-8
N = int(input())

# define L

# adjust
ans = ""
while N != 0:
    # print(N, ans)
    if N % 4 == 0:
        ans = "00" + ans
        N -= 0
    elif N % 4 == 1:
        ans = "01" + ans
        N -= 1
    elif N % 4 == 2:
        ans = "10" + ans
        N -= -2
    else:
        ans = "11" + ans
        N -= -1
    N = int(N / 4)
    
for i in range(len(ans)):
    if ans[i] != "0":
        print(ans[i:])
        break
else:
    print(0)
Buggy code:
N = int(input())
ans = ''
while N != 0:
    bit = N % 2
    ans = str(bit) + ans
    N -= bit
    N //= -2
print(ans)

Fixed code:
N = int(input())
ans = ''
while N != 0:
    bit = N % 2
    ans = str(bit) + ans
    N -= bit
    N //= -2
if not ans:ans=0
print(ans)
Buggy code:
from math import log2

def main():
    N = int(input())
    if N == 0:
        print(0)
        return
    Ans = []
    while N !=  1:
        r = N%2
        Ans.append(r)
        N = -1*( N // 2)
    print(*Ans[::-1],sep="")
    return

if __name__ == "__main__":
    main()

Fixed code:
from math import log2

def main():
    N = int(input())
    if N == 0:
        print(0)
        return
    Ans = []
    while N !=  0:
        r = N%2
        Ans.append(r)
        N = -1*( N // 2)
    print(*Ans[::-1],sep="")
    return

if __name__ == "__main__":
    main()
Buggy code:
N = int(input())
ans = ''

while N:
    if N % 2:
        N -= 1
        ans += '1'
    else:
        ans += '0'
    N //= -2
if len(ans):
    print(ans)
else:
    print(0)

Fixed code:
N = int(input())
ans = ''

while N:
    if N % 2:
        N -= 1
        ans += '1'
    else:
        ans += '0'
    N //= -2
if len(ans):
    print(ans[::-1])
else:
    print(0)
Buggy code:
n = int(input())
s = ""

while abs(n) > 0:
    if(abs(n) % 2 == 0):
        s = "0" + s
    else:
        s = "1" + s
        n -= 1
    n = n // (-2)
print(s)

Fixed code:
n = int(input())
s = ""

if n == 0:
    print("0")

while abs(n) > 0:
    if(abs(n) % 2 == 0):
        s = "0" + s
    else:
        s = "1" + s
        n -= 1
    n = n // (-2)
print(s)
Buggy code:
N = int(input())
s = ''
while N != 0:
    if N % 2 == 1:
        s += '1'
        N = (N - 1) / (-2) 
    else:
        s += '0'
        N = N / ( -2 )
print(s[::-1])

Fixed code:
N = int(input())
s = ''

if N != 0:
    while N != 0:
        if N % 2 == 1:
            s += '1'
            N = (N - 1) / (-2) 
        else:
            s += '0'
            N = N / ( -2 )
else :
    s = '0'
print(s[::-1])
Buggy code:
n = int(input())
ans = []
for i in range(10**5):
    if n == 0:
        break
    if n%pow(2,i+1) != 0:
        ans.append('1')
        n -= pow(-2,i)
    else:
        ans.append('0')
    

ans = ans[::-1]
ans_s = ''.join(ans)
print(ans_s)

Fixed code:
n = int(input())
ans = []
if n == 0:
    print(0)
    exit()
for i in range(10**5):
    if n == 0:
        break
    if n%pow(2,i+1) != 0:
        ans.append('1')
        n -= pow(-2,i)
    else:
        ans.append('0')
    

ans = ans[::-1]
ans_s = ''.join(ans)
print(ans_s)
Buggy code:
n=int(input())
s=[]
while n!=0:
    r=n%(-2)
    if r<0:
        r+=2
    n=(n-r)//(-2)
    s.append(str(r))
s.reverse()
print(''.join(s))


Fixed code:
n=int(input())
s=[]
if n==0:
    s.append('0')
while n!=0:
    r=n%(-2)
    if r<0:
        r+=2
    n=(n-r)//(-2)
    s.append(str(r))
s.reverse()
print(''.join(s))
Buggy code:
N = int(input())
a = ''
n = 0
while N != 0:
    b = '0' if N % (2**(n + 1)) == 0 else '1'
    a += b
    N -= ((-2)**n) * int(b)
    n += 1
print(a[::-1])


Fixed code:
N = int(input())
a = ''
n = 0
while N != 0:
    b = '0' if N % (2**(n + 1)) == 0 else '1'
    a += b
    N -= ((-2)**n) * int(b)
    n += 1
print(a[::-1] if a else 0)
Buggy code:
n = int(input())
i = 1
ans = ''
while n != 0:
    if n % i == 0 and n % (i * -2) != 0:
        n -= i
        ans += '1'
    else:
        ans += '0'
    i *= -2
print(ans[::-1])

Fixed code:
n = int(input())
i = 1
ans = ''
while n != 0:
    if n % i == 0 and n % (i * -2) != 0:
        n -= i
        ans += '1'
    else:
        ans += '0'
    i *= -2
if ans == '':
  print(0)
else:
  print(ans[::-1])
Buggy code:
n = int(input())
res = ""
while True:
	if n == 0:
		break
	else:
		if n%2 == 0:
			res += '0'
		else:
			res += '1'
			n -= 1
		n //= -2
print(res[::-1])

Fixed code:
n = int(input())
if n == 0:
	print(0)
	exit()
res = ""
while True:
	if n == 0:
		break
	else:
		if n%2 == 0:
			res += '0'
		else:
			res += '1'
			n -= 1
		n //= -2
print(res[::-1])
Buggy code:
N = int(input())
tmp = ''
while N:
  if(N%2 == 0):
    tmp += '0'
  else:
    tmp += '1'
  N -= 1
  N //= -2
print(tmp[::-1])

Fixed code:
N = int(input())
tmp = ''
while N:
  if(N%2 == 0):
    tmp += '0'
  else:
    tmp += '1'
  N -= 1
  N //= -2
if(tmp == ''):
  tmp = '0'
print(tmp[::-1])
Buggy code:
N = int(input())
ans = ""
while N != 0:
  if(N%2 == 0):
    ans += "0"
  else:
    ans += "1"
    N -= 1
  N //= -2
if(bit == ""):
  ans = ""
print(ans[::-1])  

Fixed code:
N = int(input())

ans = ""
while N != 0:
  if(N%2 == 0):
    ans += "0"
  else:
    ans += "1"
    N -= 1
  N /= -2
if(ans == ""):
  ans = "0"
print(ans[::-1])
Buggy code:
n = int(input())
ans = ''
i = 0
while n != 0:
    if n % ((-2) ** (i + 1)) == 0:
        ans = '0' + ans
    else:
        ans = '1' + ans
        n -= (-2) ** i
    i += 1
print(ans)

Fixed code:
n = int(input())

ans = ""
i = 1
while n != 0:
    if n%2 == 1:
        n += (-1)**i
        ans = "1" + ans
    else:
        ans = "0" + ans
    n //= 2
    i += 1

if ans == "":
    ans = "0"
print(ans)
Buggy code:
n = int(input())
lst = []

while (n!=0):
    r = int(n%2)
    if(r<0):
        r += 2
    lst.append(r)
    n = (n-r)/(-2)

for i in range(len(lst)):
    print(lst[-1-i],end="")
print()

Fixed code:
n = int(input())
lst = []

while (n!=0):
    r = int(n%2)
    if(r<0):
        r += 2
    lst.append(r)
    n = (n-r)/(-2)

if len(lst) ==0:
    print("0")
else:
    for i in range(len(lst)):
        print(lst[-1-i],end="")
    print()
Buggy code:

n = int(input())

bit = []
while n != 0:
    bit.append(-(-n % -2))
    n = -(-n // -2)

for i in range(len(bit) - 1, -1, -1):
    print(bit[i], end = "")
print()

Fixed code:

n = int(input())
if n == 0:
    print(0)
    exit()
bit = []
while n != 0:
    bit.append(-(-n % -2))
    n = -(-n // -2)

for i in range(len(bit) - 1, -1, -1):
    print(bit[i], end = "")
print()
Buggy code:
# -*- coding: utf-8 -*-
#ABC105C
import sys

n = int(input())
#tmp = input().split()
#hoge = list(map(lambda a: int(a), tmp))

res=[]

while(1):
	#print(n)
	if(n==0):
		break
	if n%2==1:
		res.append(1)
		n-=1
		n=n//(-2)
	else:
		res.append(0)
		n=n//(-2)

res2=""
for i in range(0,len(res)):
	res2=res2+str(res[len(res)-i-1])
print(res2)

Fixed code:
# -*- coding: utf-8 -*-
#ABC105C
import sys

n = int(input())
#tmp = input().split()
#hoge = list(map(lambda a: int(a), tmp))

res=[]

if(n==0):
	print("0")
	sys.exit()

while(1):
	#print(n)
	if(n==0):
		break
	if n%2==1:
		res.append(1)
		n-=1
		n=n//(-2)
	else:
		res.append(0)
		n=n//(-2)

res2=""
for i in range(0,len(res)):
	#res2=res2+str(res[len(res)-i-1])
	res2=res2+str(res[-i-1])
print(res2)
Buggy code:
import math

def main():
	n = int(input())
	ans = ""

	i = 0
	while n != 0:
		print(n)
		if n % (2 ** (i + 1)) != 0:
			ans += "1"
			n -= (-2) ** i
		else:
			ans += "0"

		i += 1

	if n == 0:
		print(0)
	else:
		print(ans[::-1])

if __name__ == '__main__':
	main()

Fixed code:
import math

def main():
	n = int(input())
	ans = ""

	i = 0

	if n == 0:
		print(0)
		return 

	while n != 0:
		if n % (2 ** (i + 1)) != 0:
			ans += "1"
			n -= (-2) ** i
		else:
			ans += "0"

		i += 1

	print(ans[::-1])

if __name__ == '__main__':
	main()
Buggy code:
n = int(input())

ans = []
a = n
while a != 0:
    b = a % (-2)
    a //= (-2)
    if b == -1:
        a += 1
        b = 1
    ans.append(b)

ans.reverse()    
print(*ans, sep='')        


Fixed code:
n = int(input())

ans = []
a = n
while a != 0:
    b = a % (-2)
    a //= (-2)
    if b == -1:
        a += 1
        b = 1
    ans.append(b)
if not ans: ans = [0]
ans.reverse()    
print(*ans, sep='')
Buggy code:
n = int(input())
i = 0
ans = []
while n:
    i += 1
    if n%(2**i):
        n -= (-2)**(i-1)
        ans.append("1")
    else:
        ans.append("0")
print("".join(ans[::-1]))

Fixed code:
n = int(input())
i = 0
ans = []
if n == 0:
    print(0)
    quit()
while n:
    i += 1
    if n%(2**i):
        n -= (-2)**(i-1)
        ans.append("1")
    else:
        ans.append("0")
print("".join(ans[::-1]))
Buggy code:
n=int(input())
ans=""
if n==0:print("0");exit()
while n!=0:
    ans +=str(n%2)
    n=n//-2
print("".join(ans[::-1]))

Fixed code:
n=int(input())
ans=""
if n==0:print("0");exit()
while n!=0:
    ans +=str(n%2)
    n=-(n//2)
print("".join(ans[::-1]))
Buggy code:
n=int(input())
x=""
while n!=0:
    x=str(n%2)+x
    n=-(n//2)
    print(x,n)
print(0 if x=="" else x)

Fixed code:
n=int(input())
x=""
while n!=0:
    x=str(n%2)+x
    n=-(n//2)
print(0 if x=="" else x)
Buggy code:
N = int(input())
S = ""
flg = 1
while N != 0:
    if N % 2:
        S = "1" + S
        N -= flg
    else:
        S = "0" + S
    N //= 2
    flg *= -1
print(S)


Fixed code:
N = int(input())
S = ""
flg = 1
while N != 0:
    if N % 2:
        S = "1" + S
        N -= flg
    else:
        S = "0" + S
    N //= 2
    flg *= -1
if S == "": S = "0"
print(S)
Buggy code:
N=int(input())
l=[]
j=0
while sum(l[i]*(-2)**i for i in range(len(l)))!=N:
  if sum(l[i]*(-2)**i for i in range(len(l)))%((-2)**(j+1))==N%((-2)**(j+1)):
    l.append(0)
  else:
    l.append(1)
  j+=1
print(''.join(map(str,reversed(l))))

Fixed code:
N=int(input())
l=[0] if N==0 else []
j=0

while sum(l[i]*(-2)**i for i in range(len(l)))!=N:
  if sum(l[i]*(-2)**i for i in range(len(l)))%((-2)**(j+1))==N%((-2)**(j+1)):
    l.append(0)
  else:
    l.append(1)
  j+=1
print(''.join(map(str,reversed(l))))
Buggy code:
a=int(input());s=''
while a!=0:s+=str(a%2);a=-(a//2)
print(int(s[::-1]))

Fixed code:
a=int(input());s=''
while a!=0:s+=str(a%2);a=-(a//2)
print(int(s[::-1]) if s != '' else 0)
Buggy code:
def div(x):
    a = x //(-2)
    if a*(-2) > x:
        a+=1
    return a
n = int(input())
bi = ""
while n != 0:
    x = div(n)
    if n % (-2) != 0:
        bi = "1"+bi
    elif x != 0:
        bi = "0"+bi 
    n = x
print(bi)

Fixed code:
def div(x):
    a = x //(-2)
    if a*(-2) > x:
        a+=1
    return a
n = int(input())
bi = ""
flag = 0
if n == 0:
    flag = 1
while n != 0:
    x = div(n)
    if n % (-2) != 0:
        bi = "1"+bi
    elif x != 0:
        bi = "0"+bi 
    n = x
print("0" if flag == 1 else bi)
Buggy code:
N = int(input())

ans = ''
while(N != 0):
  r = N % 2
  ans += str(r)
  N = (N-r) // (-2)
  #print(N,r)
print(''.join(reversed(ans)))

Fixed code:
N = int(input())

if N == 0:
  print(0)
  exit()

ans = ''
while(N != 0):
  r = N % 2
  ans += str(r)
  N = (N-r) // (-2)
  #print(N,r)
print(''.join(reversed(ans)))
Buggy code:
N = int(input())
ans = []

while N != 0:
    r = N % 2
    r = abs(r)
    N = (N - r) // -2
    ans.append(str(r))
ans.reverse()
print(''.join(ans))

Fixed code:
N = int(input())
ans = []

if N == 0:
    print(0)
    exit()

while N != 0:
    r = N % 2
    r = abs(r)
    N = (N - r) // -2
    ans.append(str(r))
ans.reverse()
print(''.join(ans))
Buggy code:
n=int(input())

if n==0:
    print(0)
else:
    ans=""
    while n!=0:
        ans=str(n%2)+ans
        n=n//(-2)
ans=int(ans)
print(ans)

Fixed code:
n=int(input())

if n==0:
    ans="0"
else:
    ans=""
    while n!=0:
        ans=str(n%2)+ans
        n=-1*(n//2)
ans=int(ans)
print(ans)
Buggy code:
N = int(input())
ans = []
for i in range(10**10):
    if N == 0:
        break
    if N%2 == 1:
        ans.append("1")
        N -= (-1)**(i)
    else:
        ans.append('0')
    N = N // 2

print(''.join(ans[::-1]))

Fixed code:
N = int(input())
ans = []
if N == 0:
    print(0)
    exit()
for i in range(10**10):
    if N == 0:
        break
    if N%2 == 1:
        ans.append("1")
        N -= (-1)**(i)
    else:
        ans.append('0')
    N = N // 2

print(''.join(ans[::-1]))
Buggy code:
import math

def dnt(n):
    if n >= 0:
        return (-1) * (n // 2)
    else:
        return math.ceil((-1) * (n / 2))

N = int(input())
S = ""

while N != 1:
    if N % 2 == 1:
        S = "1" + S
    else:
        S = "0" + S
    N = dnt(N)
    print(N)

print("1"+S)

Fixed code:
import math

def dnt(n):
    if n >= 0:
        return (-1) * (n // 2)
    else:
        return math.ceil((-1) * (n / 2))

N = int(input())
S = ""

if N == 0:
    print(0)

else:
    while N != 1:
        if N % 2 == 1:
            S = "1" + S
        else:
            S = "0" + S
        N = dnt(N)
    print("1"+S)
Buggy code:
N = int(input())
ans = ""

while N != 0:
    if N % 2 != 0:
        N -= 1
        ans = "1" + ans
    else:
        ans = "0" + ans
        N /= -2
    if ans == "":
        ans = "0"

print(ans) 

Fixed code:
N = int(input())
ans = ""

while N != 0:
    if N % 2 != 0:
        N -= 1
        ans = "1" + ans
    else:
        ans = "0" + ans
    N /= -2
if ans == "":
    ans = "0"

print(ans)
Buggy code:
N=int(input())
L=[]
M=""
while N!=0:
  M=int((-1)*(N%(-2)))
  if N<0:
    N=int((N-1)/(-2))
  else:
    N=int(N/(-2))
  L.insert(0,str(M))
print("".join(L))


Fixed code:
N=int(input())
L=[]
M=""
while N!=0:
  M=int((-1)*(N%(-2)))
  if N<0:
    N=int((N-1)/(-2))
  else:
    N=int(N/(-2))
  L.insert(0,str(M))
if len(L)==0:
  L=["0"]
print("".join(L))
Buggy code:
N = int(input())
k = 0
i = 0
ans = []
while k != N:
    j = pow(-2, i)
    p = '1' if (N - k - j) % pow(2, i + 1) == 0 else '0'
    ans.append(p)
    k += int(p) * j
    i += 1

print(''.join(reversed(ans)))


Fixed code:
N = int(input())
k = 0
i = 0
ans = []
while k != N:
    j = pow(-2, i)
    p = '1' if (N - k - j) % pow(2, i + 1) == 0 else '0'
    ans.append(p)
    k += int(p) * j
    i += 1

if N == 0:
    print(0)
else:
    print(''.join(reversed(ans)))
Buggy code:
N=int(input())
if N==0:print(0)
bi=''
while n!=0:
    bi+=str(n%abs(k))
    if k<0:n=-(-n//k)
    else:n=n//k
print(bi[::-1])

Fixed code:
n=int(input())
if n==0:print(0)
k=-2
bi=''
while n!=0:
    bi+=str(n%abs(k))
    if k<0:n=-(-n//k)
    else:n=n//k
print(bi[::-1])
Buggy code:
N = int(input())
s = []
for i in range(100):
    if N % (2 ** (i+1)) != 0:
        N -= (-2) ** i
        s.append('1')
    else:
        s.append('0')

s.reverse()
print(s)
t = ''.join(s)
print(int(t))


Fixed code:
N = int(input())
s = []
for i in range(100):
    if N % (2 ** (i+1)) != 0:
        N -= (-2) ** i
        s.append('1')
    else:
        s.append('0')

s.reverse()
t = ''.join(s)
print(int(t))
Buggy code:
N=int(input())
i=0
s=[]
n=N
while 1:
    k=pow(2,i+1)
    d=n%k
    if d!=0:
        s.append(1)
        n=n-pow(-2,i)
    elif n//k!=0:
        s.append(0)
    else:
        break
    i=i+1
while s:
    print(s.pop())
    

Fixed code:
N=int(input())
i=0
s=[]
n=N
while 1:
    k=pow(2,i+1)
    d=n%k
    if d!=0:
        s.append(1)
        n=n-pow(-2,i)
    elif n//k!=0:
        s.append(0)
    else:
        break
    i=i+1
while s:
    print(s.pop(),end="")
if N==0:
    print(0,end="")
print("")
Buggy code:
from math import *

#N = int(input())
N = int(input().strip())

def search_n(N):
    if N == 0 or N == 1:
        return 1
    minN = 0
    maxN = 1
    for i in range(1, 32):
        a1 = minN + (-2)**i
        a2 = maxN + (-2)**i
        minN = min(minN, min(a1, a2))
        maxN = max(maxN, max(a1, a2))
        if N <= maxN and N >= minN:
            return i

result = []
while N != 0 and N != 1:
    n = search_n(N)
    N -= (-2)**n
    if len(result) == 0:
        result = ['0' for i in range(0, n+1)]
    result[n] = '1'

if N==1:
    result[0] = '1'

result.reverse()
print(''.join(result))


Fixed code:
from math import *

#N = int(input())
N = int(input().strip())

def search_n(N):
    if N == 0 or N == 1:
        return 1
    minN = 0
    maxN = 1
    for i in range(1, 40):
        a1 = minN + (-2)**i
        a2 = maxN + (-2)**i
        minN = min(minN, min(a1, a2))
        maxN = max(maxN, max(a1, a2))
        if N <= maxN and N >= minN:
            return i

result = ['0']
while N != 0 and N != 1:
    n = search_n(N)
    N -= (-2)**n
    if len(result) == 1:
        result = ['0' for i in range(0, n+1)]
    result[n] = '1'

if N==1:
    result[0] = '1'

result.reverse()
print(''.join(result))
Buggy code:
n = int(input())
ans = ''
for i in range(10000):
    if n == 0:
        break
    if n % 2 ** (i + 1) == 0: 
        ans = '0' + ans
    else:
        n -= (-2)**i
        ans = '1' + ans
print(ans)

Fixed code:
n = int(input())
ant = 0
if n == 0:
    ant = 1
ans = ''
for i in range(10000):
    if n == 0:
        break
    if n % 2 ** (i + 1) == 0: 
        ans = '0' + ans
    else:
        n -= (-2)**i
        ans = '1' + ans
if ant == 0:
    print(ans)
else:
    print('0')
Buggy code:
import bisect
def put(a,b):
    a+="0"*20
    b+="0"*20
    s=""
    for  i in range(20):
        s+=a[i]+b[i]
    s=s[-1::-1]
    ind=s.find("1")
    if ind==-1:
        print(0)
    else:
        s=s[ind:]
        print(s[-1::-1])

def quad(i):
    s=""
    while i>0:
        s+=str(i%4)
        i//=4
    return s[-1::-1]

l=[0,1]
for i in range(1,18):
    l+=[4**i+j for j in l]

n=int(input())
for i in range(len(l)):
    if (n-l[i])%2==0:
        ind=bisect.bisect_left(l,(l[i]-n)//2)
        if l[i]-2*l[ind]==n:
            put(quad(l[i]),quad(l[ind]))
            break


Fixed code:
import bisect
def put(a,b):
    l=max(len(a),len(b))
    a="0"*l+a
    b="0"*l+b
    s=""
    for i in range(-1,-l-1,-1):
        s+=a[i]+b[i]
    s=s[-1::-1]
    ind=s.find("1")
    print(s[ind:])

def quad(i):
    s=""
    while i>0:
        s+=str(i%4)
        i//=4
    return s[-1::-1]

l=[0,1]
for i in range(1,18):
    l+=[4**i+j for j in l]

n=int(input())
if n==0:
    print(0)
else:
    for i in range(len(l)):
        if (n-l[i])%2==0:
            ind=bisect.bisect_left(l,(l[i]-n)//2)
            if l[i]-2*l[ind]==n:
                put(quad(l[i]),quad(l[ind]))
                break
Buggy code:
N = int(input())
S = ""
while N != 0:
    if N % 2 != 0:
        N -= 1
        S = "0" + S
    else:
        S = "1" + S
    N //= (-2)
print(S if S != "" else "0")


Fixed code:
N = int(input())
S = ""
while N != 0:
    if N % 2 != 0:
        N -= 1
        S = "1" + S
    else:
        S = "0" + S
    N //= (-2)
print(S if S != "" else "0")
Buggy code:
n=int(input())
s=""
base=-2
while n!=0:
    if n%-2==0:
        s='0'+s
    if n%-2!=0:
        s='1'+s
        n-=1
    n/=-2
print(s)

Fixed code:
n=int(input())
s=""
base=-2
while n!=0:
    if n%-2==0:
        s='0'+s
    if n%-2!=0:
        s='1'+s
        n-=1
    n/=-2
print("0" if s=="" else s)