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):
n = int(input())
key = []
if n%2:
  key.append("1")
  n -= 1
else:
  key.append("0")

bef_p, bef_q = 0, 0
n //= 2
while n:
  k_p, k_q = (n//2)%2, n%2
  if k_p == 0:
    if k_q == 0:
      key.append("0")
      key.append("0")
      bef_p, bef_q = 0, 0
    else:       
      key.append("1")
      key.append("1")
      bef_p, bef_q = 0, 0      
  else:
    if k_q == 0:
      key.append("0")
      key.append("1")
      bef_p, bef_q = 0, 0
    else:
      key.append("1")
      key.append("0")
      bef_p, bef_q = 1, 1
  n //= 4
  n = n + bef_p*2-bef_q
key.reverse()
print(int("".join(key)))

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

def nega_binary(num):
    if num == 0:
        return 0
    res = []
    while num != 0:
        remainder = abs(num) % 2
        res.append(str(remainder))
        if num < 0 and remainder:
            num -= 1
        num = int(num / -2)
    return ''.join(reversed(res))

print(nega_binary(N))

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

Solution (Python):
N = int(input())
ans = [0] * 40
if N == 0:
    print(0)
    exit()
else:
    while N != 0:
        i = 1 if N < 0 else 0
        k = pow(-2, i)
        while abs(N) > abs(k):
            i += 2
            k += pow(-2, i)
        ans[i] = 1
        N -= pow(-2, i)

for j in range(39, -1, -1):
    if ans[j] == 1:
        print(''.join(map(str, reversed(ans[:j + 1]))))
        exit()

Solution (Python):
n=int(input())
s=0
k=0
ans=[]
if n==0:
  print(0)
while n!=0:
  if k%2==0:
    x=n%(2**(k+1))
    if x==0:
      ans.append('0')
    else:
      ans.append('1')
      n-=x
  else:
    x=n%(2**(k+1))
    if x==0:
      ans.append('0')
    else:
      ans.append('1')
      n+=x
  k+=1
print(''.join(ans)[::-1])

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

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

ans = []

while N :
    r = abs(N%2)
    ans.append(int(r))
    N = (N-r)//(-2)

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

Solution (Python):
n=int(input())
L=[]
cnt=0
while(n!=0):
    cnt+=1
    a=n%(2**cnt)
    b=(1 if a>0 else 0)
    L.append(b)
    n=n-(((-2)**(cnt-1))*b)
L=list(map(str,L))[::-1]
print("".join(L) if len(L)>0 else 0)

Solution (Python):
N=int(input())
if(N==0):
    print(0)
    exit()
res=''
while(N!=0):
    r=N%2
    if(r<0):
        r+=2
    res+=str(r)
    N=(N-r)//(-2)
print(res[::-1])

Solution (Python):



def main():
  n = int(input())
  s = 0
  ans = []
  for i in range(50):
    if (n - s) % (2**(i+1)) == 0:
      ans.append('0')
    else:
      ans.append('1')
      s += ((-2) ** i)
    if s == n:
      break
  print(''.join(ans[::-1]))
    
if __name__=='__main__':
  main()

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

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

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

ans = ''
while True:
    ans += str(n % 2)
    if(n < 0):
        n = (abs(n) + 1) // 2
    else:
        n = -1 * (n // 2)

    if(n == 1):
        ans += '1'
        break

print(ans[::-1])

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

if n==0:print(0);exit()
while n!=0:
    ans +=str(n%2)
    n=-(n//2)

print(ans[::-1])

Solution (Python):
from sys import exit

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

lst = []
i = 1
while N:
    n2 = N % 2
    lst.append(n2)
    N = (N - n2 * i) // 2
    i *= -1
print(''.join(map(str, reversed(lst))))

Solution (Python):

def submit():
    n = int(input())
    s = ""
    c = 0
    base = 1

    def check_mod(n, base, c):
        divider = -2 * base
        tmp = n % divider
        if tmp == c:
            return True
        else:
            
            return tmp - divider == c

    while c != n:
        if check_mod(n, base, c):
            s = "0" + s
        else:
            s = "1" + s
            c += base
        base *= -2

    if s:
        print(s)
    else:
        print("0")


if __name__ == "__main__":
    submit()

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

Solution (Python):
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def foo(n):
    h = {0:'0', 1:'1', -2:'10', -1:'11'}
    if n in h:
        ret = h[n]
        
        return ret
    r = n%4
    if r==0:
        s = '00'
        v = 0
    elif r==1:
        s = '01'
        v = 1
    elif r==2:
        s = '10'
        v = -2
    else:
        s = '11'
        v = -1
    ret = foo((n-v)//4) + s
    
    return ret

n = inn()
if n==0:
    print(0)
else:
    s = foo(n)
    for i in range(len(s)):
        if s[i]=='1':
            break
    print(s[i:])

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

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

Solution (Python):
from collections import deque
import sys
input = sys.stdin.readline
import bisect as bi
from operator import mul
from functools import reduce
import math

def main():
    n = int(input())
    n += 1 if n > 0 else -1
    
    s = ""
    while abs(n) > 1:
        c = "1" if n % 2 == 0 else "0"
        s = c+s 
        n = n // -2 + (0 if n > 0 else 1)

    print(0 if not s else s)
main()

Solution (Python):
n = int(input())
ans = []
while n!=0 and n!=1:
    ans.append((-n)%2)
    n = -(n//2)
ans.reverse()
ans = [n]+ans
ans = [str(n) for n in ans]
print(''.join(ans))

Solution (Python):
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def foo(n):
    h = {0:'0', 1:'1', -2:'10', -1:'11'}
    if n in h:
        ret = h[n]
        
        return ret
    r = n%4
    if r==0:
        s = '00'
        v = 0
    elif r==1:
        s = '01'
        v = 1
    elif r==2:
        s = '10'
        v = -2
    else:
        s = '11'
        v = -1
    ret = foo((n-v)//4) + s
    
    return ret

n = inn()
if n==0:
    print(0)
else:
    s = foo(n)
    for i in range(len(s)):
        if s[i]=='1':
            break
    print(s[i:])

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

if N == 0:
    print(0)
else:
    ans = ""
    while N != 0:
        digit = abs(N%(-2))
        ans += str(digit)
        N -= digit
        N //= -2

    for i in reversed(range(len(ans))):
        print(ans[i],end="")

Solution (Python):


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

if N == 0:
    ans_list=[0]
else:
    ans_list=[]

while N != 0:
    digit1 = abs( N%(-2) )
    ans_list += [digit1]
    N = (N - digit1) // (-2)
    
print( *ans_list[::-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):


def get_ans():
    n = int(input().rstrip())
    if n == 0:
        return "0"
    dv = 1
    bit_list = []
    while n != 0:
        tmp = n % (dv*2)
        if tmp == 0:
            bit_list.append("0")
        else:
            bit_list.append("1")
        n -= tmp
        dv *= -2
    return "".join(reversed(bit_list))


print(get_ans())

Solution (Python):
n = int(input())
 
ansl = []
if n == 0:
    print("0")
    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())
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())

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

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

        n /= (-2)

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
n = -int(input())
a = ""

while n:
    a+=str(n%2)
    n//=-2

print(a[::-1] if a else 0)

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

if n == 0:
    print(0)
    
else:
    a = []
    while n != 0:
        if n%2 == 0:
            a.append(0)
        else:
            a.append(1)
            n -= 1
        n//=(-2)
    
    print(''.join(map(str, a[::-1])))

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

def calculate2(n):
    arr = []
    for i in range(40):

        if n % (2**(i+1)) != 0:
            arr.append(1)
            n = n - ((-2) ** i)
        else:
            arr.append(0)
        if n == 0:
            break

    arr.reverse()
    return arr

result = calculate2(N)
result = "".join([str(s) for s in result])
print(result)

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

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

if __name__ == '__main__':
    main()

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

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

x = n

ans = []

if x == 0:
    print(0)
else:
    while  x != 0:
        ans.append(abs(x%(-2)))
        x = (x - ans[-1])/(-2)


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

    print()

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

Solution (Python):
N = int(input())
S =""
for i in range(100):
    if N==0:break
    if N%pow(2,i+1)!=0:
        S+="1"
        N-=pow(-2,i)
    else:S+="0"
print("0" if S=="" else S[::-1])

Solution (Python):
a = int(input(""))
list = []
if(a == 0):
    list.append(0)
while(a):
    if(a%(-2)==0):
        list.append(0)
        a//=-2
    elif(a%(-2)==-1):
        list.append(1)
        a -= 1
        a//=-2

list.reverse()
for i in list:print(i,end='')
print()

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

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

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

ans = []
t = 1
p = 1

while N!=0:
    if N%(p*2)!=0:
        ans.append(1)
    else:
        ans.append(0)

    N -= ans[-1]*p*t
    t *= -1
    p *= 2

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

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

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

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

print(ans[::-1])

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

    def to_bin(n):
        """
        n:10進数 -> 2進数
        """
        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 "".join(digits[::-1])

    print(to_bin(N))


if __name__ == '__main__':
    main()

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

ans = []
while N != 0:
    if N % 2 == 1:
        ans.append("1")
        N -= 1
    else:
        ans.append("0")
    N //= - 2

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

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

kp=-10
km=10
k=0
while not(km<=n and n<=kp):
    k=k+1
    km=-int(2*(4**k-1)/(4-1))
    kp=int((4**k-1)/(4-1))



n=n-km

v=""
for kk in range(k):
    np=n//4**(k-kk-1)
    n=n-np*4**(k-kk-1)
    if np==0:
        v=v+"10"
    elif np==1:
        v=v+"11"
    elif np==2:
        v=v+"00"
    elif np==3:
        v=v+"01"


if len(v)>0 and v[0]=="0":
    v=v[1:]
if len(v)>0:
    print(v)
else:
    print(0)

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

res = []
if N != 0:
    while N != 0:
        q, r = divmod(N, -2)

        if r in {0, 1}:
            N = q
        else:
            r = N - (-2) * (q + 1)
            N = q + 1
        res.append(r)
else:
    res.append(0)

print("".join(list(map(str, res[::-1]))))

Solution (Python):
N = int(input())
if N == 0:
    print('0')
else:
    ans = ''
    for i in range(100):
        if N == 0:
            break
        if abs(N) % (2**(i+1)) != 0:
            ans += '1'
            N -= (-2)**i
        else:
            ans += '0'

    print(ans[::-1])

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

if answer == '':
    answer = '0'

print(answer)

Solution (Python):
def main():
  n=int(input())
  ans=[]
  if n==0:
    print(0)
  while n!=0:
    s=n%2
    ans.append(s)
    if s==0:
      n//=(-2)
    else:
      n=(n-1)//(-2)
  ans=ans[::-1]
  print(''.join([str(bit) for bit in ans]))
if __name__=='__main__':
  main()

Solution (Python):
n=int(input())
t=[]
x=0
for i in range(60):
    y=((n-x)%(1<<(i+1)))*(-1)**i
    if y==(-2)**i:
        t+=['1']
        x+=(-2)**i
    else:
        t+=['0']
    if x==n:
        break
print(''.join(t)[::-1])

Solution (Python):
import math
n=int(input())
ans_rev=""
if n==0:
    print(0)
else:
    while n!=1:
        ans_rev+=str(abs(n%(-2)))
        n=math.ceil(n/(-2))
    ans_rev+="1"
    ans=ans_rev[::-1]
    print(ans)

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

Solution (Python):
LOWER, UPPER = range(2)
MAX_DIGIT = 33
n = 0
bounds = [0] * MAX_DIGIT
for digit in range(MAX_DIGIT):
    n = (n << 1) | (digit & 1)
    bounds[digit] = [-(n >> (digit & 1)), n >> (not (digit & 1))]

N = int(input())

answer = 0
n = (1 << digit) * (1 if MAX_DIGIT & 1 else -1)

while digit:
    answer <<= 1
    n = (-1) * n >> 1
    if bounds[digit][LOWER] <= N < bounds[digit - 1][LOWER] or \
        bounds[digit - 1][UPPER] < N <= bounds[digit][UPPER]:
        answer |= 1
        N -= n
    digit -= 1

print(format(answer, "b"))

Solution (Python):

N=int(input())
def X(N):
    x=N%2
    N_new=(N-x)//(-2)
    if N_new==0:
        return x
    return X(N_new)*10+x
print(X(N))

Solution (Python):
n = int(input())
if n == 0:
  print(0)
else:
  ans = ""
  now = 0
  while n:
    r = n % (2**(now+1))
    if r:
      ans = "1" + ans
      n -= (-2)**now
    else:
      ans = "0" + ans
    now += 1
  print(ans)

Solution (Python):

if __name__ == '__main__':
    N=int(input())
    if N==0:
        print(0)
    else:
        ans=[]
        while N:
            ans.append(str(N%2))
            N=-(N//2)
        ans.reverse()
        print("".join(ans))

Solution (Python):
n = int(input())
r = 100
s = [0] * (r+1)
w = 0
for i in range(r+1):
    mod = 2 ** (i+1)
    if n % mod == w % mod:
        s[i] = 0
    else:
        s[i] = 1
    w += s[i] * (-2)**i
    if w == n:
        break

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

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

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

Solution (Python):
n=int(input())
t=1
b=''
for i in range(len(bin(n))):
  if n%(2*t): b='1'+b; n-=t
  else: b='0'+b
  t*=-2
print(int(b))

Solution (Python):
from math import ceil, log

def main():
    n = int(input())
    if n == 0:
        print(0)
        return
    k = 2 * int(log(3 * n, 4)) + 1 if n > 0 else 2 * ceil(log((2 - 3 * n) // 2, 4))
    s = [0] * k
    while n:
        k = 2 * int(log(3 * n, 4)) if n > 0 else 2 * ceil(log((2 - 3 * n) // 2, 4)) - 1
        s[k] = 1
        n -= (-2)**k
    print(*s[::-1], sep="")

if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()

mi = 0; ma = 1
li = [[0,1]]
for i in range(1,10**6):
    tmp = (-2) ** i
    if tmp < 0: mi += tmp
    else: ma += tmp
    li.append([mi,ma])
    if mi <= n <= ma:
        c = i+1
        break

res = []
for i in range(c)[::-1]:
    tmp = n - (-2) ** i
    if i != 0:
        nexl,nexr = li[i-1]
        if nexl <= tmp <= nexr:
            res.append('1')
            n = tmp
        else: res.append('0')
        continue
    res.append('1') if n else res.append('0')
ans = int("".join(res))
print(ans)

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

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

Solution (Python):
from sys import stdin
n = int(stdin.readline().rstrip())
def num(n):
    if n == 0:
        return ""
    if n%2 == 0:
        return num(n//(-2)) + "0"
    else:
        return num((n-1)//(-2)) + "1"
if n == 0:
    print(0)
    exit()
print(num(n))

Solution (Python):
n = int(input())
s = []
i = 1
m = (n%2)
s.append(n%2)
while 1:
    if m == n:
        break
    if n%(2**(i+1)) == m or n%(2**(i+1))-2**(i+1) == m:
        s.append(0)
    else:
        s.append(1)
        m += (-2)**i
    i += 1

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

Solution (Python):
n = int(input())
if n == 0:
    print(0)
    exit()
flag = True
ans_str = ''
while True:
    if n == 1:
        ans_str = '1' + ans_str
        print(int(ans_str))
        exit()
    if n < 0 and (-n)%2 == 1:
        ans_str = '1' + ans_str
        n = -(n-1)//2
    elif n < 0 and (-n)%2 == 0:
        ans_str = '0' + ans_str
        n = -n//2
    elif n > 0 and n%2 ==1:
        ans_str = '1' + ans_str
        n = -(n//2)
    elif n > 0 and n%2 ==0:
        ans_str = '0' + ans_str
        n = -(n//2)

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

n2_lis=[1]
for i in range(1,mx):
    n2_lis.append(n2_lis[i-1]*(-2))

sum_p=[0]
sum_m=[0]
sp=0
sm=0
for num in n2_lis:
    if num > 0:
        sp+=num
    else:
        sm+=num
    sum_p.append(sp)
    sum_m.append(sm)

rg=[]
for i in range(mx):
    rg1=n2_lis[i] + sum_p[i]
    rg2=n2_lis[i] + sum_m[i]
    rg.append([min(rg1,rg2),max(rg1,rg2)])

ans=[]
for i in reversed(range(0,mx)):
    if rg[i][0] <= n and n <= rg[i][1]:
        ans.append(1)
        n-=n2_lis[i]
    else:
        ans.append(0)
ans = ''.join([str(n) for n in ans])
print(int(ans))

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

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

Solution (Python):
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue

read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines 

def SI():
    return int(readline())
def MI():
    return map(int, readline().split())
def MLI():
    return map(int, open(0).read().split())

inf = float("inf")


def main():
    N = SI()
    
    if N == 0:
        print(0)
    else:
        ret = ''
        cursor = 1
        devide = 2
        while N != 0:
            if N % devide == 0:
                ret = '0' + ret
            else:
                ret = '1' + ret
                N -= cursor
            cursor *= -2
            devide *= 2
        
        print(ret)

if __name__ == "__main__":
    main()

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

    def to_bin(n):
        """
        n:10進数 -> 2進数
        """
        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 "".join(digits[::-1])

    print(to_bin(N))


if __name__ == '__main__':
    main()

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

ans = []
while True:
    if n % 2 == 1:
        ans.append('1')
        n -= 1
    else:
        ans.append('0')
    n = n // (-2)
    if n == 0:
        break

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

Solution (Python):
s=int(input())
x=s
list=[]
for i in range(1000000000000000000):
    y=x%(-2)
    if y == -1:
        x = (x-1)//(-2)
        y = 1
    else:
        x=x//(-2)
    list.insert(0, y)
    if x == 0:
        print(*list, sep="")
        break

Solution (Python):
def main():
    target_number = int(input())
    answer = ""
    if target_number == 0:
        answer = "0"
    else:
        while abs(target_number) > 0:
            if target_number % 2:
                answer = "1" + answer
                target_number = (target_number - 1) // -2
            else:
                answer = "0" + answer
                target_number = target_number // -2
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    i = 0
    if not N:
        print(0)
        return
    ans = ""
    while N:
        if N>>i&1:
            ans += "1"
            N -= pow(-1,i%2==1) * 1<<i
        else:
            ans += "0"
        i+=1
    
    print(ans[::-1])
if __name__ == '__main__':
    main()

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

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

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

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

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

ans=[]
NN=10**7

for _ in range(NN):
    if (abs(N))%2==1:
        ans.append("1")
        N-=1
    else:
        ans.append("0")
    if N==0:
        break
    N=(abs(N)//2)*-1*(N//abs(N))
    
print(''.join(map(str, ans[::-1])))

Solution (Python):
import math
import sys

N = int(input())

ans = []
if N == 0:
  print(0)
  sys.exit()

while(N != 0):
  m = N % (-2)
  if m == -1:
    m = 1
  ans.insert(0, str(m))
  N = math.ceil(N / (-2))

print("".join(ans))

Solution (Python):
def minus2base(n):
    if n==0:
        return '0'
    elif n==1:
        return '1'
    elif n>1:
        k=1
        i=1
        a=n
        while a-k>=0:
            a=a-k
            if a==0:
                break
            k=4*k
            i=i+1
        if n-k>0:
            A='10'
            l=1
            j=1
            a=n-k
            while a-l>=0:
                a=a-l
                if a==0:
                    break
                l=l*4
                j=j+1
            m=i-j-1
            while m>0:
                A=A+'00'
                m=m-1
            return A+minus2base(n-k)
        elif n-k==0:
            i=0
            A='1'
            while k//4**i>1:
                A=A+'00'
                i=i+1
            return A
        else:
            A='1'
            l=2
            j=1
            a=n-k
            while 0>a+l:
                a=a+l
                l=l*4
                j=j+1
            m=i-j-1
            while m>0:
                A=A+'00'
                m=m-1
            return A+minus2base(n-k)
    else:
        k=2
        i=1
        a=n
        while 0>a+k:
            a=a+k
            k=4*k
            i=i+1
        if n+k<0:
            A='10'
            l=2
            j=1
            a=n+k
            while a+l<0:
                a=a+l
                l=l*4
                j=j+1
            m=i-j-1
            while m>0:
                A=A+'00'
                m=m-1
            return A+minus2base(n+k)
        elif n+k==0:
            i=0
            A='1'
            while k//4**i>1:
                A=A+'00'
                i=i+1
            return A[:-1]
        else:
            A='1'
            l=1
            j=1
            a=n+k
            while a-l>=0:
                a=a-l
                if a==0:
                    break
                l=4*l
                j=j+1
            m=i-j
            while m>0:
                A=A+'00'
                m=m-1
            return A+minus2base(n+k)
N=int(input())
print(minus2base(N))

Solution (Python):

import math
import heapq
import bisect
import numpy as np
from collections import Counter


N = int(input())
ans = ""
while N:
    ans = str(N&1)+ans
    N = -(N>>1)
print(ans if ans else 0)

Solution (Python):
import math
import sys
n=int(input())
ans=[]
syo=n
if n==0:
    print(0)
    sys.exit(0)
while syo!=0:
    zan=syo%-2
    if zan==-1:
        zan=1
    ans.insert(0,zan)
    syo=math.ceil(syo/-2)
for i in range(len(ans)):
    print(ans[i],end="")

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

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

if S=="":
    S="0"

print(S)

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())
if 0<= n < 2:
    print(n)
    exit()

bit = 2
i = 0
l,r = 0,1
rang = [(0,1)]
while n < l or r < n:
    i += 1
    bit *= -2
    if i % 2:
        l = bit+1 + r
    else:
        r = bit-1 + l
    rang.append((l,r))
    

ans = []

bit //= 2

while i >= 0:
    t = n - bit
    
    if rang[i][0] <= t <= rang[i][1]:
        ans.append('1')
        n = t
    else:
        ans.append('0')
    i -= 1
    bit //= -2
print(''.join(ans))

Solution (Python):
n=int(input())
s=""
while n:
    s=str(n&1)+s
    n=-(n>>1)
print(s if s else 0)

Solution (Python):
n=int(input())
deg=[0]*40
if n>=0:
    for i in range(32):
        if n>>i&1:
            if i%2==0:
                deg[i]+=1
                if deg[i]>=2:
                    deg[i+1]+=1
                    deg[i+2]+=1
                    deg[i]-=2
            else:
                deg[i]+=1
                deg[i+1]+=1
                if deg[i]>=2:
                    deg[i+1]-=1
                    deg[i]-=2
                if deg[i+1]>=2:
                    deg[i+2]+=1
                    deg[i+3]+=1
                    deg[i+1]-=2
        else:
            if i%2==0:
                if deg[i]>=2:
                    deg[i+1]+=1
                    deg[i+2]+=1
                    deg[i]-=2
            else:
                if deg[i]>=2:
                    deg[i+1]-=1
                    deg[i]-=2
                if deg[i+1]>=2:
                    deg[i+2]+=1
                    deg[i+3]+=1
                    deg[i+1]-=2
else:
    n*=-1
    for i in range(32):
        if n>>i&1:
            if i%2==1:
                deg[i]+=1
                if deg[i]>=2:
                    deg[i+1]+=1
                    deg[i+2]+=1
                    deg[i]-=2
            else:
                deg[i]+=1
                deg[i+1]+=1
                if deg[i]>=2:
                    deg[i+1]-=1
                    deg[i]-=2
                if deg[i+1]>=2:
                    deg[i+2]+=1
                    deg[i+3]+=1
                    deg[i+1]-=2
        else:
            if i%2==1:
                if deg[i]>=2:
                    deg[i+1]+=1
                    deg[i+2]+=1
                    deg[i]-=2
            else:
                if deg[i]>=2:
                    deg[i+1]-=1
                    deg[i]-=2
                if deg[i+1]>=2:
                    deg[i+2]+=1
                    deg[i+3]+=1
                    deg[i+1]-=2
deg.reverse()
l=39
for i in range(40):
    if deg[i]==1:
        l=i
        break
print(*deg[l:],sep="")

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

N = -N

if N == 0:
  print(0)
  exit()
  
t = []
while N != 0:
  s = N % -2
  if s == 0:
    t.append(0)
  else:
    t.append(1)
    
  N //= -2
  
t = list(reversed(t))
print(''.join(map(str, t)))

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

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