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: Accepted

Solution code:
n=int(input())

s=""
index=1

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

if len(s)==0:
    s="0"

print(s[::-1])

Submission status: Accepted

Solution code:
def negabinary(i):
    if i == 0:
        digits = ['0']
    else:
        digits = []
        while i != 0:
            i, remainder = divmod(i, -2)
            if remainder < 0:
                i, remainder = i + 1, remainder + 2
            digits.append(str(remainder))
    return ''.join(digits[::-1])


print(negabinary(int(input())))

Submission status: Accepted

Solution code:
N = int(input())
def solve(n):
	if n == 0:
		return "0"
	out = []
	while n != 0:
		n, rem = divmod(n, -2)
		if rem < 0:
			n += 1
			rem -= -2
		out.append(rem)
	return "".join(map(str, out[::-1]))
print(solve(N))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N = int(input())

S = ''
for i in range(50):
    if N % -2 == 0:
        S = '0' + S
    else:
        S = '1' + S
        N -= 1

    N = N // -2

print(int(S))

Submission status: Accepted

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

#n,k=[int(i) for i in input().split()]

n=int(input())
a=[]

if n==0:
    a=["0"]

while n != 0:
        a.append(str(n%2))
        n=-(n-n%2)//2

print("".join(list(reversed(a))))

Submission status: Accepted

Solution code:
n = int(input())

a = ""

if n == 0:
    print(0)
else:
    while n != 0:
        if n % (-2) == 0:
            a += "0"
            n = n // -2
        else:
            a += "1"
            n = n // -2 + 1
    b = a[::-1]
    print(b)

Submission status: Accepted

Solution code:
n = int(input())
ans = []

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

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

		i += 1

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

Submission status: Accepted

Solution code:
N = int(input())
fugou = 1
ans = ''
if N == 0:
    ans = '0'
else:
    q = N
    while q!= 0:
        if q > 0:
            r = q%2
            q = (-1)*(q//2)
        else:
            q = -q
            r = q%2
            if r == 0:
                q = q//2
            else:
                q = q//2+1
        ans += str(r)
print(ans[::-1])

Submission status: Accepted

Solution code:
n = int(input())
answer = ''
while n <= -1 or 2 <= n:
    if n % 2 == 0:
        answer = '0' + answer
        n //= -2
    else:
        answer = '1' + answer
        n = n // -2 + 1
print(str(n) + answer)

Submission status: Accepted

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

res_list = []
k = 0

while N != 0:
    if N % (2**(k+1)) != 0:
        N -= (-2)**k
        res_list.append("1")
    else:
        res_list.append("0")
    k += 1
if len(res_list) == 0:
    res_list.append("0")
    
print("".join(reversed(res_list)))

Submission status: Accepted

Solution code:
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

n = input()
if n == 0:
    print '0'
    exit()
num = 1
sig = 1
ans = ''
while n != 0:
    if n % (num * 2) != 0:
        n -= num * sig
        ans += "1"
    else:
        ans += "0"
    num *= 2
    sig *= -1
print ans[::-1]

Submission status: Accepted

Solution code:
A = int(input());
answer = str();
i=0;

if(A==0):
    print("0");
else:
    while(A!=0):
        if(A%abs(pow(-2,i+1))!=0):
            A-=pow(-2,i);
            answer = str(1) + answer;
        else:
            answer = str(0) + answer;
        i+=1;
    print(answer);

Submission status: Accepted

Solution code:
N = int(input())

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

a = ''
b = -2

while N != 1:
    if N % b == 0:
        a += '0'
        N = N // b
    else:
        a += '1'
        if N > 0:
            N = N // b + 1
        else:
            N = N // b + 1
if N == 1:
    a += '1'
print(a[::-1])

Submission status: Accepted

Solution code:
def foo(n):
    if n == 0:
        return "0"
    else:
        res = ""
        while n != 0:
            r = n % (-2)
            n = n // (-2)
            if r < 0:
                n += 1
                r += 2
            res += str(r)
    return "".join(reversed(res))


n = int(input())
print(foo(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(N):
    if N == 0: return '0'
    s = []
    b = 1
    while N != 0:
        s.append('0' if N % 2 == 0 else '1')
        if N % 2 != 0:
            N -= b
        N //= 2
        b = -b
    s.reverse()
    return ''.join(s)

N = int(input())
print(solve(N))

Submission status: Accepted

Solution code:
N = input()

i = 1
s = ""

while abs(i) <= abs(N):
	if (abs(N) & abs(i)) != 0:
		s += '1'
		N -= i
	else:
		s += '0'

	i *= -2

if s == "":
	s = "0"
s = s[::-1]
print s

Submission status: Accepted

Solution code:
n = int(input())
if n == 0:
	 print ("0")
out = []
while n != 0:
	 n, rem = divmod(n, -2)
	 if rem < 0:
	 	 n += 1
	 	 rem -= -2
	 out.append(rem)
print ("".join(map(str, out[::-1])))

Submission status: Accepted

Solution code:
n=int(input())
b=2
c=0
ans=0
while n!=0:
    if n%b!=0:
        ans+=10**c
        n-=(-2)**c
    c+=1
    b*=2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l=[]
tmp=1
if n%abs(tmp*2)!=0:
    n-=tmp
    l.append('1')
else:
    l.append('0')

while n!=0:
    tmp *= (-2)
    if n%abs(tmp*2)!=0:
        n-=tmp
        l.append('1')
    else:
        l.append('0')
print(''.join(reversed(l)))

Submission status: Accepted

Solution code:
n=int(input())

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

Submission status: Accepted

Solution code:
def f(x):
 if x==0:return "0"
 if x==1:return "1"
 return f((x%2-x)/2)+str(x%2)
n=input()
print f(n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
bit = []
for i in range(32):
    b = (N >> i) & 1
    if i % 2 == 0:
        bit.append(b)
        if b:
            N -= 1 << i
    else:
        bit.append(((N >> i) & 1))
        if b:
            N += 1 << i
while bit and bit[-1] == 0:
    bit = bit[:-1]
if not bit:
    bit = [0]
print(*bit[::-1], sep='')

Submission status: Accepted

Solution code:
n=int(input())
s=''
while True:
    r=n%(-2)
    n //= -2
    if r<0:
        r+=2
        n+=1
    s+=str(r)
    if n == 0: break
print(s[::-1])

Submission status: Accepted

Solution code:
N = int(input())

answer = ''

for i in range(40):
    if N % (2**(i + 1)) != 0:
        N -= (-2)**i
        answer = '1' + answer
    else:
        answer = '0' + answer
while len(answer) > 1 and answer[0] == '0':
    answer = answer[1:]

print(answer)

Submission status: Accepted

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

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

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

print(S)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()

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

Submission status: Accepted

Solution code:
n = input()
x = 1
ret = ""
while n != 0:
    if n % abs(2*x) != 0:
        n -= x
        ret = "1" + ret
    else:
        ret = "0" + ret
    x *= -2
if len(ret) == 0:
    ret = "0"
print ret

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import bisect
from collections import deque

n=int(input())

ans=[0]

for i in range(2**20):
  ch=0
  for j in range(20):
    
    if (i>>j)&1:
      ch+=2**(j*2)
  ans.append(ch)
  
ans1=[]
for x in range(2**20):
  ch1=0
  for y in range(20):
    if (x>>y)&1:
      ch1+=(-2)**(y*2+1)
  ans1.append(ch1)
  

for a in ans1:
  if n-a>=0:
    d=bisect.bisect_right(ans,n-a)
    if ans[d-1]==n-a:
      ans_min=a
      ans_plus=ans[d-1]
      break
      
v=1
C=0
while v<=ans_plus:
  v*=4
  C+=2
C-=2
pl_list=[]
while C>-1:
  if ans_plus>=2**C:
    pl_list.append(1)
    ans_plus-=2**C
    C-=2
  else:
    pl_list.append(0)
    C-=2
w=-2
D=1

while ans_min<=w:
  w*=4
  D+=2
D-=2

mi_list=[]
while D>0:
  if ans_min<=(-2)**D:
    mi_list.append(1)
    ans_min-=(-2)**D
    D-=2
  else:
    mi_list.append(0)
    D-=2

ans_str=[]
P=deque(pl_list)
M=deque(mi_list)

while P or M:
  if P:
    x=P.pop()
  else:
    x=0
  if M:
    y=M.pop()
  else:
    y=0
  ans_str.append(str(x))
  ans_str.append(str(y))

ans_str_r=list(reversed(ans_str))
if ans_str_r[0]=='0':
  ans_str_r.remove('0')
  
print(''.join(ans_str_r))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main(){
  int n; cin >> n;
  if(n == 0){
      cout << 0 << '\n';
      return 0;
  }
  int base = -2;
  string ans;
  while(n){
    int r = n%base;
    n = n/base;
    if(r < 0) n++;
    if(r < 0) r = r*(-1);
    char x = r + '0';
    ans = x + ans;
    
  }
  cout << ans << '\n';
}

Submission status: Runtime Error

Solution code:
n = int(input())

dp =[0]*40

if n ==0:
    print(0)

elif n >0:
    x = bin(n)
    bx = x[2:]
    lx = len(bx)
    for i in range(lx-1,-1,-1):
        dp[i] = int(bx[lx-1-i])
    for i in range(40):
        if i % 2 ==1 and dp[i]==1:
            dp[i+1] +=1
    while max(dp) >1:
        for i in range(40):
            if dp[i] >=2:
                dp[i] -=2
                if dp[i+1] >0:
                    dp[i+1] -=1
                else:
                    dp[i+1] +=1
                    dp[i+2] +=1
    dpr = list(reversed(dp))
    dprs = list(map(lambda x :str(x),dpr))
    dprj = "".join(dprs)
    print(int(dprj))    

else:
    x = bin(n)
    bx = x[2:]
    lx = len(bx)
    for i in range(lx-1,-1,-1):
        dp[i] = int(bx[lx-1-i])
    for i in range(40):
        if i % 2 ==1 and dp[i]==1:
            dp[i+1] +=1
    while max(dp) >1:
        for i in range(40):
            if dp[i] >=2:
                dp[i] -=2
                if dp[i+1] >0:
                    dp[i+1] -=1
                else:
                    dp[i+1] +=1
                    dp[i+2] +=1
    dpr = list(reversed(dp))
    dprs = list(map(lambda x :str(x),dpr))
    dprj = "".join(dprs)
    print(int(dprj))

Submission status: Runtime Error

Solution code:
# abc105_c.py
# https://atcoder.jp/contests/abc105/tasks/abc105_c

# C - Base -2 Number /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# 整数 Nが与えられるので、N の −2進数表現を求めてください。

# ここで、Sが N の −2進数表現であるとは、以下を全て満たすことです。

#     Sは 0 および 1 のみからなる文字列である
#     S=0 でなければ Sの先頭の文字は 1 である
#     S=SkSk−1...S0とすると、S0×(−2)0+S1×(−2)1+...+Sk×(−2)k=Nが成り立つ

# なお、任意の整数 Mに対して M の −2進数表現が一意に定まることが証明できます。

# 制約
#     入力はすべて整数である
#     −109≤N≤109

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N

# 出力
# Nの −2進数表現を出力せよ。

# 入力例 1
# -9

# 出力例 1
# 1011

# (−2)0+(−2)1+(−2)3=1+(−2)+(−8)=−9
# なので 1011 は −9 の −2進数表現です。

# 入力例 2
# 123456789

# 出力例 2
# 11000101011001101110100010101

# 入力例 3
# 0

# 出力例 3
# 0

global BITS
BITS = ''


def calculation(lines):
    N = int(lines[0])
    bits = ''

    if N == 0:
        return ['0']

    for i in range(30):
        # (-2)^i
        if N % (-2)**(i+1) == 0:
            bits = '0' + bits
        else:
            bits = '1' + bits
            N -= (-2)**i
            if N == 0:
                return [bits]

    # # (-2)^0
    # if N % (-2)**1 == 0:
    #     bits = '0' + bits
    # else:
    #     bits = '1' + bits
    #     N -= (-2)**0
    #     if N == 0:
    #         return [bits]

    # # (-2)^1
    # if N % (-2)**2 == 0:
    #     bits = '0' + bits
    # else:
    #     bits = '1' + bits
    #     N -= (-2)**1
    #     if N == 0:
    #         return [bits]

    # # (-2)^2
    # if N % (-2)**3 == 0:
    #     bits = '0' + bits
    # else:
    #     bits = '1' + bits
    #     N -= (-2)**2
    #     if N == 0:
    #         return [bits]

    # # (-2)^3
    # if N % (-2)**4 == 0:
    #     bits = '0' + bits
    # else:
    #     bits = '1' + bits
    #     N -= (-2)**3
    #     if N == 0:
    #         return [bits]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines



# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['-9']
        lines_export = ['1011']
    if pattern == 2:
        lines_input = ['123456789']
        lines_export = ['11000101011001101110100010101']
    if pattern == 3:
        lines_input = ['0']
        lines_export = ['0']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

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

lim = 30
top = [0]*(lim+1)
bottom = [0]*(lim+1)

for i in range(1, lim+1):
	if i%2:
		t = (i+1)//2
		top[i] = (4**t-1)//3
		bottom[i] = bottom[i-1]
	else:
		b = i//2
		bottom[i] = (4**b-1)*2//3
		top[i] = top[i-1]

digit = [0]*(lim+1)
for i in range(1, lim+1):
	digit[i] = (-2)**(i-1)

if 0 <= N:
	idx = bisect_left(top, N)
else:
	idx = bisect_left(bottom, -N)

ans = ""
for i in range(idx, 0, -1):
	if -bottom[i-1] <= N <= top[i-1]:
		ans += "0"
	else:
		ans += "1"
		N -= digit[i]

print(ans)

Submission status: Runtime Error

Solution code:
import sys
import itertools
import bisect

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    N = in_n()
    comb = itertools.product([0, 1], repeat=15)

    p = []
    m = []
    for c in comb:
        pt, mt = 0, 0
        for i in range(len(c)):
            pt += c[i] * (4 ** i)
            mt += c[i] * 2 * (4 ** i)
        p.append(pt)
        m.append(mt)

    p.sort()
    m.sort()

    for i in range(len(p)):
        if p[i] < N:
            continue
        else:
            pred_m = -(N - p[i])
            j = bisect.bisect_left(m, pred_m)
            if m[j] == pred_m:
                pred_p = p[i]
                break

    ans = pred_p | pred_m
    print(bin(ans)[2:])


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:

ans = ""
if N == 1:
    print("1")
elif N == -1:
    print("10")
else:
    while True:
        r = N % 2
        N = (N-r) /-2
        ans = str(int(r)) + ans
        if N == 0 or N == 1:
            ans = str(int(N)) + ans
            break

    print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
n = int(input())
if n == 0:
  print(0)
  exit()
else:
  pass

m = math.floor(math.log2(abs(n)))
ans = []
for i in range(m+2):
  ans.append(n//((-2)**(m+1-i)))

while True:
  if ans[0] == 0:
    ans = ans[1:len(ans)]
  else:
    break

ANS = [str(ans[i]) for i in range(len(ans))]
print(int("".join(ANS)))

Submission status: Runtime Error

Solution code:
n = int(input())

ans = ""
cnt = 0

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

Submission status: Runtime Error

Solution code:
n = int(input())
ansl = []
if n == 0:
	print(0)
    exit()
while n != 0:
	if n % 2 == 1:
		ansl.append("1")
		n -= 1
	else:
		ansl.append("0")
	n //= -2
print("".join(ansl)[::-1])

Submission status: Runtime Error

Solution code:
n=int(input())
ans=''
while n!1:
  r=n%(-2)
  ans+=r
  n=n//(-2)
ans+=n
ans.reverse()
print(ans)

Submission status: Runtime Error

Solution code:
def resolve():
	s = input()
	k = int(input())
	if len(s) == 1:
		print(s)
		return

	for i in s:
		if int(i) == 1:
			continue
		print(i)
		return
	print(s[0])
resolve()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
x = ''
While n != 0:
  x += str(n%2)
  n = -(n//2)
  
if x == '':
  print(0)
else:
  print(x)

Submission status: Runtime Error

Solution code:
# solution

data=int(input())

a="";k=1

while data:
	t=k;k*=-2
	if n%k:n-=t;a+="1"
	else:a+="0"
print(a[::-1]or 0)

Submission status: Runtime Error

Solution code:
def log2(n):
    i = 1
    r = 0
    if n < 0:
        i = 2
        r = 1
        n = -n
    s = i
    while n > s:
        i *= 4
        s += i
        r += 2
    return r


def resolve():
    n = int(input())
    if n == 0:
        print(0)
        return
    ans = [0] * 30
    while n:
        l = log2(n)
        ans[l] += 1
        n = n - (-2) ** l
    while ans[-1] == 0:
        ans.pop()
    print("".join([str(x) for x in ans[::-1]]))


if __name__ == '__main__':
    resolve()

Submission status: Runtime Error

Solution code:
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from math import gcd

def main():
    n = int(input())
    s = []
    if n == 0:
        print('0')
        return

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

if __name__ =='__main__':
    main()

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
Alist = list(map(int, input().strip().split()))
p = 1
for i in range(len(Alist)-1):
    if Alist[i]*Alist[i+1] <= 0:
        q = i
        p = p*(-1)
length = 10**10
ans2 = 10**10
if p == 1:
    if Alist[0] > 0:
        ans = Alist[K-1]
    if Alist[0] < 0:
        ans = -Alist[0]
if p == -1:
    for i in range(len(Alist)):
        if i + K - 1 < len(Alist):
            if i + K - 1 == q:
                length = min(abs(Alist[i]),length)
            elif i == q + 1:
                length = min((Alist[i+K-1]),length)
            else:
                length = min(min(abs(Alist[i+K-1]-Alist[i])+abs(Alist[i]),abs(Alist[i+K-1]-Alist[i]),abs(Alist[i+K-1])),length)
    ans = length
for i in range(len(Alist)):
    ans2 = min(ans2,abs(Alist[i]))
if K == 1:
    print(ans2)
else:
    if len(Alist) > 1:
        print(ans)
    if len(Alist) ==1:
        print(Alist[0])

Submission status: Runtime Error

Solution code:
n = int(input())
s = ''
value = 0
count = 0
while value != n:
    r = n % 2**(count+1)
    if (value + (-2)**count)%(2**(count+1)) == r:
        s += '1'
        value += (-2)**count
    else:
        s += '0'
    count += 1
print(int(s[::-1]))

Submission status: Runtime Error

Solution code:
N = int(input())
def Base(x,n):
  if (int(x/n)):
    return Base(int(x/n),n) + str(x % n)
  return str(x % n)
print(int(Base(N,-2))

Submission status: Runtime Error

Solution code:
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include <assert.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
#include<set>
#include <climits>
using namespace std;
typedef unsigned long long ull;
#define ll long long int
static const double PI = 3.141592653589793;
const ll INF = 100000000000000;
ll mod = 1000000007;
//typedef vector<int> V;
//typedef vector<V> VV;
//typedef vector<VV> VVV;

int main(){
	ll n;
	string s="";
	cin >> n;
	ll ind = 1;
	while (n != 0) {
		int a =abs((n % (ind*(-2)))/ind);
		n -= a * (ind);
		s = to_string(a) + s;
		ind *= -2;
	}
	cout << s << endl;
}

Submission status: Runtime Error

Solution code:
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    from math import log2, ceil
    N = II()
    if N == 0:
        print(0)
        return
    ans_stack = deque()
    determined = 0
    for i in range(100):
        if (N - determined) % 2 ** (i+1) != 0:
            ans_stack.append(1)
            determined += (-2) ** i
        else:
            ans_stack.append(0)
        if determined == N:
            break
    ans_str = ''
    while len(ans_stack) > 0:
        item = ans_stack.pop()
        ans_str += str(item)
    print(ans_str)
    '''
    1 -2 4 -8 16 -32 64 -128
    '''
            
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
a,b,c=map(int,input().split())
    if 4*a*b<(c-a-b)**2 :
        print('Yes')
    else:
        print('No')

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
ans = [0] * 31
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(30, -1, -1):
    if ans[j] == 1:
        print(''.join(map(str, reversed(ans[:j + 1]))))
        exit()

Submission status: Runtime Error

Solution code:
n =int(input())

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

l = [(-2)**_ for _ in range(100) if abs((-2)**_) <= 10**10]

if n > 0:
    x = [1]
    for i in range(len(l)):
        if abs(l[i]) < abs(n):
            x.append(l[i+1])

elif n < 0:
    x = []
    for j in range(len(l)):
        if abs(l[j]) < abs(n):
            x.append(l[j])

#print(len(x))

y = []
from itertools import combinations
for __ in range(len(x)):
    y += list(combinations(x, __))

for k in y:
    if sum(k) == n:
        z = list(k)

#print(y)
#print(z)

p = []
for q in range(len(x)):
    if x[q] in z:
        p.append(str(1))
    else:
        p.append(str(0))

p.reverse()
print(''.join(p))

Submission status: Runtime Error

Solution code:
n =int(input())

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

l = [(-2)**_ for _ in range(100) if abs((-2)**_) <= 10**10]

if n > 0:
    x = [1]
    for i in range(len(l)):
        if abs(l[i]) < abs(n):
            x.append(l[i+1])

elif n < 0:
    x = []
    for j in range(len(l)):
        if abs(l[j]) < abs(n):
            x.append(l[j])

#print(len(x))

y = []
from itertools import combinations
for __ in range(len(x)):
    y += list(combinations(x, __))

for k in y:
    if sum(k) == n:
        z = list(k)

#print(y)
#print(z)

p = []
for q in range(len(x)):
    if x[q] in z:
        p.append(1)
    else:
        p.append(0)

p.reverse()
print(p)

Submission status: Runtime Error

Solution code:
n = int(input())
if n == 0:
    print(0)
    exit()
flag = True
ans_str = ''
while True:
    if n // (-2) == 0:
        ans_str = '1' + ans_str
        print(int(ans_str))
        exit()
    else:
        ans_str = n%(-2) + ans_str

Submission status: Runtime Error

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

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

print(num(n))

Submission status: Runtime Error

Solution code:
N = int(input())
a = []
if N == 0:
  a.append["0"]
while N != 0:
  a.append(str(N % 2))
  N = -(N // 2)
print("".join(reversed(a)))

Submission status: Runtime Error

Solution code:
N = int(input())
S = ""
while N:
     S = chr(N % (-2)) + S
     N /= (-2)
print(S)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
# https://atcoder.jp/contests/abc105/tasks/abc105_c
# -2進数
# 前に考えたときはわからなかったけど、数式イジイジしたら解けた


N = int(input())

if N == 0:
    print(0)
	exit()
ans = ''
while N != 0:
    if N & 1:  # 奇数ならbitが立つのは共通する性質
        ans += '1'
        N /= -2
        if N > 0:
            N += 1
        N = int(N)
    else:
        ans += '0'
        N //= -2


print(ans[::-1])

Submission status: Runtime Error

Solution code:
n = input()
negBase = -2

converted = ""

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

else:
    converted = "01"
    while (n != 0): 
      
        remainder = n % (negBase) 
        n = int(n/negBase) 
  
        if (remainder < 0): 
            remainder += ((-1) * negBase) 
            n += 1
  
        converted = str(remainder) + converted

print(converted)

Submission status: Runtime Error

Solution code:
n = input()
negBase = -2

if (n == 0): 
        return "0"
  
    converted = "01"
    while (n != 0): 
      
        remainder = n % (negBase) 
        n = int(n/negBase) 
  
        if (remainder < 0): 
            remainder += ((-1) * negBase) 
            n += 1
  
        converted = str(remainder) + converted

Submission status: Runtime Error

Solution code:
n=int(input())
if n==0:print(0)
bi=''
while n!=0:
    bi+=str(n%abs(k))
    if k<0:n=-(-n//k)
    else:n=n//k
print(bi[::-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# -2進数を求める
N = int(input())

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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='')

Submission status: Runtime Error

Solution code:
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='')

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
Z = int(input())
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))

Submission status: Runtime Error

Solution code:
Z = int(input())
n = (-2)

ans = ""

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

Submission status: Runtime Error

Solution code:
n = map(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)
        reversed(a)
    return a
 
print(basen(n))

Submission status: Runtime Error

Solution code:
n = map(int,input())


def base-2(n):
    a = ()
    while n! = 0:
        r = n % 2:
        if (r < 0):
            r += 2

            n = (n - r)/2
            a.append(str(r))
    if(a = ""):
    a = "0"
    reversed(a)
print(base(n))