Problem:
 Score : 300 points    Problem Statement Given an integer N , find the base -2 representation of N .  Here, S is the base -2 representation of N when the following are all satisfied:   S is a string consisting of 0 and 1 .  Unless S =  0 , the initial character of S is 1 .  Let S = S_k S_{k-1} ... S_0 , then S_0 \times (-2)^0 + S_1 \times (-2)^1 + ... + S_k \times (-2)^k = N .   It can be proved that, for any integer M , the base -2 representation of M is uniquely determined.      Constraints  Every value in input is integer.  -10^9 \leq N \leq 10^9         Input Input is given from Standard Input in the following format:  N       Output Print the base -2 representation of N .        Sample Input 1 -9      Sample Output 1 1011  As (-2)^0 + (-2)^1 + (-2)^3 = 1 + (-2) + (-8) = -9 , 1011 is the base -2 representation of -9 .       Sample Input 2 123456789      Sample Output 2 11000101011001101110100010101       Sample Input 3 0      Sample Output 3 0

Solution (Python):
def main():
    n=int(input())
    ans=""
    while n!=0:
        ans = str(n%2) + ans
        n = -(n//2)
    if ans=="":
        print(0)
    else:
        print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n=int(input())
    ans=[]
    if n==0:
        print(n)
    else:
        while n!=0:
            ans.append(n%2)
            n = n//(-2) + n%abs(-2)
        for i in ans[::-1]:
            print(i,end="")
        print()
if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    L = [(0, 1), (-2, 1)]
    for leng in range(2, 17):
        min_v = (-2*(4**(leng+(2-1)//2) - 1))//3
        max_v = (4**(leng+(2-1)//2) - 1)//3
        L.append((L[-1][0], max_v))
        L.append((min_v, max_v))
    
    S = [(1, 1)]
    for leng in range(1, 32):
        if leng & 1:
            S.append((L[leng][0], L[leng-1][0]-1))
        else:
            S.append((L[leng-1][1]+1, L[leng][1]))
    
    ans = ["0"] * 32
    cnt = 31
    for le, ri in S[::-1]:
        if ri < le:
            le, ri = ri, le
        if le <= N <= ri:
            ans[cnt] = "1"
            N -= (-2)**cnt
        cnt -= 1
    print(int("".join(ans[::-1])))


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
if N == 0:
    print(0)
    exit()
bit = []
while N != 0:
    bit.append(str(abs(N % 2)))
    N = (N - N % 2) // (-2)
bit.reverse()
print("".join(bit))

Solution (Python):
N=int(input())
ans=""

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

print(ans)

Solution (Python):
n=int(input())
import math
i=0
ans=0
if n!=0:
  while n!=1:
    ans+=(n-math.ceil(n/(-2))*(-2))*(10**i)
    n=math.ceil(n/(-2))
    i+=1
  ans+=10**i
else:
  ans=0
print(ans)

Solution (Python):
n = int(input())
s = []
if n != 0:
    while abs(n) > 0:
        if n%2 != 0:
            s.append(str(-(n%(-2))))
            n = n//(-2) + 1
        else:
            s.append(str(-(n%(-2))))
            n = n//(-2) 
else:
    s = "0"
print("".join(s[::-1]))

Solution (Python):
n = int(input())
ans = ""

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

if ans == "":
    ans = "0"

print(ans)

Solution (Python):

from math import ceil, floor
n = int(input())


low = 0
high = 1
digit = 1

while True:
    if low <= n <= high:
        break

    if digit & 1:
        low += (-2) ** digit
    else:
        high += (-2) ** digit
    digit += 1

ans = ""
for i in range(digit, 0, -1):
    mid = (low + high) / 2
    if low <= n < mid:
        if i % 2 == 0:
            ans += "1"
        else:
            ans += "0"
        high = floor(mid) if mid > 0 else ceil(mid)
    else:
        if i % 2 == 0:
            ans += "0"
        else:
            ans += "1"
        low = ceil(mid) if mid > 0 else floor(mid)

print(ans)

Solution (Python):
number = int(input())

def to_bin(n):
    if n == 0:
        return [0]
    
    digits = []
    i = 0
    base = 1
    while n != 0:
        if n % (base * 2) == 0:
            digits.append('0')
        else:
            digits.append('1')
            n -= base
        i+= 1
        base *= -2
    return digits[::-1]

ans_list = to_bin(number)

for ans in ans_list:
    print(ans, end='')

Solution (Python):
N=int(input())
def f(x):
  
  i=0
  counter=0
  while counter<x:
    counter+=2**i
    i+=2
  return i-1

def g(x):
  k=f(x)
  out=[1]
  for i in range(k-1, 1, -1):
    out.append(h(x, i))
  if x%2==0:
    out.append(0)
  else:
    out.append(1)
  return out

def h(x, i):
  j=i//2
  b=sum([2**(2*k) for k in range(j)])
  if ((x-b-1)//(2**(i-1)))%2==0:
    return 1
  else:
    return 0
  
def e(n):
  
  n_=-n
  i=1
  while n_>2**i:
    i+=2
    
  return 2**i+n

if N>0:
  out=g(N)
  out=map(str, out)
  out="".join(out)
elif N<0:
  N_=-N
  k=N_//2+N_%2
  out=g(k)
  out.append(N_%2)
  out=map(str, out)
  out="".join(out)
else:
  out=0
  
print(out)

Solution (Python):
n = int(input())
ans = ''
for i in range(10000):
    
    if n % 2 == 0:
        ans = '0' + ans
    else:
        ans = '1' + ans
        n -= 1
    
    n //= -2
print(int(ans))

Solution (Python):
n = int(input())
ans = ''
for i in range(10000):
    if n % 2 == 0:
        ans = '0' + ans
    else:
        ans = '1' + ans
        n -= 1
    n //= -2

print(int(ans))

Solution (Python):
def main():
    n=int(input())
    ans=[]
    if n==0:
        print(0)
        return
    while n != 0:
        MOD=n%(-2)
        if MOD <0:
            MOD+=2
        ans.append(str(MOD))
        n=(n-MOD)//(-2)
    ans.reverse()
    print(''.join(ans))

if __name__=='__main__':
    main()

Solution (Python):
N=int(input())
if N==0:
    ans='0'
else:
    ans=''
    while N!=0:
        if N%2==1:
            ans='1'+ans
            N-=1
        else:
            ans='0'+ans
        N//=-2
print(ans)

Solution (Python):
n = int(input())
if n == 0:
    print(0)
    exit()
ans = []
while n:
    mod = n % 2
    n //= -2
    n += mod
    ans.append(mod)

ans = ans[::-1]
print(''.join(map(str, ans)))

Solution (Python):
import math

n=int(input())
s=""

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

Solution (Python):

import sys, math, itertools, heapq, collections, bisect, string, copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7
ans = []
count = 0; pro = 1

n=int(input())
if n==0:
    print(0)
    exit()
while n!=1:
    
    
    
    
    if n<0:
        if n%2==1:
            n=-(n-1)//2
            ans.append(1)
        else:
            n=-(n//2)
            ans.append(0)
    else:
        ans.append(n%2)
        n=-(n//2)
ans.append(1)
ans.reverse()
print(*ans,sep="")

Solution (Python):
N=int(input())


if N>=0:
  k=0
  while N>2**k:
    k+=2
else:
  k=1
  while N<-2*(2**(k-1)):
    k+=2

S=[0]*(k+1)
for i in range(k+1):
  if N%(-2)==-1:
    S[i]=1
    N-=1
  N//=-2
print(int("".join(reversed(list(map(str,S))))))

Solution (Python):
def judge(m,i):
    if m==1:
        return 1
    elif m>0:
        if m%(2**i)==0:
            return 0
        else:
            return 1
    else:
        m = -m
        if m%(2**i)==0:
            return 0
        else:
            return 1

def examC():
    n = I()
    N = copy.deepcopy(n)
    i = 0
    ans = []
    while(N!=0):
        cur = judge(N,i+1)


        N -=((-2)**i)*cur
        ans.append(cur)
        i +=1
    if not ans:
        ans = [0]
    print("".join(map(str,ans[::-1])))

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Solution (Python):

N = int(input())
ans = []

now = 1
while N != 0:
    if N%(abs(now)*2) == 0:
        ans.append("0")
    else:
        ans.append("1")
        N-=now
    
    now*=(-2)
    
if ans == []:
    print(0)
else:
    out = ""
    ans = ans[::-1]
    
    for a in ans:
        out+=a
        
    print(out)

Solution (Python):
import sys
from collections import deque

N = int(input())

ans = deque([])
if N == 0:
    print(0)
else:
    while N != 0:
        if N % -2 != 0:
            N -= 1
            ans.appendleft('1')
        else:
            ans.appendleft('0')
        N /= -2
    print(''.join(ans))

Solution (Python):
N =int(input())
now = 0
max_list = [1]
min_list = [0]

def show_binary(now_val , now_idx):
    
    if now_idx == 0:
        print(now_val,end = "")
        return
    if now_val == 0:
        print("0", end='')
        show_binary(now_val, now_idx - 1)
    elif now_idx % 2 == 1:
        if min_list[now_idx - 1] > now_val >= min_list[now_idx]:
            print("1" , end = "")
            show_binary(now_val - (-2) ** now_idx, now_idx - 1)
        else:
            print("0" , end = '')
            show_binary(now_val, now_idx - 1)
    else:
        if max_list[now_idx - 1] < now_val <= max_list[now_idx]:
            print("1" , end = "")
            show_binary(now_val - (-2) ** now_idx, now_idx - 1)
        else:
            print("0" , end = '')
            show_binary(now_val, now_idx - 1)

for i in range(1,35):
    
    if i % 2 == 1:
        min_list.append(min_list[-1] - 2 ** i)
        max_list.append(max_list[-1])
        if min_list[i-1] >= N >= min_list[i]:
            break
    
    else:
        min_list.append(min_list[-1])
        max_list.append(max_list[-1] + 2 ** i)
        if max_list[i-1] <= N <= max_list[i]:
            break



if 0 <= N <= 1:
    i = 0
show_binary(N,i)

Solution (Python):

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

Solution (Python):
N = int(input())
if N == 0:
    print(0)
    exit()

if N > 0:
    N_bin = bin(N)[2:]
else:
    N_bin = bin(-N)[2:]
ans = [s for s in N_bin]
ans.reverse()
ans.append('0')
ans.append('0')

if N >= 0:
    p = 1
else:
    p = 0
for i in range(len(ans)):
    if i % 2 == p:
        if ans[i] == '1':
            k = i
            while True:
                if ans[k+1] == '0':
                    ans[k+1] = '1'
                    break
                else:
                    ans[k+1] = '0'
                    k += 1
while ans[-1] == '0':
    ans.pop()

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

Solution (Python):
N = int(input())
lis = [0]*40
tmp = [2]+[2**(i*2) for i in range(1,23)]
rui = [0]
for t in tmp:
    rui.append(rui[-1]+t)
for i in range(40):
    if i==0:
        if N%2 == 1:
            lis[0]=1
    else:
        if (N-rui[(i+1)//2])%((2**i) *2) < 2**i:
            lis[i]=1


print(int("".join(map(str,reversed(lis)))))

Solution (Python):
from numpy import cumsum
N = int(input())
lis = [0]*40
tmp = [0,2]+[2**(i*2) for i in range(1,23)]
rui = cumsum(tmp)
for i in range(40):
    if i==0:
        if N%2 == 1:
            lis[0]=1
    else:
        if (N-rui[(i+1)//2])%((2**i) *2) < 2**i:
            lis[i]=1


print(int("".join(map(str,reversed(lis)))))

Solution (Python):
n = int(input())

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

minus = False
if n < 0:
    minus = True
    n *= -1

a = [int(x) for x in format(n, "050b")[::-1]] 
m = len(a)

for i in range(m):
    if a[i] and ((i % 2 and not minus) or (not i % 2 and minus)):
        a[i+1] += 1

for i in range(m):
    if a[i] == 2:
        a[i] = 0
        if a[i+1] >= 1:
            a[i+1] -= 1
        else:
            a[i+1] += 1
            a[i+2] += 1

ans = []
flg = False
for x in a[::-1]:
    if x == 1: flg = True
    if flg: ans.append(str(x))

print("".join(ans))

Solution (Python):
n = -2
N = int(input())
ans = 0
digit = 0
while N != 0:
    if N%2 == 0:
        N //= n
        digit += 1
    else:
        ans += 1*(10**digit)
        N = N//n + 1
        digit += 1
print(ans)

Solution (Python):
n = int(input())
if n == 0:
    print(0)
    exit()

ans = list()
while n != 0:
    ans.append(str((n%-2)*(-1)))
    if n % (-2) < 0:
        n = (n-1) // (-2)
    else:
        n = n // (-2)

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

Solution (Python):
n = int(input())
if n == 0:
    print(0)
    exit()

ans = list()
while n != 0:
    ans.append(str((n%-2)*(-1)))
    if n % (-2) < 0:
        n = n // (-2) + 1
    else:
        n = n // (-2)

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	n = INT()
	if n == 0:
		print(0)
		sys.exit()
		
	ans = []
	while n != 0:
		ans.append((n % (-2))*(-1))
		if n%(-2) < 0:
			n = n//(-2) + 1
		else:
			n = n//(-2)

	print(*ans[::-1], sep = '')


if  __name__=='__main__':
    main()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()

s = []
tmp = N
if N == 0:
	print(0)
	sys.exit()
while tmp != 1:
	s.append(str(-1*(tmp%(-2))))
	tmp = ceil(tmp/(-2))
s.append("1")
print("".join(s)[::-1])

Solution (Python):
N = int(input())
MOD=[]

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

for i in range(1,10**9):
    if 2**(i-3)>abs(N):
        break
    MOD.append(N%(2**i))

ans = []
def value(ans):
    buff=0
    for i,a in enumerate(ans):
        buff += a*((-2)**i)
    return buff

for i,mod in enumerate(MOD):
    divide = 2**(i+1)
    if value(ans) % divide == mod:
        ans.append(0)
    else:
        ans.append(1)

ans = list(reversed([str(i) for i in ans]))
while ans[0]=="0":
    ans.pop(0)
print("".join(ans))

Solution (Python):
N = int(input())

ans = ""

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

print(ans)

Solution (Python):
import sys
from collections import deque
input = sys.stdin.readline

N = int(input().strip())
ans = deque([])
if N == 0:
  print(0)
  exit()
while N != 0:
    if N % -2 != 0:
        N -= 1
        ans.appendleft('1')
    else:
        ans.appendleft('0')
    N /= -2

print(''.join(ans))

Solution (Python):
N = int(input())

def get_ans(x):
    if x == 0:
        return ['0']
    d = []
    i = 0
    div = 1
    while x != 0:
        if x % (div*2) == 0:
            d.append('0')
        else:
            d.append('1')
            x -= div
        i += 1
        div = div * (-2)
    return d

a = get_ans(N)
b = list(reversed(a))
ans = ''.join(b)
print(ans)

Solution (Python):
import sys
n = int(input())

ansl = []
if n == 0:
    print("0")
    sys.exit()
while n:
    if n % -2 == 0:
        ansl.append("0")
    else:
        n -= 1
        ansl.append("1")
    n = n // -2

ansl.reverse()
print("".join(ansl))

Solution (Python):
n = int(input())
s = []

if n%2 == 0:
	s.append(0)
else:
	s.append(1)
i = 1
nn = n - s[i-1]
while nn != 0:
	if nn%(2**(i+1)) == 0:
		s.append(0)
	else:
		s.append(1)
	nn -= s[i]*(-2)**i
	i += 1
s.reverse()
print("".join(map(str, s)))

Solution (Python):
def solve():
  n = int(input())
  if n == 0:
    print(0)
    exit()
  n *= -1
  ans = ""
  while n != 0:
    if n%2 == 1:
      ans = "1"+ans
    else:
      ans = "0"+ans
    n //= -2
  print(ans)
solve()

Solution (Python):
n = int(input())

num = -n
ans = ""


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

while num!= 0:
    if num % 2 == 0:
       ans = "0" + ans
    else:
        ans = "1" + ans
    num //= (-2)
    
    
print(ans)

Solution (Python):
n = int(input())

num = -n
ans = []


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

while num!= 0:
    if num == 1:
        ans.append(11)
        break
    if num == -1:
        ans.append(1)
        break
    if num % (-2) == 0:
       ans.append(0)
    else:
        ans.append(1)
    num //= (-2)
    
    
print(*ans[::-1],sep='')

Solution (Python):
n = int(input())
x = ""
while n!=0:
  x = str(n%2)+x
  n = -(n//2)
print(0 if x=="" else x)

Solution (Python):
n = int(input())

ans = ""
while n:
    if n % 2:
        ans += "1"
        n -= 1
    else:
        ans += "0"
    n //= -2
if not ans:
    ans = "0"
print(ans[::-1])

Solution (Python):
N = int(input())
if N==0:
    print(0)
    exit()

sign = 1
S = []
while N!=0:
    S.append(N%2)
    N = (N - S[-1]*sign)//2
    sign *= -1

print(''.join(map(str, reversed(S))))

Solution (Python):
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
























def main():
	n=int(input())
	ans=[]
	
	if n==0:
		print(0)
		exit(0)
	
	while True:
		if -1<n<1:
			break
		elif n%(-2)==-1:
			ans.append(1)
			n=n//(-2)+1
		elif n%(-2)==1:
			ans.append(1)
			n=n//(-2)
		else:
			ans.append(0)
			n //= (-2)
	ans=ans[::-1]
	ans="".join(map(str,ans))
	
	print(ans)
	
	

if __name__ == '__main__':
	main()

Solution (Python):


N=int(input())

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

high=[2**(2*i)  for i in range(16)]
low=[-2**(2*i+1) for i in range(16)]
hh=[]
ll=[]
sum_h=0
sum_l=0
for i in range(16):
    sum_h+=high[i]
    sum_l+=low[i]
    hh.append(sum_h)
    ll.append(sum_l)

    
flag=True
while N!=0:
    
    if N>0:
        for index,item in enumerate(hh):
            if N-item<=0:
                if flag:
                    l=[0]*(2*index+1)
                    flag=False
                l[-2*index-1]=1
                N-=high[index]
                break
    else:
        for index,item in enumerate(ll):
            if N-item>=0:
                if flag:
                    l=[0]*(2*index+2)
                    flag=False
                    length=len(l)
                l[-2*index-2]=1
                N-=low[index]
                break

print("".join(list(map(str,l))))
"""
print(high)
print(low)
print(hh)
print(ll)
"""

Solution (Python):
N = int(input())

L = [[0,1]]
i = 1
while True:
	d = (-2) ** i
	if d < 0:
		L.append([L[-1][0]+d,L[-1][1]])
	else:
		L.append([L[-1][0],L[-1][1]+d])

	a,b = L[-1]
	if a <= N <= b:
		break

	i += 1
		
ans = []
tmp = N
for i in reversed(range(len(L))):
	if i == 0:
		if tmp == 1:
			ans.append("1")
		else:
			ans.append("0")
		break

	add = (-2) ** i
	a,b = L[i]
	c,d = L[i-1]
	if a == c:
		if d < tmp <= b:
			ans.append("1")
			tmp -= add
			continue
	elif b == d:
		if a <= tmp < c:
			ans.append("1")
			tmp -= add
			continue

	ans.append("0")

if ans[0] == "0":
	ans.pop(0)

print("".join(ans))

Solution (Python):

N = int(input())

if N == 0:
    print(0)

else:
    buf = []
    base = 2
    while N != 0:
        buf.append(N % base)
        N = -(N // base)

    print(''.join(reversed(list(map(str, buf)))))

Solution (Python):
n = int(input())


def F2(n):
    if n // 2 == 0:
        return str(n % 2)
    return F2(-(n // 2)) + str(n % 2)


print(F2(n))

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    if n == 0:
        print(0)
    else:
        ans = []
        while n:
            if n % -2 == 0:
                ans.append("0")
                n //= -2
            else:
                ans.append("1")
                n //= -2
                n += 1
        ans.reverse()
        print("".join(ans))


if __name__ == '__main__':
    solve()

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    if n == 0:
        print(0)
    else:
        ans = []
        while n:
            if n % -2 == 0:
                ans.append("0")
                n //= -2
            else:
                ans.append("1")
                n //= -2
                n += 1
        ans.reverse()
        print("".join(ans))


if __name__ == '__main__':
    solve()

Solution (Python):
S = int(input())

num = ''
def division(N):
  if N%2==0:
    return N//-2,'0'
  else:
    return (N//-2)+1,'1'
  
  
if S==0:
  print(0)
else:
  while S!=0:
    a,b = division(S)
    num += b
    S = a
  print(num[::-1])

Solution (Python):
N = int(input())
if (N==0):
    print(0)
    exit()
ans = ''
while(N!=0):
    if (N%2):
        N -= 1
        ans = '1' + ans
    else:
        ans = '0' + ans
    N = N // -2
print(ans)

Solution (Python):




import sys















def baseConvert(n, base):
    if n == 0:
        return ''
    else:
        for i in range(abs(base)):
            if n % abs(base) == i:
                return baseConvert((n - i) // base, base) + str(i)
 
def main():
    n = int(sys.stdin.readline().rstrip())
    base = -2
    
    if n == 0:
        ans = '0'
    else:
        ans = baseConvert(n, base)
    print(ans)

if __name__ == "__main__":
    
    main()

Solution (Python):
-9




import sys

import math













def f(n):
    if n == 0:
        return ''
    else:
        if n % 2 == 0:
            return f(n // (-2)) + '0'
        else:
            return f((n - 1) // (-2)) + '1'
    
 
def main():
    n = int(sys.stdin.readline().rstrip())
    
    if n == 0:
        ans = '0'
    else:
        ans = f(n)
    print(ans)
    





if __name__ == "__main__":
    
    main()

Solution (Python):
n = int(input())
if n == 0:
    print(0)
    exit()
ans = ""
while n != 0:
    if n % (2) == 0:
        n = n // (-2)
        ans = "0" + ans
    else:
        n = (n - 1) // (-2)
        ans = "1" + ans
print(ans)

Solution (Python):
n = int(input())

pl = [int(((4**i) - 1)/3) for i in range(1,20)]
mi = [int(-2 * ((4**i) - 1)/3) for i in range(20,0,-1)]
plli = [int(4 ** i) for i in range(20)]
mili = [int(-2 * (4**i)) for i in range(19,-1,-1)]
li = []

import bisect

def func(n):
    if n == 0:
        return None
    elif n > 0:
        inde = bisect.bisect_left(pl,n)
        li.append(2*inde + 1)
        m = n-plli[inde]
        func(m)
    else:
        inde = bisect.bisect_right(mi,n)
        li.append((20 - inde + 1) * 2 )
        m = n-mili[inde-1]
        func(m)

if n == 0:
    print(0)
else:
    func(n)
    lis2 = []
    for i in range(li[0]):
        lis2.append("0")
    for a in li:
        lis2[-a] = "1"
    st = "".join(lis2)
    print(st)

Solution (Python):
def conv(s):
    s = list(s)
    s.reverse()
    ret = 0
    for i in range(len(s)):
        ret += int(s[i]) * (-2)**i
    return ret

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

s = ''
d = 2
while abs(n) > 0:
    if n % d == 0:
        s = '0' + s
    else:
        s = '1' + s
    n -= conv(s[0]+'0'*(len(s)-1))
    d *= 2

print(s)

Solution (Python):
Z = int(input())

if Z == 0:
  print(0)

else:
  n = (-2)

  ans = ""

  while abs(Z) >= 1:
    r = Z % n
    if r < 0:
      r = r + 2
    Z = int((Z - r) / n)
    ans += str(r)

  ans = "".join(list(reversed(ans)))


  print(int(ans))

Solution (Python):
n = int(input())

ttl = n
ans = []

memo = -2
memo2 = 1

while(abs(ttl)>0):
    if ttl%memo != 0:
        ttl -= memo2
        ans.append(1)
    else:
        ans.append(0)

    memo *= (-2)
    memo2 *= (-2)

if n == 0:
    print(0)
else:
    for i in range(1,len(ans)+1):
        print(ans[-i],end = "")
    print()

Solution (Python):
n=int(input())

l=list()
c=0
if n==0:
  l.append(0)
while n!=0:
  if n%2:
    l.append(1)
    n -= -1 if c%2 else 1
  else:
    l.append(0)
  n //= 2
  c += 1

for i in reversed(l):
  print(i, end='')

print()

Solution (Python):
N = int(input())
ans = ''
if N == 0:
    ans = '0'
else:
    while N != 0:
        if N%2 == 1:
            N -= 1
            ans += '1'
        else:
            ans += '0'
        N /= -2
print(ans[::-1])

Solution (Python):

N = int(input())

rest = N
i = 0
ans_l = []

while not rest == 0:
    if rest % (-2)**(i+1) == 0:
        ans_l.append('0')
    else:
        ans_l.append('1')
        rest -= (-2)**i
    i += 1


ans = ''.join(ans_l[::-1])
if N == 0:
    ans = 0

print(ans)

Solution (Python):
N = int(input())

if N == 0:
    print(0)
    exit()
else:
    ans = ""
    while N != 0:
        if N % 2 == 1:
            ans = "1" + ans
            if N > 0:
                N = (N // 2) * (-1)
            else:
                N = N // (-2) + 1
        else:
            ans = "0" + ans
            N = N // (-2)

print(ans)

Solution (Python):
n=int(input())
s=""
while n: 
    rem=n%(-2)
    n=n//(-2)
    if(rem<0):
        rem+=2 
        n+=1 
    s=str(rem)+s 
print(s if s else "0")

Solution (Python):
def F(N):
    if N == 0:
        return ''
    if N % 2 == 0:
        return F(N//-2) + '0'
    return F((N-1)//-2) + '1'

N = int(input())
answer = F(N)
if N == 0:
    answer = 0
print(answer)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
res = [N % 2]
for i in range(1, N.bit_length() * 2):
  t = N % pow(2, i + 1)
  u = 0
  for j in range(i):
    u += res[j] * pow(-2, j)
  if u % pow(2, i + 1) == t:
    res.append(0)
  else:
    res.append(1)
res.reverse()
rres = ""
f = 1
for i in range(len(res)):
  if f and res[i] == 0:
    continue
  if f and res[i]:
    f = 0
  rres += str(res[i])
if rres == "": print(0)
else: print(rres)

Solution (Python):
n=int(input())
if n==0:
    print(0)
    exit()
ans=str("")
while(n!=0):
    r=n%2
    if r<0:
        r+=2
    n=(n-r)//(-2)
    ans=str(r)+ans
print(ans)

Solution (Python):
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)

Solution (Python):



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

    a = []
    while n!= 0:
        r = n % 2

        
        if (r < 0):
            r += 2

        n = (n - r)//(-2)
        a.append(r)
        
    if a == []:
        a.append(0)
        
    a.reverse()

    
    print("".join(map(str,a)))


if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())

def f(n):
    if n==0:
        return ""
    if n%2==0:
        return f(n//(-2))+"0"
    return f((n-1)//(-2))+"1"

if n==0:
    print(0)
else:
    print(f(n))

Solution (Python):
n = int(input())
s = ''
while n!=0:
    s = str(n%2)+s
    n = -(n//2)
print(0 if s=='' else s)

Solution (Python):
n = int(input())

def basen(n):
    a = []
    while n!= 0:
        r = n % 2
        if (r < 0):
            r += 2

        n = (n - r)//(-2)
        a.append(r)
    if a == []:
        a.append(0)
    a.reverse()
    return "".join(map(str,a))
print(basen(n))

Solution (Python):
import sys
n=int(input())
if n==0:
    print(0)
    sys.exit()
ans=""
for i in range(2**31):
    a=(-2)**i
    if (n//a)%2==1:
        ans="1"+ans
        n-=a
        if n==0:
            print(ans)
            break
    else:
        ans="0"+ans

Solution (Python):

def main():
    N = int(input())
    ans = ""
    while N != 0:
        r = N % 2
        r += 2 if r < 0 else 0
        N = (N - r) // -2
        ans += str(r)
    print(ans[::-1] if ans else 0)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
res = ""
cnt = 0
div = 0
if n == 0:
    print(0)
else:
    while n != 0:
        div = n % 2**(cnt+1)
        div = 1 if div > 0 else 0
        res = str(div) + res
        if div > 0:
            n -= (-2) ** cnt
        cnt += 1
    print(res)

Solution (Python):
n = int(input())
ans = ""
for i in range(10**5):
  if n % 2 ** (i + 1) != 0:
    n -= (-2) ** i
    ans = "1" + ans
  else:
    ans = "0" + ans
  if n == 0:
    break
print(ans)

Solution (Python):
n=int(input())
x=""
while n!=0:
    x=str(n%2)+x
    n=-(n//2)
print(0 if x=="" else x)

Solution (Python):
N = int(input().strip())

ans = []

while abs(N) > 0:
    ans.append(abs(N) % 2)
    N = (N // 2) * -1

if not len(ans):
    ans = [0]

[print(i, end='') for i in ans[::-1]]
print('')

Solution (Python):
N = int(input())
ans = ''
t = 0
count = 1
if N==0:
  ans = '0'
while N!=0:
  if N%(2**count)==0:
    ans += '0'
  else:
    ans += '1'
    N -= (-2)**(count-1)
  count += 1
print(ans[::-1])

Solution (Python):
N=int(input())
A=''

while N!=0:
    A=str(N%2)+A
    N=-(N//2)

print(A if A!='' else '0')

Solution (Python):
n = int(input())
x = ''

while n!=0:
  x = str(n%2) + x
  n = -(n//2)

print(0 if x == '' else x)

Solution (Python):
n = int(input())

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

if s:
    print(''.join(map(str, reversed(s))))
else:
    print(0)

Solution (Python):
n=int(input())
if n == 0:
    print(0)
s = ""

while n != 0:
    if n%2 == 0:
        
        s = "0" + s
    elif n%2 == 1:
        n -= 1
        s = "1" +s
    n = (n//-2)

print(s)

Solution (Python):
n = int(input())
dp = [2**i if i % 2 == 0 else -2**i for i in range(32) ]

if n < 0 :
    plus_minus = 1
elif n > 0:
    plus_minus = 0
else:
    print(0)
    exit()

a = 0
for i in range(plus_minus,32,2):
    if abs(dp[i]) + abs(a) > abs(n):break
    a += dp[i]
s = "1"

if plus_minus == 1:
    b = dp[i]
    for j in range(i-1,-1,-1):
        if j % 2 == 0:
            if (b + dp[j]) + a <= n:
                s += "1"
                b += dp[j]
            else: s += "0"
        else:
            a -= dp[j]
            if b + a > n:
                s += "1"
                b += dp[j]
            else:
                s += "0"

else:
    b = dp[i]
    for j in range(i-1,-1,-1):
        if j % 2 == 1:
            if (b + dp[j]) + a >= n:
                s += "1"
                b += dp[j]
            else: s += "0"
        else:
            a -= dp[j]
            if b + a < n:
                s += "1"
                b += dp[j]
            else:
                s += "0"
print(s)

Solution (Python):
import math
import sys

n = int(input())
if n == 0:
  print(0)
  sys.exit()
  
keta = 0
under = 0
s = ""
nn = 1

if n > 0:
    while True:
      if sum([2**i for i in range(0,nn,2)])+1<= n and n <= sum([2**i for i in range(0,nn+1,2)]):
          keta = nn+1
          under = sum([2**i for i in range(0,nn,2)])
          break
      else:
          nn+=1

    for i in range(1,keta):
        remainder = (n-under)%(2**i)
        if remainder in range(1,2**(i-1)+1):
            s += "0" if i%2==1 else "1"
        else:
            s += "1" if i%2==1 else "0"
    else:
        s+="1"
    print(s[::-1])

else:
    while True:
        if n <= sum([(-2)**i for i in range(1,nn,2)]) and n >= sum([(-2)**i for i in range(1,nn+1,2)]):
            keta = nn+1
            under = sum([(-2)**i for i in range(1,nn,2)])
            break
        else:
            nn+=1

    for i in range(1,keta):
        remainder = abs(n-under)%(2**i)
        if remainder in range(1,2**(i-1)+1):
            s += "1" if i%2==1 else "0"
        else:
            s += "0" if i%2==1 else "1"
    else:
        s+="1"
    print(s[::-1])