Source Code
import math as m
ans = []
def check():
    k = True
    if(a[-1] != 1):
        k = False
    
    for i in range(len(a)-1):
        if(a[i]!=0):
            k = False
    return k
def flip(i):
    b = (i + m.ceil((len(a)/2)-1 )% len(a)) + 1
    c = (i - m.ceil((len(a)/2) - 1 )% len(a)) + 1
    
    ans.append(i)
    if(a[i]==0):
        a[i] = 1
    else:
        a[i] = 0
    if((b>0) and b<len(a)):
        if(a[b] == 0):
            a[b] = 1
        else:
            a[b] = 0
    if((c>0) and c<len(a)):
        if(a[c] == 0):
            a[c] = 1
        else:
            a[c] = 0
n = input("")
a = input("")

a = [int(i) for i in a]
l = int(n)-1
if(a[(l)] == 0):
    flip((len(a)-1))
r = int((len(a)-1)/2)        
for i in range(int(n)*7):
    while(r>1):
        if(a[r]==1):
            flip(r)
            break
        else:
            r = int(r/2)
            
if(check()):
    print(len(ans))
    for i in range(len(ans)):
        print(ans[i],end = " ")
else:
    print(-1)
Copy
Binary Circle cheeesy
Python 3
19 ms
3.4 MB
Wrong Answer