Problem: 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.

Submission attempts (in order):

flaga=True
S='1'
N=int(input())
D=N
flag=0
p=1
K=0
if N==0:
    print(0)
    exit(0)
elif N==1:
    print(1)
    exit(0)
elif N>0:
    D-=1
    while flag==0:
        if D+1-p>0:
            D-=p
            p*=4
            K+=2
        else:
            print(D)
            for i in range(K):
                if D<p//2:
                    if flaga==True:
                        S +='1'
                    else:
                        S +='0'
                else:
                    D-=p//2
                    if flaga==True:
                        S +='0'
                    else:
                        S +='1'
                p=p//2
                flaga = not flaga
            print(S)
            exit(0)
else:
    D=abs(D)-2
    while flag==0:
        if D+1-p>0:
            D-=p
            p*=4
            K+=2
            print(D,p)
        else:
            p*=2
            print(D)
            for i in range(K+1):
                if D<p//2:
                    if flaga==True:
                        S +='1'
                    else:
                        S +='0'
                else:
                    D-=p//2
                    if flaga==True:
                        S +='0'
                    else:
                        S +='1'
                p=p//2
                flaga = not flaga
            print(S)
            exit(0)







import math
flaga=True
S='1'
N=int(input())
D=N
flag=0
p=1
K=0
if N==0:
    print(0)
    exit(0)
elif N==1:
    print(1)
    exit(0)
elif N>0:
    D-=1
    while flag==0:
        if D+1-p>0:
            D-=p
            p*=4
            K+=2
        else:
            #print(D)
            for i in range(K):
                if D<p//2:
                    if flaga==True:
                        S +='1'
                    else:
                        S +='0'
                else:
                    D-=p//2
                    if flaga==True:
                        S +='0'
                    else:
                        S +='1'
                p=p//2
                flaga = not flaga
                
            print(S)
            exit(0)
else:
    D=abs(D)-1
    p+=1
    while flag==0:
        if D-p>=0:
            D-=p
            p*=4
            K+=2
            #print(D,p)
        else:
            
            for i in range(K+1):
                if D<p//2:
                    if flaga==True:
                        S +='1'
                    else:
                        S +='0'

                else:
                    D-=p//2
                    if flaga==True:
                        S +='0'
                    else:
                        S +='1'
                flaga = not flaga
                p=p//2

            print(S)
            exit(0)





Verdicts: Wrong Answer

Accepted