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



Sample input:
-9


Sample output:
1011

Submission status: Runtime Error

Solution code:
import math
n = int(input())
if n == 0:
    print(0)
else:
    base = math.floor(math.log2(abs(n)))
    res = ""
    for i in range(base+1, -1, -1):
        if i % 2 == 0:
            if -(-2)**(i-1) <= n <= -(-2) ** (i+1):
                res += "1"
                n -= (-2) ** i
            else:
                res += "0"
        else:
            if -(-2)**(i-1) >= n >= -(-2) ** (i+1):
                res += "1"
                n -= (-2) ** i
            else:
                res += "0"
    if res[0] == "0":
        print(res[1:])
    else:
        print(res)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
nn = math.floor(math.log2(abs(n)))
keta = 0
under = 0
s = ""

if n > 0:
    if 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)])
    else:
        keta = nn+3
        under = sum([2**i for i in range(0,nn+1,2)])

    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])

elif n < 0:
    if 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-1,2)])
    else:
        keta = nn+3
        under = sum([(-2)**i for i in range(1,nn+1,2)])
    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])

else:
    print(0)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
nn = math.floor(math.log2(abs(n)))
keta = 0
under = 0
s = ""

if n > 0:
    if 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)])
    else:
        keta = nn+3
        under = sum([2**i for i in range(0,nn+1,2)])

    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])

elif n < 0:
    if n >= sum([(-2)**i for i in range(1,nn+1,2)]):
        keta = 2*(nn)
        under = sum([(-2)**i for i in range(1,nn-1,2)])
    else:
        keta = 2*(nn+1)
        under = sum([(-2)**i for i in range(1,nn+1,2)])
    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])

else:
    print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
for i in range(2**n):
    a = list(format(i,'b'))[::-1]
    
    summ = 0
    for index,aa in enumerate(a):
        summ += int(aa)*((-2)**index)

    if summ == n:
        print(format(i,'b'))
        break

Submission status: Runtime Error

Solution code:
n = int(input())

ans = ""
while n != 0:
    ans = str(n % 2) + ans
    n = - (n // 2)
if "" == ans:
    ans = 0
print("".join(map(str, ans)))

Submission status: Runtime Error

Solution code:
invtwos = [1]
i = 0
while abs(invtwos[i]) <= 10**9:
    invtwos.append(invtwos[i]*(-2))
    i += 1
invtwos.append(invtwos[-1]*(-2))

n = int(input())
ans = []
i = 0
while n != 0:
    if n%abs(invtwos[i+1]) != 0:
        ans.append(1)
        n -= invtwos[i]
    else:
        ans.append(0)
    i += 1
ans.reverse()
for i in range(len(ans)):
    if i != len(ans)-1:
        print(ans[i],end="")
    else:
        print(ans[i])

Submission status: Runtime Error

Solution code:
from collections import deque
n = int(input())
ans = deque([])
while n > 0:
    if n % 2 == 0:
        ans.appendleft(0)
    else:
        ans.appendleft(1)
    n = n // 2
print("".join(ans))

Submission status: Runtime Error

Solution code:
n=int(input())
if n==0:
  print('0')
else:
  ls=[]
  while(n!=0):
    ls.append(n%2)
    n=-1*(n-n%2)//2
ls.sort(reverse:True)
print(ls)

Submission status: Runtime Error

Solution code:
N=int(input())
ans=[]
t=N
while t != 0:
    if t%(-2)==0:
        ans.append('0')
        t //= -2
    else:
        ans.append('1')
        t=(t-1)//(-2)
        
ans = rereversed(ans)
print(''.join(ans))

Submission status: Runtime Error

Solution code:
N=int(input())
ans=[]
t=N
while t > 0:
    if t%(-2)==0:
        ans.append('0')
        t //= -2
    else:
        ans.appappend('1')
        t=(t-1)//(-2)
        
print(''.join(reversed(ans)))

Submission status: Runtime Error

Solution code:
def sigma4jou(k):
    total = 0
    for i in range(k):
        total += 4 ** (i)
    return(total)

def pketa(N):
    k = 1
    while N - sigma4jou(k) > 0:
        k += 1
    return(2 * k - 1)

def mketa(N):
    k = 1
    while N + 2 * sigma4jou(k) < 0:
        k += 1
    return(2 * k)

def getResult(N):
    result = ""
    if N == 0:
        result += "0"
    elif N > 0:
        k = pketa(N)
        for i in range(k, 0, -2):
            j = int((i+1)/2)
            if abs((sigma4jou(j) - N) // (2 ** (i-1))) % 2 == 0:
                result += "1"
            else:
                result += "0"
            if i > 1:
                if abs(((sigma4jou(j) - N)) // (2 ** (i-2))) % 2 == 1:
                    result += "1"
                else:
                    result += "0"
    elif N < 0:
        k = mketa(N)
        for i in range(k, 0, -2):
            j = int(i/2)
            if abs((N + 2 * sigma4jou(j)) // (2 ** (i-1))) % 2 == 0:
                result += "1"
            else:
                result += "0"
            if i > 1:
                if abs(((N + 2 * sigma4jou(j))) // (2 ** (i-2))) % 2 == 1:
                    result += "1"
                else:
                    result += "0"
    return(result)

N = input()
print(getResult(N))

Submission status: Runtime Error

Solution code:
x

Submission status: Runtime Error

Solution code:
n = int(input())
s = []
div = -2
i = 0
while n!=0:
    r = n % div
    if r == 0:
        s.append(0)
    else:
        s.append(1)
        n -= (-2) ** i
    div *= 2
    i += 1
ans = ""
for i in range(len(s)):
    ans =  str(s[i]) + ans
if n != 0
    print(ans)
else:
    print(0)

Submission status: Runtime Error

Solution code:
N = int(input())
base = ""
d = 0
while N != 0:
    if N%2 == 0:
        base += "0"
        N = N//2
    else:
        base += "1"
        if d%2 == 0:
            N = (N-1)//2
        else:
            N = (N+1)//2
    d += 1
print(int(base[::-1]))

Submission status: Runtime Error

Solution code:
import math
N = int(input())

def order2(x):
  if x > 0 :
    k = 0
    check = 0
    while check == 0 :
      s = 0
      for i in range(0, k+1, 2):
        s += (-2)**i
        ans = i
      if s >= x:
        check = 1
      k += 2
  elif x < 0 :
    k = 1
    check = 0
    while check == 0 :
      s = 0
      for i in range(1, k+1, 2):
        s += (-2)**i
        ans = i
      if s <= x:
        check = 1
      k += 2
  return ans

if N!= 0 :


  l = [] 
  a = N
  i = order2(N)
  while i >= 0:
    if a == 0 :
      l.append(0)
    if a > 0 and (-2)**i >0 :
        s = 0
        for j in range(0, i, 2):
          s += (-2)**j
        print(a,s)
        if a > s :
          l.append('1')
          a -= (-2)**i
        else :
          l.append('0')
    elif a > 0 and (-2)**i < 0:
        l.append('0')
    elif a < 0 and (-2)**i > 0:
        l.append('0')
    elif a < 0 and (-2)**i < 0:
        s = 0
        for j in range(1, i, 2):
          s += (-2)**j
        if a < s :
          l.append('1')
          a -= (-2)**i
        else :
          l.append('0')
    i -= 1

  print(''.join(l))

else :
  print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
tmp = 1
lipos = [1]
while tmp<10**9:
  tmp *= 4
  lipos.append(lipos[-1]+tmp)
#print(lipos)
tmp = -2
lineg = [-2]
while tmp > - 10**9:
  tmp *= 4
  lineg.append(lineg[-1]+tmp)
#print(lineg)
if n == 0:
  print("0")
elif n == 1:
  print("1")
elif n == -1:
  print("10")
elif n > 0:
  flag = True
  i = 0
  while flag:
    if lipos[i] < n <= lipos[i+1]:
      k = i+1
      flag = False
    i += 1
  diff = lipos[k]-n
  print(bin(lipos[k]^diff)[2:])
else:
  flag = True
  i = 0
  if lineg[i] > n >= lineg[i+1]:
    k = i+1
    flag = False
  i += 1
  diff = n-lineg[k]
  print(bin((-lineg[k])^diff)[2:])

Submission status: Runtime Error

Solution code:
n = int(input())
tmp = 1
lipos = [1]
while tmp<10**9:
  tmp *= 4
  lipos.append(lipos[-1]+tmp)
#print(lipos)
tmp = -2
lineg = [-2]
while tmp > - 10**9:
  tmp *= 4
  lineg.append(lineg[-1]+tmp)
#print(lineg)
if n == 0:
  print("0")
elif n == 1:
  print("1")
elif n == -1:
  print("10")
elif n > 0:
  flag = True
  i = 0
  while flag:
    if lipos[i] < n <= lipos[i+1]:
      k = i+1
      flag = False
    i += 1
  diff = lipos[k]-n
  print(bin(lipos[k]^diff)[2:])
else:
  flag = True
  i = 0
  if lineg[i] > n > lineg[i+1]:
    k = i+1
    flag = False
  i += 1
  diff = n-lineg[k]
  print(bin((-lineg[k])^diff)[2:])

Submission status: Runtime Error

Solution code:
n = int(input())
bin_n = bin(n)
ranges = []

def base_minus2(m, i, s):
    tmp = s
    if i == 1:
        return tmp + str(m%2)
    for j in range(i-1, -1, -1):
        if m >= ranges[j-1][0] and m <= ranges[j-1][1]:
            tmp += "1"
            return base_minus2(m-(-2)**j, j, tmp)
        else:
            tmp += "0"

if n == 0:
    print("0")
elif n == 1:
    print("1")
else:
    for i in range(1, 30):
        min_r = sum([(-2)**j for j in range(1, i, 2)]) + (-2)**i
        max_r = sum([(-2)**j for j in range(0, i, 2)]) + (-2)**i
        ranges.append([min_r, max_r])

    result = base_minus2(n, 30, "")
    print(result.lstrip("0"))

Submission status: Runtime Error

Solution code:
n = int(input())
bin_n = bin(n)
ranges = []

def base_minus2(m, i, s):
    tmp = s
    if i == 1:
        return tmp + str(m%2)
    for j in range(i-1, -1, -1):
        if m >= ranges[j-1][0] and m <= ranges[j-1][1]:
            print(ranges[j-1], j)
            tmp += "1"
            print(tmp)
            return base_minus2(m-(-2)**j, j, tmp)
        else:
            tmp += "0"

if n == 0:
    print("0")
elif n == 1:
    print("1")
else:
    for i in range(1, 30):
        min_r = sum([(-2)**j for j in range(1, i, 2)]) + (-2)**i
        max_r = sum([(-2)**j for j in range(0, i, 2)]) + (-2)**i
        ranges.append([min_r, max_r])

    result = base_minus2(n, 30, "")
    print(result.lstrip("0"))

Submission status: Runtime Error

Solution code:
from math import log
n = int(input())
s = ""

for i in range(int(log(abs(n),2))+3):
    #print("i=",i)
    if n % 2**(i+1) == 2**i:
        s = "1" + s
        n -= (-2)**(i)
        #print(i,n)
    else:
        s = "0" + s
if "1" in s:
    for j in s[s.find("1"):]:
        print(j,end = "")
else:
    print(0)

Submission status: Runtime Error

Solution code:
N = int(input())

ans = ''
while N != 0:
    r = N % 2
    N = (N - r) / (-2)
    ans += r

ans[::-1]
if N == 0:
    ans = '0'
    
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
if N == 0:
    print(0)
else:
    li = []
    ind = 0
    while N != 0:
        if N % 2**(ind + 1) == 0:
            li.insert(0,0)
            ind += 1
        else:
            li.insert(0,1)
            N -= (-2)**(ind)
            ind += 1            
x = ''.join([str(li[i]) for i in range(len(li))])
print(x)

Submission status: Runtime Error

Solution code:
n = int(input())

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

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

print(s[::-1])

Submission status: Runtime Error

Solution code:
N = int(input())

S = str()
count = 1
memo = 0
while a:
    amari = N%(2 ** count)
#    print ('amari', amari)
    if (amari- memo) == 2 ** (count-1):
        s = 1
    else:
        s = 0
    memo = memo + s * (-2) **(count-1)
#    print ('momo', memo)
    S = str(s) + S
    count += 1
    if memo == N:
        print (S)
        a = not a

Submission status: Runtime Error

Solution code:
n=int(input())
absn=abs(n)
sign=[1,-1]

b,cnt=1,0
while b<absn*2:
    b*=2
    cnt+=1
ans=[]
while cnt >= 0:
    sub=n-b*sign[cnt%2]
    if abs(sub)<abs(b) or abs(sub)<=abs(n):
        ans.append("1")
        n=sub
    else:
        ans.append("0")
    b//=2
    cnt-=1
for i in range(3):
    if ans[i]=="1":break
print("".join(ans[i::]))

Submission status: Runtime Error

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

    else:
        ans+="0"
        N//=(-2)

print(ans[::-1])

Submission status: Runtime Error

Solution code:
N = int(input())
str = ''

while(N != 0):
    if N % 2:
        N -= 1
        N //= -2
        str += '1'
    else:
        N //= -2
        str += '0'
        
if str = '':
    print(0)
else:
    print(str[::-1])

Submission status: Runtime Error

Solution code:
n=int(input())
ans,i="",0
while n!=0:
  if (n-(-2)**i)%((-2)**(i+1))==0:ans="1"+ans;n-=(-2)**i
  else:ans="0"+ans
  i+=1
print(int(ans))

Submission status: Runtime Error

Solution code:
N = int(input())

# 1, -2, 4, -8, 16, -32

def S(a):
  if a > 0:
    c = 0
  else:
    c = 1
  while True:
    if 2 ** (c-1) > abs(a):
      return c - 2
    else:
      c += 2

n = N
s = S(n)
#print(s, n)
b = [0] * (s+1)
b[s] = 1
n -= (-2)**s
while n != 0:
  s = S(n)
  #print(s, n)
  b[s] = 1
  n -= (-2)**s
#print(b)
print(''.join(map(str, b[::-1])))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

import bisect

N = int(input())

plus = [2 ** x for x in range(0, 35, 2)]
minus = [2 ** x for x in range(1, 35, 2)]

cum_plus = [sum(plus[:x]) for x in range(1, len(plus))]
cum_minus = [sum(minus[:x]) for x in range(1, len(minus))]

flags = []
answer = 0
while answer != N:
    if N - answer > 0:
        insert_index = bisect.bisect_left(cum_plus, N - answer)
        flags.append(insert_index * 2)
        answer += plus[insert_index]
        cum_plus = cum_plus[:insert_index]
    else:
        insert_index = bisect.bisect_left(cum_minus, abs(N - answer))
        flags.append(insert_index * 2 + 1)
        answer -= minus[insert_index]
        cum_minus = cum_minus[:insert_index]
        
output = [0] * (flags[0] + 1)
for flag in flags:
    output[flag] = 1
 
print(''.join([str(x) for x in output[::-1]]))

Submission status: Runtime Error

Solution code:
N = int(input())
if N == 0:
  print(0)
else:
  ans = ''
  flag = False
  while flag == False:
    if N%2 == 0:
      ans = '0'+ans
      N = N/(-2)
    else:
      ans = '1'+ans
      N -= 1
      if N == 0:
        flag = True
      else:
        N = N/(-2)
print(ans)

Submission status: Runtime Error

Solution code:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long int ll;
ll N;
int main(int argc, char const *argv[]) {
  cin >> N;
  ll temp=N;
  string S;
  for(int i=1;i<=30;i++){
    if(temp%(ll)pow(2,i)!=0){
      S.push_back('1');
      temp=temp-(ll)pow(-2,i-1);
    }else{
      S.push_back('0');
    }
  }
  while(S.back()=='0'){
    S.pop_back();
    if(S.empty()){
      S='0';
      break;
    }
  }
  reverse(S.begin(),S.end());
  cout<<S<<endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())

s = ""

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

print(s if s != "" else 0)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
N, M = map(int, input().split(" "))
A = [int(i) for i in input().split()]
count = 0
for i in range(N):
    for k in range(i,N):
        S = sum(A[i:k+1])
        if S % M ==0:
            count = count +1
 
print(count)

Submission status: Runtime Error

Solution code:
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))

mod = [a%M for a in A]

mod_dict={}
mod_dict[0]=1

for m in mod:
  mod_dict[m]=mod_dict.get(m,0)+1

answer=0

for x in mod_dict.values():
  answer+=x-1

print(int(answer))

Submission status: Runtime Error

Solution code:
n=int(input())
L=[]
while n!=0:
    if n>0 and n%2==0:
        n=-n//2
        L.append('0')
    elif n>0 and n%2==1:
        n=(-n+1)//2
        L.append('1')
    elif n<0 and -n%2==0:
        n=-n//2
        L.append('0')
    elif n<0 and -n%2==1:
        n=(-n+1)//2
        L.append('1')
print(int(''.join(L[::-1])))

Submission status: Runtime Error

Solution code:
a=int(input());s=''
while a!=0:s+=str(a%2);a=-(a//2)
print(int(s[::-1]))

Submission status: Runtime Error

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
D,G = map(int, input().split())
points = [ [int(j) for j in input().split()] for _ in range(D)]
points = [ [x[0], x[1], 100*e*x[0]] for e,x in enumerate(points, 1)]

ans = float("inf")
for i in range(1<<D): # for complete bonus bit set 
    lg = G
    cnt = 0
    for d in range(D):
        if i & (1<<d) != 0:
            lg -= points[d][1] # complete bonus
            # lg -= (100*(d+1))*points[d][0] # normal points
            lg -= points[d][2] # normal points
            cnt += points[d][0]
            if lg <= 0:
                break
    if lg <= 0:
        ans = min(ans, cnt)
        continue
    
    # other points
    for d in range(D-1, -1, -1):
        if i & (1<<d) != 0: continue

        if lg <= points[d][2]:
            quot = (lg+(100*(d+1)-1)) // (100*(d+1)) # carryUp
            lg -= 100*(d+1)*quot
            cnt += quot;  break
        else:
            cnt += points[d][0]
            lg -= points[d][2]
    if lg <= 0:
        ans = min(ans, cnt)
        continue
print(ans)

Submission status: Runtime Error

Solution 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])

Submission status: Runtime Error

Solution code:
N=int(input())

if N%2==0:
  ans='0'
else:
  ans='1'
  
i=2
while abs(tmp)<=abs(N):
  if N%((-2)**i)==0:
    ans='0'+ans
  else:
    ans='1'+ans
    
print(ans)

Submission status: Runtime Error

Solution code:
# coding:utf-8

n = input()

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

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

print(ans[::-1])

Submission status: Runtime Error

Solution code:
  N = int(input())
  minus_bit = ''
  if N == 0:
      minus_bit = '00'
  while N != 0:
      mod = N % 4
      if mod == 0:
          minus_bit = minus_bit + '00'
          N = N//4
      elif mod == 1:
          minus_bit = minus_bit + '10'
          N = (N-1)//4
      elif mod == 2:
          minus_bit = minus_bit + '01'
          N = (N+2)//4
      else:
          minus_bit = minus_bit + '11'
          N = (N+1)//4

  if minus_bit[-1] == '0':
      minus_bit = minus_bit[:-1]
  print(minus_bit[::-1])

Submission status: Runtime Error

Solution code:
N=int(input())
if N==0:
    a=0
elif N>0:
    a=0
    i=31
    while i>=0:
        if N%(2**i)==0:
            if i%2==1:
                a+=2**(i+1)+2**i
                break
            else:
                a+=2**i
                break
        else:
            if N>2**i:
                N-=2**i
                if i%2==1:
                    a+=2**(i+1)+2**i
                else:
                    a+=2**i
            i-=1
else:
    a=0
    i=31
    while i>=0:
        if N%(2**i)==0:
            if i%2!=1:
                a+=2**(i+1)+2**i
                break
            else:
                a+=2**i
                break
        else:
            if -N>2**i:
                N+=2**i
                if i%2!=1:
                    a+=2**(i+1)+2**i
                else:
                    a+=2**i
            i-=1
print(int(format(a,"b"))

Submission status: Runtime Error

Solution code:
N=int(input())
if N==0:
    print(0)
elif N>0:
    a=0
    i=31
    while i>=0:
        if N%(2**i)==0:
            if i%2==1:
                a+=2**(i+1)+2**i
                break
            else:
                a+=2**i
                break
        else:
            if N>2**i:
                N-=2**i
                if i%2==1:
                    a+=2**(i+1)+2**i
                else:
                    a+=2**i
            i-=1
    print(int(str(a),2))
else:
    a=0
    i=31
    while i>=0:
        if N%(2**i)==0:
            if i%2!=1:
                a+=2**(i+1)+2**i
                break
            else:
                a+=2**i
                break
        else:
            if -N>2**i:
                N+=2**i
                if i%2!=1:
                    a+=2**(i+1)+2**i
                else:
                    a+=2**i
            i-=1
    print(int(str(a),2))

Submission status: Runtime Error

Solution code:
N=int(input())
if N==0:
    print(0)
elif N>0:
    a=0
    i=31
    while i>=0:
        if N%(2**i)==0:
            if i%2==1:
                a+=2**(i+1)+2**i
                break
            else:
                a+=2**i
                break
        else:
            if N>2**i:
                N-=2**i
                if i%2==1:
                    a+=2**(i+1)+2**i
                else:
                    a+=2**i
            i-=1
    print(int(format(a,2)))
else:
    a=0
    i=31
    while i>=0:
        if N%(2**i)==0:
            if i%2!=1:
                a+=2**(i+1)+2**i
                break
            else:
                a+=2**i
                break
        else:
            if -N>2**i:
                N+=2**i
                if i%2!=1:
                    a+=2**(i+1)+2**i
                else:
                    a+=2**i
            i-=1
    print(int(format(a,2)))

Submission status: Runtime Error

Solution code:
import math
import sys

N = int(input())
max = math.ceil(math.log(abs(N), 2)) + 3

result = []
numerator = N
for i in range(0, max):
    if numerator % (math.pow(2, i + 1)) == 0:
        result.append(str(0))
    else:
        result.append(str(1))
        numerator -= math.pow(-2, i)

    if numerator == 0:
        break
result.reverse()
print("".join(result))

Submission status: Runtime Error

Solution code:
N = int(input())
res = []
for i in range(32):
    digit = (-2) ** i
    if N % (digit * (-2)) != 0:
        N -= digit
        res.append('1')
    else:
        res.append('0')
while res[-1] == '0':
    res.pop()
print(''.join(res[::-1]))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())

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

Submission status: Runtime Error

Solution 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)

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,str(bin(n))[2:]))
for i in range(1,len(l)+3): 
    if l[-i] == 2:
        l[-i] = 0
        if i == len(l):
            l.insert(0,1)
        else:
            l[-(i+1)]+=1
    if i%2==0 and l[-i]==1:
        if i == len(l):
            l.insert(0,1)
        else:
            l[-(i+1)]+=1
s = ''.join([str(x) for x in l])
print(s)

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,str(bin(n))[2:]))
for i in range(1,len(l)+3): 
    if l[-i] == 2:
        l[-i] = 0
        try:
            l[-(i+1)]+=1
        except:
            l.insert(0,1)
    if i%2==0 and l[-i]==1:
        try: 
            l[-(i+1)]+=1
        except:
            l.insert(0,1)
s = ''.join([str(x) for x in l])
print(s)

Submission status: Runtime Error

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

n=int(input())
l=list(map(int,str(bin(n))[2:]))
for i in range(1,len(l)+3): 
    if l[-i] == 2: #2のとき繰上げ
        l[-i] = 0
        try:
            l[-(i+1)]+=1
        except:
            l.insert(0,1)
    if i%2==0 and l[-i]==1: #-2^nが-2のとき01→11に変換
        try: 
            l[-(i+1)]+=1
        except:
            l.insert(0,1)
s = ''.join([str(x) for x in l])
print(s)

Submission status: Runtime Error

Solution code:
a = []
aa = (int)(input())
if(aa == 0):
  print(0)
else:
  while(aa!=0):
    a.append(aa%(-2))
    a/=(-2)
  print(a[::-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
k = 1
kotae = []
kotae2 = []

if n != 0:
    while n != 0:
        if n % ((-2) ** k) == 0:
            kotae.append(0)
        else:
            kotae.append(1)
            n = n - ((-2) ** (k - 1))
        k = k + 1

    for i in kotae[::-1]:
        kotae2.append(i)

    print("".join(kotae2))
else:
    print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
ans = ''
for i in range(30):
    if n == 0:
        break
    if n % 2 ** (i + 1) == 0: 
        ans = ans + '0'
    else:
        n -= (-2)**i
        ans = ans + '1'
print(int(ans))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
s =""
k = 0
while n!=0:
  if n%(2**(k+1)) == 2**k:
    if k%2 == 0:
      n -= 2**k
    else:
      n += 2**k
    s += "1"
  else:
    s += "0"
  k += 1

if s="":
  s="0"

print("".join(s))

Submission status: Runtime Error

Solution code:
#coding:utf-8
n = int(input())

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

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

Submission status: Runtime Error

Solution code:
N = int(input())

Ans = 0
while N!=0:
    Ans = str(N%2) +Ans
    N = (N - N%2)//2
    N *= -1

print(Ans)

Submission status: Runtime Error

Solution code:
n=int(input())
if n==0:
    result=0
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))

Submission status: Runtime Error

Solution 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))

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
if n ==0:
  print(0)
else:
  while n != 0:
  if n%2 ==0:
    n = n/(-2)
    a.append("0")
  else:
    n = (n-1)/(-2)
    a.append("1")
    
b = ""
for i in range(len(a)):
  b += a[len(a)-i-1]

print(b)

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
while n > 0:
  if n%2 ==0:
    n = n/(-2)
    a.append("0")
  else:
    n = (n-1)(-2)
    a.append("1")
    
b = ""
for i in range(len(a)):
  b += a[len(a)-i-1]
  
print(b)

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
while n > 0:
  if n%2 ==0:
    n = n/(-2)
    a.append("0")
  else:
    n = (n-1)(-2)
    a.append("1")
    
b = ""
for i in range(len(a)):
  b += a[len(a)-i-1]
  
print("b")

Submission status: Runtime Error

Solution code:
import numpy as np
N, M = map(int, input().split())
A = [int(i) for i in input().split()]
ar = np.eye(N) * A

for h in range(0, N):
    for w in range(1, h+1):
        ar[-h-1, -h-1+w] = ar[-h, -h-1+w] + ar[-h-1, -h-2+w] - ar[-h, -h-2+w]
print(int(sum(sum(ar % M == 0)) - sum(np.linspace(1, N-1, N-1))))

Submission status: Runtime Error

Solution code:
# input
N = int(input())

ans = []

if N == 0:
    print(0)
else:
    ans.append(0)
    N = N - 1
    while N != 0:
        if N > 0:
            k = 0
            while (-2) ** k <= N:
                k += 2
            ans.append(k - 2)
            N = N - (-2) ** (k - 2)
        else:
            k = 1
            while (-2) ** k >= N:
                k += 2
            ans.append(k - 2)
            N = N - (-2) ** (k - 2)

n = max(ans) + 1 # N を -2進法で表したときの桁数
ans_bin = [0 for _ in range(n)]

for i in range(n):
    if i in ans:
        ans_bin[i] = 1

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

Submission status: Runtime Error

Solution code:
import math

# input
N = int(input())

if N == 0:
    print(0)
elif N > 0:
    n = 2 * math.floor(math.log(3 * N + 1, 4)) + 1 # N を -2進法で表したときの桁数
    ans = [0 for _ in range(n)]
    ans[0] = 1
    ans[1 + 2 * n] = 1
    N = N - (-2) ** n
    while N > 0:
        n = math.ceil(math.log((1 + ((3 * (N - 1)) / 2)), 4))
        ans[1 + 2 * n] = 1
        N = N - (-2) ** n
else:
    n = 2 * math.ceil(math.log((3 * (N + 1) / 2) + 1, 4)) # N を -2進法で表したときの桁数
    ans = [0 for _ in range(n)]
    ans[0] = 1
    ans[n] = 1
    N = N - (-2) ** n
    while N < 0:
        n = math.ceil(math.log(3 * abs(N) - 1, 4))
        ans[2 * n] = 1
        N = N - (-2) ** n

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