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):
n = int(input())

plus = []
minus = []
plus_sum = []
minus_sum = []

s_p = 0
s_m = 0
for i in range(31):
    if i % 2 == 0:
        plus.append(2**i)
        s_p += 2**i
        plus_sum.append(s_p)
    else:
        minus.append(2**i)
        s_m += 2**i
        minus_sum.append(s_m)

def ten_four(num):
    def for_four(num, arr):
        if num == 0:
            if arr == []:
                return '0'
            else:
                arr_str = map(str, arr[::-1])
                ans = (''.join(arr_str))
                return ans
        else:
            s = num // 4
            a = num % 4
            arr.append(a)
            return for_four(s, arr)
    
    arr = []
    return for_four(num, arr)


if n == 0:
    print(0)
elif n == 1:
    print(1)
elif n == -1:
    print(11)
elif n == -2:
    print(10)

elif n > 0:
    for i in range(len(plus_sum)):
        if n <= plus_sum[i]:
            max_4 = i - 1
            n_4 = n - 1 - plus_sum[max_4]
            break
        else:
            pass
    n_4zf = ten_four(n_4).zfill(max_4 + 1)
    n_ans = n_4zf.translate(str.maketrans({'0': '10', '1': '11', '2': '00', '3': '01'}))
    print('1'+n_ans)

elif n < 0:
    n_1 = n % 2
    n = int(abs((n - n_1)/2))
    print(n)
    for i in range(len(plus_sum)):
        if n <= plus_sum[i]:
            max_4 = i - 1
            n_4 = n - 1 - plus_sum[max_4]
            break
        else:
            pass
    n_4zf = ten_four(n_4).zfill(max_4 + 1)
    n_ans = n_4zf.translate(str.maketrans({'0': '10', '1': '11', '2': '00', '3': '01'}))
    print('1'+n_ans+str(n_1))

n = int(input())

plus = []
minus = []
plus_sum = []
minus_sum = []

s_p = 0
s_m = 0
for i in range(31):
    if i % 2 == 0:
        plus.append(2**i)
        s_p += 2**i
        plus_sum.append(s_p)
    else:
        minus.append(2**i)
        s_m += 2**i
        minus_sum.append(s_m)

def ten_four(num):
    def for_four(num, arr):
        if num == 0:
            if arr == []:
                return '0'
            else:
                arr_str = map(str, arr[::-1])
                ans = (''.join(arr_str))
                return ans
        else:
            s = num // 4
            a = num % 4
            arr.append(a)
            return for_four(s, arr)
    
    arr = []
    return for_four(num, arr)


if n == 0:
    print(0)
elif n == 1:
    print(1)
elif n == -1:
    print(11)
elif n == -2:
    print(10)

elif n > 0:
    for i in range(len(plus_sum)):
        if n <= plus_sum[i]:
            max_4 = i - 1
            n_4 = n - 1 - plus_sum[max_4]
            break
        else:
            pass
    n_4zf = ten_four(n_4).zfill(max_4 + 1)
    n_ans = n_4zf.translate(str.maketrans({'0': '10', '1': '11', '2': '00', '3': '01'}))
    print('1'+n_ans)

elif n < 0:
    n_1 = n % 2
    n = int(abs((n - n_1)/2))
    for i in range(len(plus_sum)):
        if n <= plus_sum[i]:
            max_4 = i - 1
            n_4 = n - 1 - plus_sum[max_4]
            break
        else:
            pass
    n_4zf = ten_four(n_4).zfill(max_4 + 1)
    n_ans = n_4zf.translate(str.maketrans({'0': '10', '1': '11', '2': '00', '3': '01'}))
    print('1'+n_ans+str(n_1))

Verdicts: Wrong Answer

Accepted