Source Code
/// Zengy Manga
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;

#include "bits/stdc++.h"
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace __gnu_pbds;
using namespace __gnu_cxx;

using ll = long long;
using ii = pair<int, int>;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define pb push_back
#define F first
#define S second
#define f(i, a, b)  for(int i = a; i < b; i++)
#define all(a)  a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define popCnt(x) (__builtin_popcountll(x))
#define int ll

const int N = 1e6+5, LG = log2(N) + 1, MOD = 1e9 + 7;
const double PI = acos(-1);

vector<int> ans;
//int dp[10005][2][2][2][2];
vector<int> ind;
string str;
//int solve(int index, bool start, bool startVal, bool previous, bool previousVal) {   ///(index,startXoredOrNot,previousXored)
//    if(index==str.size()) {
//
//    }
//    int &ret =dp[index][start][startVal][previous][previousVal];
//    if(~ret)
//        return ret;
//    ret = 0;
//    bool val = (str[index]-'0') ^ previous;
//    ///do I xor or not
//    if(index == 1) {
//        ret = solve(index + 1, start, startVal ^ 1, 1, val ^ 1)
//        | solve(index + 1, start, startVal, 0, val);
//    }
//    else if(index + 1 != str.size()) {
//        if((previousVal^1) == 1) {
//            ret = solve(index + 1, start,, 1, val^1);
//        }   else {
//            ret = solve(index + 1, start, 0, val);
//        }
//    }   else {
//
//
//    }
//    return ret;
//}
bool check() {

    f(i,0,2)
    f(j,0,2)
    f(k,0,2) {
        vector<bool> go(str.size());
        go[0]=i;
        go[1]=j;
        go.back()=k;
        for(int i = 2; i + 1 < go.size(); i++) {
            bool val = (str[i-1] - '0') ^ go[i-1] ^ go[i-2];
            go[i] = !val;
        }
        bool ok = true;
        f(i,0,str.size()) {
            bool val = (str[i] - '0') ^ go[i] ^ (go[(i+str.size()-1)%str.size()]) ^ (go[(i+str.size()+1)%str.size()]);
            ok &= val;
        }
        if(ok) {
            f(i,0,go.size())if(go[i])ans.pb(ind[i]);
            return true;
        }
    }
    return false;
}

void doWork() {

    int n;
    cin >> n;
    string s;
    cin >> s;
    s = "#" + s;
    vector<bool> vis(n + 1);
    f(i,1,n+1)if(!vis[i]) {
        ind.clear();
        str.clear();
        for(int j = i; !vis[j]; j = (j + (n / 2) - 1) % n + 1) {
            vis[j] = true;
            str.pb(s[j]);
            ind.pb(j);
        }
        if(!check()) {
            cout << "-1\n";
            return;
        }
    }
    cout << sz(ans) << '\n';
    for(int i = 0; i  < sz(ans); i++)
        cout << ans[i] << " \n"[i+1==sz(ans)];

}
int32_t main() {
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif // ONLINE_JUDGE

    int t = 1;
//    cin >> t;
    while (t--) {
        doWork();
    }


    return 0;
}
Copy
Binary Circle DeadlyPillow
GNU G++17
5 ms
1.5 MB
Accepted