Problem:
Problem I: Shuffle 2
Problem
$n$枚のカードからなる束があり、下から$i$番目のカードには$i$が書かれている。この束に対して、以下のように定義されるシャッフルを$q$回行う。
束を下から見たとき、奇数番目のカードを上に重ねていって作られる束$x$、偶数番目のカードを上に重ねていって作られる束$y$を考える。その後以下の$2$つのうち、好きな操作を行う。
操作 $0$： 束$x$の上に束$y$をのせて$1$つの束にする。
操作 $1$： 束$y$の上に束$x$をのせて$1$つの束にする。
例えば、$6$枚のカードからなる束(下から123456)に対して$1$回のシャッフルを行うことを考えたとき、操作$0$を行った場合に得られる束は下から
246135
135246、操作$1$を行った場合に得られる束は下から
135246
246135である。(14:52修正)
$q$回のシャッフルの後、$k$の書かれたカードが束の下から$d$番目にあるようにしたい。
可能であるなら$q$回のシャッフルの操作を順番に出力し、不可能ならば$-1$を出力せよ。
Input
入力は以下の形式で与えられる。
$n$ $q$ $k$ $d$
Constraints
入力は以下の条件を満たす。
$2 \le n \le 10^{15}$
$1 \le q \le 10^6$
$1 \le k,d \le n$
$n$は偶数
Output
条件を満たすシャッフルが可能なら$q$行にシャッフルの操作を出力せよ。
不可能なら$-1$を出力せよ。
Sample Input 1
4 2 1 1
Sample Output 1
0
0
Sample Input 2
4 2 3 1
Sample Output 2
0
1
Sample Input 3
4 1 1 4
Sample Output 3
-1
Sample Input 4
7834164883628 15 2189823423122 5771212644938
Sample Output 4
0
1
1
1
1
1
0
1
0
1
0
0
0
0
0

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vl = vector<ll>;
template <class T> using vec = vector<T>;
template <class T> using vv = vec<vec<T>>;
template <class T> using vvv = vv<vec<T>>;
template <class T> using minpq = priority_queue<T, vector<T>, greater<T>>;
#define all(a) (a).begin(),(a).end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define reps(i, l, r) for(ll i = (l); i < (r); ++i)
#define rrep(i, l, r) for(ll i = (r)-1; i >= (l); --i)
#define sz(x) (ll) (x).size()
template <typename T>
bool chmax(T &a, const T& b) { return a < b ? a = b, true : false; }
template <typename T>
bool chmin(T &a, const T& b) { return a > b ? a = b, true : false; }

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
class Point {
public:
    ld x;
    ld y;
    Point(ld _x = 0, ld _y = 0) : x(_x), y(_y) {}
    Point operator+(Point p) { return Point(x + p.x, y + p.y); }
    Point operator-(Point p) { return Point(x - p.x, y - p.y); }
    Point operator*(ld a) { return Point(a * x, a * y); }
    Point operator/(ld a) { return Point(x / a, y / a); }

    ld abs() { return sqrt(norm()); }
ld norm() { return x * x + y * y; }

    bool operator<(const Point& p) const {
        return !equals(x, p.x) ? x < p.x : y < p.y;
    }
    bool operator==(const Point& p) const {
        return fabs(x - p.x) < (1e-10) && fabs(y - p.y) < (1e-10);
    }
};
typedef Point Vector;
struct Segment {
    Point A;
    Point B;
};
typedef Segment Line;
class Circle {
public:
    Point C;
    ld r;
    Circle(Point C = Point(), ld r = 0.0) : C(C), r(r) {}
};
typedef vector<Point> Polygon;

struct Edge {
    ll from, to, cost;
    Edge (ll from, ll to, ll cost = 1ll) : from(from), to(to), cost(cost) {}
};
struct Graph {
    vector<vector<Edge>> G;
    Graph() = default;
    explicit Graph(ll N) : G(N) {}
    size_t size() const {
        return G.size();
    }
    void add(ll from, ll to, ll cost = 1ll, bool direct = 0) {
        G[from].emplace_back(from, to, cost);
        if (!direct) G[to].emplace_back(to, from, cost);
    }
    vector<Edge> &operator[](const int &k) {
        return G[k];
    }
};
using Edges = vector<Edge>;

ll modmul(ll a, ll b, ll mod) {
	ll ret = a * b - mod * ll(1.L / mod * a * b);
	return ret + mod * (ret < 0) - mod * (ret >= mod);
}

ll modpow(ll a, ll b, ll mod) {
	ll ans = 1;
	for(; b; a = modmul(a, a, mod), b /= 2)
		if (b & 1) ans = modmul(ans, a, mod);
	return ans;
}

void solve(){
    ll N, Q, s, t; cin >> N >> Q >> s >> t;
    s--; t--;
    vl two(Q+1, 1);
    rep(i, Q) two[i+1] = two[i] * 2 % N;
    ll u = modmul(t, two[Q], N);
    ll gap = (s + N - u) % N;
    if(Q <= 50 && two[Q] == (1LL<<Q)){
        if(gap >= two[Q]){
            cout << -1 << endl;
            return;
        }
    }
    vl ans(Q);
    ll idx = 0;
    vl inv(Q, 0);
    while(gap){
        ll y = gap % 2;
        inv[idx] = y; idx++;
        gap /= 2;
    }
    ll x = t;
    rrep(i, 0, Q){
        if(x * 2 < N) ans[i] = inv[i];
        else ans[i] = inv[i]^1;
        x = (x * 2 + inv[i]) % N;
    }
    rep(i, Q){
        cout << ans[i] << endl;
    }
    
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}
accuracy: 1
time_ms: 620
memory_kb: 24472
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

#define rep(i,n) for(ll i=0;i<n;++i)
#define all(a) (a).begin(),(a).end()
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
template<class T> T div_floor(T a, T b) { return a / b - ((a ^ b) < 0 && a % b); }
template<class T> T div_ceil(T a, T b) { return a / b + ((a ^ b) > 0 && a % b); }
template <typename T, typename U> inline bool chmin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template <typename T, typename U> inline bool chmax(T &x, U y) { return (x < y) ? (x = y, true) : false; }

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a){
    if (a.empty()) return os;
    os << a.front();
    for (auto e : a | views::drop(1)){
        os << ' ' << e;
    }
    return os;
}

void dump(auto ...vs){
    ((cout << vs << ' '), ...) << endl;
}



void solve() {
    ll N,Q,K,D;
    cin>>N>>Q>>K>>D;
    K--;
    D--;
    ll l=D;
    ll r=D+1;
    ll rest=Q;
    vector<pair<ll,ll>> P;
    rep(i,Q){
        P.push_back({l,r});
        l*=2;
        r*=2;
        ll d=l/N;
        l-=d*N;
        r-=d*N;
        rest-=1;
        if (r-l>=N){
            break;
        }
    }
    vector<ll> op;
    rep(i,rest){
        op.push_back(0);
        if (K%2==0){
            K/=2;
        }
        else{
            K/=2;
            K+=N/2;
        }
    }
    if (!((l<=K and K<r) or (l<=K+N and K+N<r))){
        cout<<-1<<endl;
        return;
    }
    reverse(all(P));
    for (auto [l,r]:P){
        ll nxt;
        nxt=K/2;
        if ((l<=nxt and nxt<r) or (l<=nxt+N and nxt+N<r)){
            if (K%2==0){
                op.push_back(0);
            }
            else{
                op.push_back(1);
            }
            K=nxt;
            continue;
        }
        nxt=K/2+N/2;
        if ((l<=nxt and nxt<r) or (l<=nxt+N and nxt+N<r)){
            if (K%2==0){
                op.push_back(1);
            }
            else{
                op.push_back(0);
            }
            K=nxt;
            continue;
        }
        assert (false);
    }
    for (ll a:op){
        cout<<a<<endl;
    }
    return;
}


int main() {
    cin.tie(0)->sync_with_stdio(0);
    ll T=1;
    while (T--){
        solve();
    }
    return 0;
}
accuracy: 1
time_ms: 330
memory_kb: 12792
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vl = vector<ll>;
template <class T> using vec = vector<T>;
template <class T> using vv = vec<vec<T>>;
template <class T> using vvv = vv<vec<T>>;
template <class T> using minpq = priority_queue<T, vector<T>, greater<T>>;
#define all(a) (a).begin(),(a).end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define reps(i, l, r) for(ll i = (l); i < (r); ++i)
#define rrep(i, l, r) for(ll i = (r)-1; i >= (l); --i)
#define sz(x) (ll) (x).size()
template <typename T>
bool chmax(T &a, const T& b) { return a < b ? a = b, true : false; }
template <typename T>
bool chmin(T &a, const T& b) { return a > b ? a = b, true : false; }

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
class Point {
public:
    ld x;
    ld y;
    Point(ld _x = 0, ld _y = 0) : x(_x), y(_y) {}
    Point operator+(Point p) { return Point(x + p.x, y + p.y); }
    Point operator-(Point p) { return Point(x - p.x, y - p.y); }
    Point operator*(ld a) { return Point(a * x, a * y); }
    Point operator/(ld a) { return Point(x / a, y / a); }

    ld abs() { return sqrt(norm()); }
ld norm() { return x * x + y * y; }

    bool operator<(const Point& p) const {
        return !equals(x, p.x) ? x < p.x : y < p.y;
    }
    bool operator==(const Point& p) const {
        return fabs(x - p.x) < (1e-10) && fabs(y - p.y) < (1e-10);
    }
};
typedef Point Vector;
struct Segment {
    Point A;
    Point B;
};
typedef Segment Line;
class Circle {
public:
    Point C;
    ld r;
    Circle(Point C = Point(), ld r = 0.0) : C(C), r(r) {}
};
typedef vector<Point> Polygon;

struct Edge {
    ll from, to, cost;
    Edge (ll from, ll to, ll cost = 1ll) : from(from), to(to), cost(cost) {}
};
struct Graph {
    vector<vector<Edge>> G;
    Graph() = default;
    explicit Graph(ll N) : G(N) {}
    size_t size() const {
        return G.size();
    }
    void add(ll from, ll to, ll cost = 1ll, bool direct = 0) {
        G[from].emplace_back(from, to, cost);
        if (!direct) G[to].emplace_back(to, from, cost);
    }
    vector<Edge> &operator[](const int &k) {
        return G[k];
    }
};
using Edges = vector<Edge>;

ll modmul(ll a, ll b, ll mod) {
	ll ret = a * b - mod * ll(1.L / mod * a * b);
	return ret + mod * (ret < 0) - mod * (ret >= mod);
}

ll modpow(ll a, ll b, ll mod) {
	ll ans = 1;
	for(; b; a = modmul(a, a, mod), b /= 2)
		if (b & 1) ans = modmul(ans, a, mod);
	return ans;
}

void solve(){
    ll N, Q, s, t; cin >> N >> Q >> s >> t;
    s--; t--;
    vl two(Q+1, 1);
    rep(i, Q) two[i+1] = two[i] * 2 % N;
    ll u = modmul(t, two[Q], N);
    ll gap = (s + N - u) % N;
    if(Q <= 50 && two[Q] == (1LL<<Q)){
        if(gap >= two[Q]){
            cout << -1 << endl;
            return;
        }
    }
    ll x = t;
    vl ans(Q);
    rep(i, Q){
        if(x * 2 < N) ans[i] = 0;
        else ans[i] = 1;
        x = (x * 2) % N;
    }
    reverse(all(ans));
    ll idx = 0;
    while(gap){
        ll y = gap % 2;
        ans[idx] ^= y; idx++;
        gap /= 2;
    }
    rep(i, Q){
        cout << ans[i] << endl;
    }
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}
accuracy: 0.16666666666666666
time_ms: 630
memory_kb: 17372
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vl = vector<ll>;
template <class T> using vec = vector<T>;
template <class T> using vv = vec<vec<T>>;
template <class T> using vvv = vv<vec<T>>;
template <class T> using minpq = priority_queue<T, vector<T>, greater<T>>;
#define all(a) (a).begin(),(a).end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define reps(i, l, r) for(ll i = (l); i < (r); ++i)
#define rrep(i, l, r) for(ll i = (r)-1; i >= (l); --i)
#define sz(x) (ll) (x).size()
template <typename T>
bool chmax(T &a, const T& b) { return a < b ? a = b, true : false; }
template <typename T>
bool chmin(T &a, const T& b) { return a > b ? a = b, true : false; }

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
class Point {
public:
    ld x;
    ld y;
    Point(ld _x = 0, ld _y = 0) : x(_x), y(_y) {}
    Point operator+(Point p) { return Point(x + p.x, y + p.y); }
    Point operator-(Point p) { return Point(x - p.x, y - p.y); }
    Point operator*(ld a) { return Point(a * x, a * y); }
    Point operator/(ld a) { return Point(x / a, y / a); }

    ld abs() { return sqrt(norm()); }
ld norm() { return x * x + y * y; }

    bool operator<(const Point& p) const {
        return !equals(x, p.x) ? x < p.x : y < p.y;
    }
    bool operator==(const Point& p) const {
        return fabs(x - p.x) < (1e-10) && fabs(y - p.y) < (1e-10);
    }
};
typedef Point Vector;
struct Segment {
    Point A;
    Point B;
};
typedef Segment Line;
class Circle {
public:
    Point C;
    ld r;
    Circle(Point C = Point(), ld r = 0.0) : C(C), r(r) {}
};
typedef vector<Point> Polygon;

struct Edge {
    ll from, to, cost;
    Edge (ll from, ll to, ll cost = 1ll) : from(from), to(to), cost(cost) {}
};
struct Graph {
    vector<vector<Edge>> G;
    Graph() = default;
    explicit Graph(ll N) : G(N) {}
    size_t size() const {
        return G.size();
    }
    void add(ll from, ll to, ll cost = 1ll, bool direct = 0) {
        G[from].emplace_back(from, to, cost);
        if (!direct) G[to].emplace_back(to, from, cost);
    }
    vector<Edge> &operator[](const int &k) {
        return G[k];
    }
};
using Edges = vector<Edge>;

ll modmul(ll a, ll b, ll mod) {
	ll ret = a * b - mod * ll(1.L / mod * a * b);
	return ret + mod * (ret < 0) - mod * (ret >= mod);
}

ll modpow(ll a, ll b, ll mod) {
	ll ans = 1;
	for(; b; a = modmul(a, a, mod), b /= 2)
		if (b & 1) ans = modmul(ans, a, mod);
	return ans;
}

void solve(){
    ll N, Q, s, t; cin >> N >> Q >> s >> t;
    s--; t--; ll M = N / 2;
    vl ans(Q, 0);
    vl two(Q+1, 1);
    rep(i, Q) two[i+1] = two[i] * 2 % N;
    ll u = modmul(t, two[Q], N);
    if(Q <= 50 && two[Q] == (1LL<<Q)){
        if((s + N - u) % N >= two[Q]){
            cout << -1 << endl;
            return;
        }
    }
    ll gap = (s + N - u) % N;
    ll x = t;
    rep(i, Q){
        if(x * 2 < N) ans[i] = 0;
        else ans[i] = 1;
        x = (x * 2) % N;
    }
    reverse(all(ans));
    ll idx = 0;
    while(gap){
        ll y = gap % 2;
        ans[idx] ^= y; idx++;
        gap >>= 1;
    }
    rep(i, Q){
        cout << ans[i] << endl;
    }
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}
accuracy: 0.16666666666666666
time_ms: 620
memory_kb: 17336
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vl = vector<ll>;
template <class T> using vec = vector<T>;
template <class T> using vv = vec<vec<T>>;
template <class T> using vvv = vv<vec<T>>;
template <class T> using minpq = priority_queue<T, vector<T>, greater<T>>;
#define all(a) (a).begin(),(a).end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define reps(i, l, r) for(ll i = (l); i < (r); ++i)
#define rrep(i, l, r) for(ll i = (r)-1; i >= (l); --i)
#define sz(x) (ll) (x).size()
template <typename T>
bool chmax(T &a, const T& b) { return a < b ? a = b, true : false; }
template <typename T>
bool chmin(T &a, const T& b) { return a > b ? a = b, true : false; }

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
class Point {
public:
    ld x;
    ld y;
    Point(ld _x = 0, ld _y = 0) : x(_x), y(_y) {}
    Point operator+(Point p) { return Point(x + p.x, y + p.y); }
    Point operator-(Point p) { return Point(x - p.x, y - p.y); }
    Point operator*(ld a) { return Point(a * x, a * y); }
    Point operator/(ld a) { return Point(x / a, y / a); }

    ld abs() { return sqrt(norm()); }
ld norm() { return x * x + y * y; }

    bool operator<(const Point& p) const {
        return !equals(x, p.x) ? x < p.x : y < p.y;
    }
    bool operator==(const Point& p) const {
        return fabs(x - p.x) < (1e-10) && fabs(y - p.y) < (1e-10);
    }
};
typedef Point Vector;
struct Segment {
    Point A;
    Point B;
};
typedef Segment Line;
class Circle {
public:
    Point C;
    ld r;
    Circle(Point C = Point(), ld r = 0.0) : C(C), r(r) {}
};
typedef vector<Point> Polygon;

struct Edge {
    ll from, to, cost;
    Edge (ll from, ll to, ll cost = 1ll) : from(from), to(to), cost(cost) {}
};
struct Graph {
    vector<vector<Edge>> G;
    Graph() = default;
    explicit Graph(ll N) : G(N) {}
    size_t size() const {
        return G.size();
    }
    void add(ll from, ll to, ll cost = 1ll, bool direct = 0) {
        G[from].emplace_back(from, to, cost);
        if (!direct) G[to].emplace_back(to, from, cost);
    }
    vector<Edge> &operator[](const int &k) {
        return G[k];
    }
};
using Edges = vector<Edge>;

ll modmul(ll a, ll b, ll mod) {
	ll ret = a * b - mod * ll(1.L / mod * a * b);
	return ret + mod * (ret < 0) - mod * (ret >= mod);
}

ll modpow(ll a, ll b, ll mod) {
	ll ans = 1;
	for(; b; a = modmul(a, a, mod), b /= 2)
		if (b & 1) ans = modmul(ans, a, mod);
	return ans;
}

void solve(){
    ll N, Q, s, t; cin >> N >> Q >> s >> t;
    s--; t--; ll M = N / 2;
    vl ans(Q, 0);
    vl two(Q+1, 1);
    rep(i, Q) two[i+1] = two[i] * 2 % N;
    ll u = modmul(t, two[Q], N);
    if(Q <= 50 && two[Q] == (1LL<<Q)){
        if((s + N - u) % N >= two[Q]){
            cout << -1 << endl;
            return;
        }
    }
    ll gap = (s + N - u) % N;
    ll x = t;
    rep(i, Q){
        if(x * 2 < N) ans[i] = 0;
        else ans[i] = 1;
        x = (x * 2) % N;
    }
    reverse(all(ans));
    ll idx = 0;
    while(gap){
        ll x = gap % 2;
        ans[idx] ^= x; idx++;
        gap >>= 1;
    }
    rep(i, Q){
        cout << ans[i] << endl;
    }
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}
accuracy: 0.16666666666666666
time_ms: 630
memory_kb: 17516
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll ILL=2167167167167167167;
const int INF=2100000000;
#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> int LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> int UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,T b){if(b<a){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
bool yneos(bool a,bool upp=false){if(a){cout<<(upp?"YES\n":"Yes\n");}else{cout<<(upp?"NO\n":"No\n");}return a;}
template<class T> void vec_out(vector<T> &p,int ty=0){
    if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'<<p[i]<<'"';}cout<<"}\n";}
    else{if(ty==1){cout<<p.size()<<"\n";}for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}}
template<class T> T vec_min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T vec_max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}
template<class T> T vec_sum(vector<T> &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;}
int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;}
template<class T> T square(T a){return a * a;}



void solve();
// POP'N ROLL MUSIC / TOMOO
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    // cin >> t;
    rep(i, 0, t) solve();
}

void solve(){
    ll N, Q, K, D;
    cin >> N >> Q >> K >> D;
    K--, D--;
    vector<int> digi(Q + 100);
    rep(k, 0, 50){
        if ((D + 1) & (1ll << k)) digi[k + Q] = 1;
    }
    auto mim = [&](int a) -> void {
        while ((int)(digi.size()) != a && digi[a] == 0) digi[a] = 1, a++;
        if ((int)digi.size() > a) digi[a] = 0;
    };
    // vec_out(digi);
    mim(0);
    rep(k, 0, 50){
        if (K & (1ll << k)) mim(k);
    }
    // vec_out(digi);
    vector<int> ans(Q);
    for (int i = Q - 1; i >= 0; i--){
        ll tmp = 0;
        rep(d, 0, 55) if (digi[d + i]) tmp += (1ll << d);
        if (tmp >= N){
            ans[i] = 1;
            rep(d, 0, 50) if (N & (1ll << d)) mim(d + i);
        }
        // vec_out(digi);
    }
    vector<int> n_ans;
    for (auto x : ans){
        n_ans.push_back((K + x) % 2);
        K /= 2;
        if (x) K += N / 2;
    }
    if (K == D){
        for (auto x : n_ans) cout << x << "\n";
    }
    else{
        cout << "-1\n";
    }
}
accuracy: 1
time_ms: 260
memory_kb: 16052
final_rank: 3

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  Int n,q,k,d;
  cin>>n>>q>>k>>d;
  k--;d--;
  
  const int MAX = 60;
  while(q>=MAX){
    cout<<(k&1)<<"\n";
    k/=2;
    q--;
  }

  using I = __int128;
  I N=n,Q=q,K=k,D=d;

  I X=((D+0)*(I(1)<<Q)-K+N-1)/N;
  I Y=((D+1)*(I(1)<<Q)-K+N-1)/N;

  if(X==Y){
    cout<<-1<<endl;
    return 0;
  }

  for(int i=0;i<q;i++){
    int b=int((X>>i)&1)^(k&1);
    k/=2;
    k+=(n/2)*int((X>>i)&1);
    cout<<b<<"\n";
  }
  assert(k==d);
  
  cout<<flush;
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3216
final_rank: 1

code_snippet: #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7;
const ll LINF=1e18;
using namespace std;
#define int long long
//template
//main
signed main(){
  int n,q,k,d;cin>>n>>q>>k>>d;
  k--;d--;
  std::vector<int> ans;
  int sd=d;
  for(int i=0;i<q;i++)sd=sd*2%n;
  int a=(k-sd+n)%n;
  std::vector<int> vs;
  for(int i=0;i<q;i++){
    vs.push_back(a%2);
    a/=2;
  }
  if(a){cout<<-1<<endl;return 0;}
  for(int i=0;i<q;i++){
    int b1=vs[q-1-i];
    int b2=(d>=n/2);
    ans.push_back(b1^b2);
    d=d*2%n+b1;
  }
  reverse(ans.begin(),ans.end());
  //cout<<d<<endl;
  for(int p:ans)cout<<p<<endl;
}
accuracy: 1
time_ms: 910
memory_kb: 22280
final_rank: 11

code_snippet: #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7;
const ll LINF=1e18;
using namespace std;
#define int long long
//template
//main
signed main(){
  int n,q,k,d;cin>>n>>q>>k>>d;
  k--;d--;
  std::vector<int> ans;
  int sd=d;
  for(int i=0;i<q;i++)sd=sd*2%n;
  int a=(k-sd+n)%n;
  int l=1;int c=0;
  for(int i=0;i<q;i++){
    l*=2;
    if(l>a)break;
    c++;
  }
  int g=pow(2,60);
  if(c==q){cout<<-1<<endl;return 0;}
  for(int i=0;i<q;i++){
    int b1=(a>>(q-1))&1;
    int b2=(d>=n/2);
    ans.push_back(b1^b2);
    a*=2;a%=g;
    d=d*2%n+b1;
  }
  reverse(ans.begin(),ans.end());
  //cout<<d<<endl;
  for(int p:ans)cout<<p<<endl;
}
accuracy: 0.16666666666666666
time_ms: 790
memory_kb: 11136
final_rank: 20

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n,q,k,d;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin>>n>>q>>k>>d;
  k--;d--;
  ll crt=d;
  rep(i,q)crt=(crt*2)%n;
  ll rest=(k-crt+n)%n;
  if(q<60&&rest>=(1LL<<q)){
    cout<<-1<<endl;
    return 0;
  }

  vector<ll> mv(q,0);
  rep(i,60){
    if((rest>>i)&1)mv[i]=1;
  }

  vector<ll> res(q);
  crt=d;
  for(ll i=q-1;i>=0;i--){
    if(crt<n/2) res[i]=mv[i];
    else res[i]=1-mv[i];
    crt=(crt*2+mv[i])%n;
  }
  assert(crt==k);
  rep(i,q)cout<<res[i]<<endl;

  return 0;
}
accuracy: 1
time_ms: 810
memory_kb: 16960
final_rank: 8

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using pint = pair<int,int>;

long long N, Q, K, D;
void solve() {
    --K, --D;
    long long pK = K, pD = D;
    for (int i = 0; i < Q; ++i) D = D * 2 % N;
    long long diff = (K - D + N) % N;

    // tmp: 逆順で見たときの 0: 2x、1: 2x+1
    vector<long long> tmp;
    while (diff) {
        tmp.push_back(diff & 1);
        diff >>= 1;
    }
    if (tmp.size() > Q) { cout << -1 << endl; return; }
    while (tmp.size() < Q) tmp.push_back(0);
    reverse(tmp.begin(), tmp.end());

    // 実際の操作に適合した復元
    vector<long long> res;
    for (int q = 0; q < tmp.size(); ++q) {
        long long nD = pD * 2;
        if (tmp[q]) ++nD;
        nD %= N;

        // nD -> pD が実際には 0 なのか 1 なのかを判定
        if (nD % 2 == 0) {
            if (pD == nD/2) res.push_back(0);
            else res.push_back(1);
        }
        else {
            if (pD == nD/2) res.push_back(1);
            else res.push_back(0);
        }
        pD = nD;
    }
    reverse(res.begin(), res.end());
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

int main() {
    cin >> N >> Q >> K >> D;
    solve();
}
accuracy: 1
time_ms: 820
memory_kb: 22288
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll under[1000500];
ll over[1000500];
ll n, q, k, d;

void query(int now) {
    ll delta = (over[now+1] - under[now+1] + 1 + n) % n;
    if(delta * 2 >= n || delta == 0) {
        under[now] = 1;
        over[now] = n;
        return;
    }
    ll after = under[now+1];
    if(after > n / 2) after - n / 2;
    ll new_under = ((after-1) * 2 + 1) % n;
    under[now] = new_under;
    over[now] = (new_under + delta * 2 - 1 + n) % n;
    return;
}

bool isin(ll under, ll over, ll val) {
    if(under <= over) {
        if(((under <= val) && (val <= over))) {
            //cout << -1 << endl;
            return true;
        }
    } else {
        if(((val >= under) || (val <= over))) {
            //cout << -1 << endl;
            return true;
        }
    }
    //cerr << "FAILED " << under << " " << over << " " << val << endl;
    return false;
}

ll one(ll now) {
    if(now % 2 == 0) {
        return now / 2;
    }
    return n / 2 + (now + 1) / 2;
}

ll zero(ll now) {
    if(now % 2 == 0) {
        return n / 2 + now / 2;
    }
    return (now + 1) / 2;
}

int main() {
    cin >> n >> q >> k >> d;
    over[q] = d;
    under[q] = d;
    for(int i = q - 1; i >= 0; i--) {
        query(i);
    }
    for(int i = 0; i <= q; i++) {
        //cout << under[i] << " " << over[i] << endl;
    }
    /*
    if(under[0] < over[0]) {
        if(!((under[0] <= k) && (k <= over[0]))) {
            //cout << -1 << endl;
            return 0;
        }
    } else {
        if(!((k >= under[0]) || (k <= over[0]))) {
            //cout << -1 << endl;
            return 0;
        }
    }
    */
    if(!isin(under[0], over[0], k)) {
        cout << -1 << endl;
        return 0;
    }
    vector<int> ans;
    ll now = k;
    for(int i = 1; i <= q; i++) {
        ll NEW = zero(now);
        //cout << i << " NEWNUMBER : " << NEW << endl;
        if(isin(under[i], over[i], NEW)) {
            ans.push_back(0);
            now = NEW;
            //cout << "0 " << now << endl;
            continue;
        }
        NEW = one(now);
        ans.push_back(1);
        now = NEW;
        //cout << "1 " << now << endl;
    }
    for(int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 810
memory_kb: 21296
final_rank: 9

code_snippet: #include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

bool check(vector<pair<ll, ll>> &v, ll x) {
  REP(i, 0, v.size()) {
    if (v[i].first <= x && x < v[i].second) {
      return true;
    }
  }
  return false;
}

int main(void) {
  ll N, Q, K, D;
  cin >> N >> Q >> K >> D, K--, D--;

  vector<vector<pair<ll, ll>>> z(Q + 1);
  z[Q].push_back(make_pair(D, D + 1));

  for (ll i = Q - 1; i >= 0; i--) {
    vector<pair<ll, ll>> v;
    REP(k, 0, z[i + 1].size()) {
      ll l = z[i + 1][k].first, h = z[i + 1][k].second;
      if (l < N / 2 && h <= N / 2) {
        v.push_back(make_pair(l * 2, h * 2));
      } else if (l < N / 2 && h > N / 2) {
        v.push_back(make_pair(l * 2, N));
        v.push_back(make_pair(0, h * 2 - N));
      } else if (l >= N / 2 && h > N / 2) {
        v.push_back(make_pair(l * 2 - N, h * 2 - N));
      }
    }

    sort(v.begin(), v.end());

    REP(k, 0, v.size()) {
      assert(v[k].first < v[k].second);
      if (z[i].size() >= 1) {
        if (z[i].back().second >= v[k].first) {
          z[i].back().second = v[k].second;
          continue;
        }
      }
      z[i].push_back(v[k]);
    }
  }

  if (!check(z[0], K)) {
    cout << -1 << endl;
  } else {
    vector<ll> ans(Q);
    ll x = K;
    REP(i, 0, Q) {
      ll n = x % 2 == 0 ? x / 2 : x / 2 + N / 2;
      if (check(z[i + 1], n)) {
        x = n;
        ans[i] = 0;
      } else {
        x = x % 2 == 0 ? x / 2 + N / 2 : x / 2;
        ans[i] = 1;
      }
    }
    REP(i, 0, Q) printf("%ld\n", ans[i]);
  }
}
accuracy: 1
time_ms: 130
memory_kb: 60012
final_rank: 7

code_snippet: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

ll n,q,k,d;
ll low[1252525], high[1252525];

int main(){
  scanf("%lld%lld%lld%lld",&n,&q,&k,&d);
  --k;--d;
  low[0] = high[0] = d;
  REP(i,q){
    low[i+1] = n; high[i+1] = -1;
    {
      ll x = low[i];
      if(x>=n/2)x-=n/2;
      CHMIN(low[i+1], 2*x);
      CHMAX(high[i+1], 2*x+1);
    }
    {
      ll x = high[i];
      if(x>=n/2)x-=n/2;
      CHMIN(low[i+1], 2*x);
      CHMAX(high[i+1], 2*x+1);
    }
    if(low[i]<=n/2-1 && n/2-1<=high[i]){
      ll x = n/2-1;
      if(x>=n/2)x-=n/2;
      CHMIN(low[i+1], 2*x);
      CHMAX(high[i+1], 2*x+1);
    }
    if(low[i]<=n/2 && n/2<=high[i]){
      ll x = n/2;
      if(x>=n/2)x-=n/2;
      CHMIN(low[i+1], 2*x);
      CHMAX(high[i+1], 2*x+1);
    }
  }
  if(k<low[q] || k>high[q]){
    puts("-1");return 0;
  }
  ll x = k;
  FORR(i,0,q){
    if(low[i]<=x/2 && x/2<=high[i]){
      puts(x%2==0 ? "0" : "1");
      x = x/2;
    }else{
      puts(x%2==0 ? "1" : "0");
      x = x/2 + n/2;
    }
  }
  assert(x == d);
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 17352
final_rank: 2

code_snippet: // need
#include <iostream>
#include <algorithm>
// data structure
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
//#include <deque>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <array>
// stream
//#include <istream>
#include <sstream>
//#include <ostream>
#include <fstream>
// etc
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>

// input
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { std::cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { std::cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC_ROW(type, n, ...)std::vector<type> __VA_ARGS__;MACRO_VEC_ROW_Init(n, __VA_ARGS__); for(int w_=0; w_<n; ++w_){MACRO_VEC_ROW_Scan(w_, __VA_ARGS__);}
template<typename T> void MACRO_VEC_ROW_Init(int n, T& t) { t.resize(n); }
template<typename First, typename...Rest>void MACRO_VEC_ROW_Init(int n, First& first, Rest&...rest) { first.resize(n); MACRO_VEC_ROW_Init(n, rest...); }
template<typename T> void MACRO_VEC_ROW_Scan(int p, T& t) { std::cin >> t[p]; }
template<typename First, typename...Rest>void MACRO_VEC_ROW_Scan(int p, First& first, Rest&...rest) { std::cin >> first[p]; MACRO_VEC_ROW_Scan(p, rest...); }
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define MAT(type, c, m, n) std::vector<std::vector<type>> c(m, std::vector<type>(n));for(auto& R:c)for(auto& w:R)std::cin>>w;
// output
#define OUT(dist) std::cout<<(dist);
#define FOUT(n, dist) std::cout<<std::fixed<<std::setprecision(n)<<(dist);
#define SOUT(n, c, dist) std::cout<<std::setw(n)<<std::setfill(c)<<(dist);
#define SP std::cout<<" ";
#define TAB std::cout<<"\t";
#define BR std::cout<<"\n";
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define ENDL std::cout<<std::endl;
#define FLUSH std::cout<<std::flush;
#define SHOW(dist) {std::cerr << #dist << "\t:" << (dist) << "\n";}
#define SHOWVECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOWVECTOR2(v) {std::cerr << #v << "\t:\n";for(const auto& xxx : v){for(const auto& yyy : xxx){std::cerr << yyy << " ";}std::cerr << "\n";}}
#define SHOWQUEUE(a) {auto tmp(a);std::cerr << #a << "\t:";while(!tmp.empty()){std::cerr << tmp.front() << " ";tmp.pop();}std::cerr << "\n";}
// utility
#define ALL(a) (a).begin(),(a).end()
#define FOR(w, a, n) for(int w=(a);w<(n);++w)
#define RFOR(w, a, n) for(int w=(n)-1;w>=(a);--w)
#define REP(w, n) for(int w=0;w<int(n);++w)
#define RREP(w, n) for(int w=int(n)-1;w>=0;--w)
#define FORLL(w, a, n) for(ll w=ll(a);w<ll(n);++w)
#define RFORLL(w, a, n) for(ll w=ll(n)-1;w>=ll(a);--w)
#define REPLL(w, n) for(ll w=0;w<ll(n);++w)
#define RREPLL(w, n) for(ll w=ll(n)-1;w>=0;--w)
#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T& a, const T b) { return a = (a > b) ? b : a; }
#define EXCEPTION(msg) throw std::string("Exception : " msg " [ in ") + __func__ + " : " + std::to_string(__LINE__) + " lines ]"
#define TRY(cond, msg) try {if (cond) EXCEPTION(msg);}catch (std::string s) {std::cerr << s << std::endl;}
//void CHECKTIME(std::function<void()> f) { auto start = std::chrono::system_clock::now(); f(); auto end = std::chrono::system_clock::now(); auto res = std::chrono::duration_cast<std::chrono::nanoseconds>((end - start)).count(); std::cerr << "[Time:" << res << "ns  (" << res / (1.0e9) << "s)]\n"; }
// test
template<class T> using V = std::vector<T>;
template<class T> using VV = V<V<T>>;

template<typename S, typename T>
std::ostream& operator<<(std::ostream& os, std::pair<S, T> p) {
	os << "(" << p.first << ", " << p.second << ")"; return os;
}

#define random_shuffle "USE std::shuffle!";

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using PAIR = std::pair<int, int>;
using PAIRLL = std::pair<ll, ll>;
constexpr int INFINT = 1 << 30;                          // 1.07x10^ 9
constexpr int INFINT_LIM = (1LL << 31) - 1;              // 2.15x10^ 9
constexpr ll INFLL = 1LL << 60;                          // 1.15x10^18
constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62);  // 9.22x10^18
constexpr double EPS = 1e-6;
constexpr int MOD = 1000000007;
constexpr double PI = 3.141592653589793238462643383279;
template<class T, size_t N> void FILL(T(&a)[N], const T& val) { for (auto& x : a) x = val; }
template<class ARY, size_t N, size_t M, class T> void FILL(ARY(&a)[N][M], const T& val) { for (auto& b : a) FILL(b, val); }
template<class T> void FILL(std::vector<T>& a, const T& val) { for (auto& x : a) x = val; }
template<class ARY, class T> void FILL(std::vector<std::vector<ARY>>& a, const T& val) { for (auto& b : a) FILL(b, val); }
// ------------>8------------------------------------->8------------

ll powMod(ll n, ll p, ll mod) {
	ll res = 1;
	while (p) {
		if (p & 1) (res *= n) %= mod;
		(n *= n) %= mod;
		p >>= 1;
	}
	return res;
}

signed main() {
	INIT;

	VAR(int, n, q, k, d);
	--k; --d;

	auto move = [&](int x, int type) {
		int t = x / 2;
		int o = x & 1;
		return t + (type != o) * (n / 2);
	};
	auto move2 = [&](int x, int type) {
		return (2 * x + type) % n;
	};

	if (q == 1) {
		int ans = -1;
		REP(t, 2) if (move(k, t) == d) ans = t;
		OUT(ans)BR;
		return 0;
	}

	[&] {

		int r = 0;
		int mi = std::min(q, 52LL);
		int now = powMod(2, q, n);
		FOR(i, q, INFINT) {
			int di = i - q;
			if (d < 1LL << di) break;
			if (d & 1LL << di) (r += now) %= n;
			(now *= 2) %= n;
		}

		int bit = (k - r) % n;
		if (bit < 0) bit += n;
		if (bit > (1LL << mi) - 1) return;

		V<int> preans;
		REP(_, mi) {
			preans.emplace_back(bit & 1);
			bit /= 2;
		}
		REP(i, q - mi) preans.emplace_back(0);

		V<int> num({ d });
		now = d;
		RREP(i, preans.size()) {
			now = move2(now, preans[i]);
			num.emplace_back(now);
		}
		std::reverse(ALL(num));

		V<int> ans;
		REP(i, num.size() - 1) {
			REP(t, 2) {
				if (move(num[i], t) == num[i + 1]) ans.emplace_back(t);
			}
		}
		if (ans.size() != q) return;

		REP(i, q) {
			OUT(ans[i])BR;
		}
		exit(0);
	}();
	OUT(-1)BR;

	return 0;
}
accuracy: 0.16666666666666666
time_ms: 60
memory_kb: 29204
final_rank: 12

code_snippet: // need
#include <iostream>
#include <algorithm>
// data structure
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
//#include <deque>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <array>
// stream
//#include <istream>
#include <sstream>
//#include <ostream>
#include <fstream>
// etc
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>

// input
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { std::cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { std::cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC_ROW(type, n, ...)std::vector<type> __VA_ARGS__;MACRO_VEC_ROW_Init(n, __VA_ARGS__); for(int w_=0; w_<n; ++w_){MACRO_VEC_ROW_Scan(w_, __VA_ARGS__);}
template<typename T> void MACRO_VEC_ROW_Init(int n, T& t) { t.resize(n); }
template<typename First, typename...Rest>void MACRO_VEC_ROW_Init(int n, First& first, Rest&...rest) { first.resize(n); MACRO_VEC_ROW_Init(n, rest...); }
template<typename T> void MACRO_VEC_ROW_Scan(int p, T& t) { std::cin >> t[p]; }
template<typename First, typename...Rest>void MACRO_VEC_ROW_Scan(int p, First& first, Rest&...rest) { std::cin >> first[p]; MACRO_VEC_ROW_Scan(p, rest...); }
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define MAT(type, c, m, n) std::vector<std::vector<type>> c(m, std::vector<type>(n));for(auto& R:c)for(auto& w:R)std::cin>>w;
// output
#define OUT(dist) std::cout<<(dist);
#define FOUT(n, dist) std::cout<<std::fixed<<std::setprecision(n)<<(dist);
#define SOUT(n, c, dist) std::cout<<std::setw(n)<<std::setfill(c)<<(dist);
#define SP std::cout<<" ";
#define TAB std::cout<<"\t";
#define BR std::cout<<"\n";
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define ENDL std::cout<<std::endl;
#define FLUSH std::cout<<std::flush;
#define SHOW(dist) {std::cerr << #dist << "\t:" << (dist) << "\n";}
#define SHOWVECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOWVECTOR2(v) {std::cerr << #v << "\t:\n";for(const auto& xxx : v){for(const auto& yyy : xxx){std::cerr << yyy << " ";}std::cerr << "\n";}}
#define SHOWQUEUE(a) {auto tmp(a);std::cerr << #a << "\t:";while(!tmp.empty()){std::cerr << tmp.front() << " ";tmp.pop();}std::cerr << "\n";}
// utility
#define ALL(a) (a).begin(),(a).end()
#define FOR(w, a, n) for(int w=(a);w<(n);++w)
#define RFOR(w, a, n) for(int w=(n)-1;w>=(a);--w)
#define REP(w, n) for(int w=0;w<int(n);++w)
#define RREP(w, n) for(int w=int(n)-1;w>=0;--w)
#define FORLL(w, a, n) for(ll w=ll(a);w<ll(n);++w)
#define RFORLL(w, a, n) for(ll w=ll(n)-1;w>=ll(a);--w)
#define REPLL(w, n) for(ll w=0;w<ll(n);++w)
#define RREPLL(w, n) for(ll w=ll(n)-1;w>=0;--w)
#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T& a, const T b) { return a = (a > b) ? b : a; }
#define EXCEPTION(msg) throw std::string("Exception : " msg " [ in ") + __func__ + " : " + std::to_string(__LINE__) + " lines ]"
#define TRY(cond, msg) try {if (cond) EXCEPTION(msg);}catch (std::string s) {std::cerr << s << std::endl;}
//void CHECKTIME(std::function<void()> f) { auto start = std::chrono::system_clock::now(); f(); auto end = std::chrono::system_clock::now(); auto res = std::chrono::duration_cast<std::chrono::nanoseconds>((end - start)).count(); std::cerr << "[Time:" << res << "ns  (" << res / (1.0e9) << "s)]\n"; }
// test
template<class T> using V = std::vector<T>;
template<class T> using VV = V<V<T>>;

template<typename S, typename T>
std::ostream& operator<<(std::ostream& os, std::pair<S, T> p) {
	os << "(" << p.first << ", " << p.second << ")"; return os;
}

#define random_shuffle "USE std::shuffle!";

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using PAIR = std::pair<int, int>;
using PAIRLL = std::pair<ll, ll>;
constexpr int INFINT = 1 << 30;                          // 1.07x10^ 9
constexpr int INFINT_LIM = (1LL << 31) - 1;              // 2.15x10^ 9
constexpr ll INFLL = 1LL << 60;                          // 1.15x10^18
constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62);  // 9.22x10^18
constexpr double EPS = 1e-6;
constexpr int MOD = 1000000007;
constexpr double PI = 3.141592653589793238462643383279;
template<class T, size_t N> void FILL(T(&a)[N], const T& val) { for (auto& x : a) x = val; }
template<class ARY, size_t N, size_t M, class T> void FILL(ARY(&a)[N][M], const T& val) { for (auto& b : a) FILL(b, val); }
template<class T> void FILL(std::vector<T>& a, const T& val) { for (auto& x : a) x = val; }
template<class ARY, class T> void FILL(std::vector<std::vector<ARY>>& a, const T& val) { for (auto& b : a) FILL(b, val); }
// ------------>8------------------------------------->8------------

ll powMod(ll n, ll p, ll mod) {
	ll res = 1;
	while (p) {
		if (p & 1) (res *= n) %= mod;
		(n *= n) %= mod;
		p >>= 1;
	}
	return res;
}

signed main() {
	INIT;

	VAR(int, n, q, k, d);
	--k; --d;

	auto move = [&](int x, int type) {
		int t = x / 2;
		int o = x & 1;
		return t + (type != o) * (n / 2);
	};
	auto move2 = [&](int x, int type) {
		return (2 * x + type) % n;
	};

	if (q == 1) {
		int ans = -1;
		REP(t, 2) if (move(k, t) == d) ans = t;
		OUT(ans)BR;
		return 0;
	}

	REP(T, 2) {
		[&] {
			int k1 = k / 2 + T * (n / 2);

			int r = 0;
			int mi = std::min(q - 1, 52LL);
			int now = powMod(2, q - 1, n);
			FOR(i, q - 1, INFINT) {
				int di = i - (q - 1);
				if (d < 1LL << di) break;
				if (d & 1LL << di) (r += now) %= n;
				(now *= 2) %= n;
			}

			int bit = (k1 - r) % MOD;
			if (bit < 0) bit += n / 2;
			if (bit > (1LL << mi) - 1) return;

			V<int> preans;
			REP(_, mi) {
				preans.emplace_back(bit & 1);
				bit /= 2;
			}
			REP(i, q - 1 - mi) preans.emplace_back(0);

			V<int> num({ d });
			now = d;
			RREP(i, preans.size()) {
				now = move2(now, preans[i]);
				num.emplace_back(now);
			}
			num.emplace_back(k);
			std::reverse(ALL(num));

			V<int> ans;
			REP(i, num.size() - 1) {
				REP(t, 2) {
					if (move(num[i], t) == num[i + 1]) ans.emplace_back(t);
				}
			}
			if (ans.size() != q) return;

			REP(i, q) {
				OUT(ans[i])BR;
			}
			exit(0);
		}();
	}
	OUT(-1)BR;

	return 0;
}
accuracy: 0.16666666666666666
time_ms: 50
memory_kb: 32200
final_rank: 13

code_snippet: // need
#include <iostream>
#include <algorithm>
// data structure
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
//#include <deque>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <array>
// stream
//#include <istream>
#include <sstream>
//#include <ostream>
#include <fstream>
// etc
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>

// input
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { std::cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { std::cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC_ROW(type, n, ...)std::vector<type> __VA_ARGS__;MACRO_VEC_ROW_Init(n, __VA_ARGS__); for(int w_=0; w_<n; ++w_){MACRO_VEC_ROW_Scan(w_, __VA_ARGS__);}
template<typename T> void MACRO_VEC_ROW_Init(int n, T& t) { t.resize(n); }
template<typename First, typename...Rest>void MACRO_VEC_ROW_Init(int n, First& first, Rest&...rest) { first.resize(n); MACRO_VEC_ROW_Init(n, rest...); }
template<typename T> void MACRO_VEC_ROW_Scan(int p, T& t) { std::cin >> t[p]; }
template<typename First, typename...Rest>void MACRO_VEC_ROW_Scan(int p, First& first, Rest&...rest) { std::cin >> first[p]; MACRO_VEC_ROW_Scan(p, rest...); }
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define MAT(type, c, m, n) std::vector<std::vector<type>> c(m, std::vector<type>(n));for(auto& R:c)for(auto& w:R)std::cin>>w;
// output
#define OUT(dist) std::cout<<(dist);
#define FOUT(n, dist) std::cout<<std::fixed<<std::setprecision(n)<<(dist);
#define SOUT(n, c, dist) std::cout<<std::setw(n)<<std::setfill(c)<<(dist);
#define SP std::cout<<" ";
#define TAB std::cout<<"\t";
#define BR std::cout<<"\n";
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define ENDL std::cout<<std::endl;
#define FLUSH std::cout<<std::flush;
#define SHOW(dist) {std::cerr << #dist << "\t:" << (dist) << "\n";}
#define SHOWVECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOWVECTOR2(v) {std::cerr << #v << "\t:\n";for(const auto& xxx : v){for(const auto& yyy : xxx){std::cerr << yyy << " ";}std::cerr << "\n";}}
#define SHOWQUEUE(a) {auto tmp(a);std::cerr << #a << "\t:";while(!tmp.empty()){std::cerr << tmp.front() << " ";tmp.pop();}std::cerr << "\n";}
// utility
#define ALL(a) (a).begin(),(a).end()
#define FOR(w, a, n) for(int w=(a);w<(n);++w)
#define RFOR(w, a, n) for(int w=(n)-1;w>=(a);--w)
#define REP(w, n) for(int w=0;w<int(n);++w)
#define RREP(w, n) for(int w=int(n)-1;w>=0;--w)
#define FORLL(w, a, n) for(ll w=ll(a);w<ll(n);++w)
#define RFORLL(w, a, n) for(ll w=ll(n)-1;w>=ll(a);--w)
#define REPLL(w, n) for(ll w=0;w<ll(n);++w)
#define RREPLL(w, n) for(ll w=ll(n)-1;w>=0;--w)
#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T& a, const T b) { return a = (a > b) ? b : a; }
#define EXCEPTION(msg) throw std::string("Exception : " msg " [ in ") + __func__ + " : " + std::to_string(__LINE__) + " lines ]"
#define TRY(cond, msg) try {if (cond) EXCEPTION(msg);}catch (std::string s) {std::cerr << s << std::endl;}
//void CHECKTIME(std::function<void()> f) { auto start = std::chrono::system_clock::now(); f(); auto end = std::chrono::system_clock::now(); auto res = std::chrono::duration_cast<std::chrono::nanoseconds>((end - start)).count(); std::cerr << "[Time:" << res << "ns  (" << res / (1.0e9) << "s)]\n"; }
// test
template<class T> using V = std::vector<T>;
template<class T> using VV = V<V<T>>;

template<typename S, typename T>
std::ostream& operator<<(std::ostream& os, std::pair<S, T> p) {
	os << "(" << p.first << ", " << p.second << ")"; return os;
}

#define random_shuffle "USE std::shuffle!";

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using PAIR = std::pair<int, int>;
using PAIRLL = std::pair<ll, ll>;
constexpr int INFINT = 1 << 30;                          // 1.07x10^ 9
constexpr int INFINT_LIM = (1LL << 31) - 1;              // 2.15x10^ 9
constexpr ll INFLL = 1LL << 60;                          // 1.15x10^18
constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62);  // 9.22x10^18
constexpr double EPS = 1e-6;
constexpr int MOD = 1000000007;
constexpr double PI = 3.141592653589793238462643383279;
template<class T, size_t N> void FILL(T(&a)[N], const T& val) { for (auto& x : a) x = val; }
template<class ARY, size_t N, size_t M, class T> void FILL(ARY(&a)[N][M], const T& val) { for (auto& b : a) FILL(b, val); }
template<class T> void FILL(std::vector<T>& a, const T& val) { for (auto& x : a) x = val; }
template<class ARY, class T> void FILL(std::vector<std::vector<ARY>>& a, const T& val) { for (auto& b : a) FILL(b, val); }
// ------------>8------------------------------------->8------------

ll powMod(ll n, ll p, ll mod) {
	ll res = 1;
	while (p) {
		if (p & 1) (res *= n) %= mod;
		(n *= n) %= mod;
		p >>= 1;
	}
	return res;
}

signed main() {
	INIT;

	VAR(int, n, q, k, d);
	--k; --d;

	auto move = [&](int x, int type) {
		int t = x / 2;
		int o = x & 1;
		return t + (type != o) * (n / 2);
	};
	auto move2 = [&](int x, int type) {
		return (2 * (x % (n / 2)) + type) % (n);
	};

	if (q == 1) {
		int ans = -1;
		REP(t, 2) if (move(k, t) == d) ans = t;
		OUT(ans)BR;
		return 0;
	}

	REP(T, 2) {
		[&] {
			int k1 = k / 2 + T * (n / 2);

			int r = 0;
			int mi = std::min(q - 1, 52LL);
			int now = powMod(2, mi, n / 2);
			FOR(i, mi, INFINT) {
				if (i >= q - 1) {
					int di = i - (q - 1);
					if (d < 1LL << di) break;
					if (d & 1LL << di) (r += now) %= n / 2;
				}
				(now *= 2) %= n / 2;
			}

			int bit = (k1 - r) % MOD;
			if (bit < 0) bit += n / 2;
			if (bit > (1LL << mi) - 1) return;

			V<int> preans;
			REP(_, mi) {
				preans.emplace_back(bit & 1);
				bit /= 2;
			}
			REP(i, q - 1 - mi) preans.emplace_back(0);

			V<int> num({ d });
			now = d;
			RREP(i, preans.size()) {
				now = move2(now, preans[i]);
				num.emplace_back(now);
			}
			num.emplace_back(k);
			std::reverse(ALL(num));

			V<int> ans;
			REP(i, num.size() - 1) {
				REP(t, 2) {
					if (move(num[i], t) == num[i + 1]) ans.emplace_back(t);
				}
			}
			if (ans.size() != q) return;

			REP(i, q) {
				OUT(ans[i])BR;
			}
			exit(0);
		}();
	}
	OUT(-1)BR;

	return 0;
}
accuracy: 0.16666666666666666
time_ms: 90
memory_kb: 32184
final_rank: 14

code_snippet: // need
#include <iostream>
#include <algorithm>
// data structure
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
//#include <deque>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <array>
// stream
//#include <istream>
#include <sstream>
//#include <ostream>
#include <fstream>
// etc
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>

// input
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { std::cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { std::cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC_ROW(type, n, ...)std::vector<type> __VA_ARGS__;MACRO_VEC_ROW_Init(n, __VA_ARGS__); for(int w_=0; w_<n; ++w_){MACRO_VEC_ROW_Scan(w_, __VA_ARGS__);}
template<typename T> void MACRO_VEC_ROW_Init(int n, T& t) { t.resize(n); }
template<typename First, typename...Rest>void MACRO_VEC_ROW_Init(int n, First& first, Rest&...rest) { first.resize(n); MACRO_VEC_ROW_Init(n, rest...); }
template<typename T> void MACRO_VEC_ROW_Scan(int p, T& t) { std::cin >> t[p]; }
template<typename First, typename...Rest>void MACRO_VEC_ROW_Scan(int p, First& first, Rest&...rest) { std::cin >> first[p]; MACRO_VEC_ROW_Scan(p, rest...); }
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define MAT(type, c, m, n) std::vector<std::vector<type>> c(m, std::vector<type>(n));for(auto& R:c)for(auto& w:R)std::cin>>w;
// output
#define OUT(dist) std::cout<<(dist);
#define FOUT(n, dist) std::cout<<std::fixed<<std::setprecision(n)<<(dist);
#define SOUT(n, c, dist) std::cout<<std::setw(n)<<std::setfill(c)<<(dist);
#define SP std::cout<<" ";
#define TAB std::cout<<"\t";
#define BR std::cout<<"\n";
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define ENDL std::cout<<std::endl;
#define FLUSH std::cout<<std::flush;
#define SHOW(dist) {std::cerr << #dist << "\t:" << (dist) << "\n";}
#define SHOWVECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOWVECTOR2(v) {std::cerr << #v << "\t:\n";for(const auto& xxx : v){for(const auto& yyy : xxx){std::cerr << yyy << " ";}std::cerr << "\n";}}
#define SHOWQUEUE(a) {auto tmp(a);std::cerr << #a << "\t:";while(!tmp.empty()){std::cerr << tmp.front() << " ";tmp.pop();}std::cerr << "\n";}
// utility
#define ALL(a) (a).begin(),(a).end()
#define FOR(w, a, n) for(int w=(a);w<(n);++w)
#define RFOR(w, a, n) for(int w=(n)-1;w>=(a);--w)
#define REP(w, n) for(int w=0;w<int(n);++w)
#define RREP(w, n) for(int w=int(n)-1;w>=0;--w)
#define FORLL(w, a, n) for(ll w=ll(a);w<ll(n);++w)
#define RFORLL(w, a, n) for(ll w=ll(n)-1;w>=ll(a);--w)
#define REPLL(w, n) for(ll w=0;w<ll(n);++w)
#define RREPLL(w, n) for(ll w=ll(n)-1;w>=0;--w)
#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T& a, const T b) { return a = (a > b) ? b : a; }
#define EXCEPTION(msg) throw std::string("Exception : " msg " [ in ") + __func__ + " : " + std::to_string(__LINE__) + " lines ]"
#define TRY(cond, msg) try {if (cond) EXCEPTION(msg);}catch (std::string s) {std::cerr << s << std::endl;}
//void CHECKTIME(std::function<void()> f) { auto start = std::chrono::system_clock::now(); f(); auto end = std::chrono::system_clock::now(); auto res = std::chrono::duration_cast<std::chrono::nanoseconds>((end - start)).count(); std::cerr << "[Time:" << res << "ns  (" << res / (1.0e9) << "s)]\n"; }
// test
template<class T> using V = std::vector<T>;
template<class T> using VV = V<V<T>>;

template<typename S, typename T>
std::ostream& operator<<(std::ostream& os, std::pair<S, T> p) {
	os << "(" << p.first << ", " << p.second << ")"; return os;
}

#define random_shuffle "USE std::shuffle!";

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using PAIR = std::pair<int, int>;
using PAIRLL = std::pair<ll, ll>;
constexpr int INFINT = 1 << 30;                          // 1.07x10^ 9
constexpr int INFINT_LIM = (1LL << 31) - 1;              // 2.15x10^ 9
constexpr ll INFLL = 1LL << 60;                          // 1.15x10^18
constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62);  // 9.22x10^18
constexpr double EPS = 1e-6;
constexpr int MOD = 1000000007;
constexpr double PI = 3.141592653589793238462643383279;
template<class T, size_t N> void FILL(T(&a)[N], const T& val) { for (auto& x : a) x = val; }
template<class ARY, size_t N, size_t M, class T> void FILL(ARY(&a)[N][M], const T& val) { for (auto& b : a) FILL(b, val); }
template<class T> void FILL(std::vector<T>& a, const T& val) { for (auto& x : a) x = val; }
template<class ARY, class T> void FILL(std::vector<std::vector<ARY>>& a, const T& val) { for (auto& b : a) FILL(b, val); }
// ------------>8------------------------------------->8------------

ll powMod(ll n, ll p, ll mod) {
	ll res = 1;
	while (p) {
		if (p & 1) (res *= n) %= mod;
		(n *= n) %= mod;
		p >>= 1;
	}
	return res;
}

signed main() {
	INIT;

	VAR(int, n, q, k, d);
	--k; --d;

	auto move = [&](int x, int type) {
		int t = x / 2;
		int o = x & 1;
		return t + (type != o) * (n / 2);
	};
	auto move2 = [&](int x, int type) {
		return (2 * (x % (n / 2)) + type) % (n);
	};

	if (q == 1) {
		int ans = -1;
		REP(t, 2) if (move(k, t) == d) ans = t;
		OUT(ans)BR;
		return 0;
	}

	REP(T, 2) {
		[&] {
			int k1 = k / 2 + T * (n / 2);

			int r = 0;
			int mi = std::min(q - 1, 49LL);
			int now = powMod(2, mi, n / 2);
			FOR(i, mi, INFINT) {
				if (i >= q - 1) {
					int di = i - (q - 1);
					if (d < 1LL << di) break;
					if (d & 1LL << di) (r += now) %= n / 2;
				}
				(now *= 2) %= n / 2;
			}

			int bit = (k1 - r) % MOD;
			if (bit < 0) bit += n / 2;
			if (bit > (1LL << mi) - 1) return;

			V<int> preans;
			REP(_, mi) {
				preans.emplace_back(bit & 1);
				bit /= 2;
			}
			REP(i, q - 1 - mi) preans.emplace_back(0);

			V<int> num({ d });
			now = d;
			RREP(i, preans.size()) {
				now = move2(now, preans[i]);
				num.emplace_back(now);
			}
			num.emplace_back(k);
			std::reverse(ALL(num));

			V<int> ans;
			REP(i, num.size() - 1) {
				REP(t, 2) {
					if (move(num[i], t) == num[i + 1]) ans.emplace_back(t);
				}
			}
			if (ans.size() != q) return;

			REP(i, q) {
				OUT(ans[i])BR;
			}
			exit(0);
		}();
	}
	OUT(-1)BR;

	return 0;
}
accuracy: 0.16666666666666666
time_ms: 90
memory_kb: 32348
final_rank: 15

code_snippet: // need
#include <iostream>
#include <algorithm>
// data structure
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
//#include <deque>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <array>
// stream
//#include <istream>
#include <sstream>
//#include <ostream>
#include <fstream>
// etc
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>

// input
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { std::cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { std::cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC_ROW(type, n, ...)std::vector<type> __VA_ARGS__;MACRO_VEC_ROW_Init(n, __VA_ARGS__); for(int w_=0; w_<n; ++w_){MACRO_VEC_ROW_Scan(w_, __VA_ARGS__);}
template<typename T> void MACRO_VEC_ROW_Init(int n, T& t) { t.resize(n); }
template<typename First, typename...Rest>void MACRO_VEC_ROW_Init(int n, First& first, Rest&...rest) { first.resize(n); MACRO_VEC_ROW_Init(n, rest...); }
template<typename T> void MACRO_VEC_ROW_Scan(int p, T& t) { std::cin >> t[p]; }
template<typename First, typename...Rest>void MACRO_VEC_ROW_Scan(int p, First& first, Rest&...rest) { std::cin >> first[p]; MACRO_VEC_ROW_Scan(p, rest...); }
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define MAT(type, c, m, n) std::vector<std::vector<type>> c(m, std::vector<type>(n));for(auto& R:c)for(auto& w:R)std::cin>>w;
// output
#define OUT(dist) std::cout<<(dist);
#define FOUT(n, dist) std::cout<<std::fixed<<std::setprecision(n)<<(dist);
#define SOUT(n, c, dist) std::cout<<std::setw(n)<<std::setfill(c)<<(dist);
#define SP std::cout<<" ";
#define TAB std::cout<<"\t";
#define BR std::cout<<"\n";
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define ENDL std::cout<<std::endl;
#define FLUSH std::cout<<std::flush;
#define SHOW(dist) {std::cerr << #dist << "\t:" << (dist) << "\n";}
#define SHOWVECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOWVECTOR2(v) {std::cerr << #v << "\t:\n";for(const auto& xxx : v){for(const auto& yyy : xxx){std::cerr << yyy << " ";}std::cerr << "\n";}}
#define SHOWQUEUE(a) {auto tmp(a);std::cerr << #a << "\t:";while(!tmp.empty()){std::cerr << tmp.front() << " ";tmp.pop();}std::cerr << "\n";}
// utility
#define ALL(a) (a).begin(),(a).end()
#define FOR(w, a, n) for(int w=(a);w<(n);++w)
#define RFOR(w, a, n) for(int w=(n)-1;w>=(a);--w)
#define REP(w, n) for(int w=0;w<int(n);++w)
#define RREP(w, n) for(int w=int(n)-1;w>=0;--w)
#define FORLL(w, a, n) for(ll w=ll(a);w<ll(n);++w)
#define RFORLL(w, a, n) for(ll w=ll(n)-1;w>=ll(a);--w)
#define REPLL(w, n) for(ll w=0;w<ll(n);++w)
#define RREPLL(w, n) for(ll w=ll(n)-1;w>=0;--w)
#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T& a, const T b) { return a = (a > b) ? b : a; }
#define EXCEPTION(msg) throw std::string("Exception : " msg " [ in ") + __func__ + " : " + std::to_string(__LINE__) + " lines ]"
#define TRY(cond, msg) try {if (cond) EXCEPTION(msg);}catch (std::string s) {std::cerr << s << std::endl;}
//void CHECKTIME(std::function<void()> f) { auto start = std::chrono::system_clock::now(); f(); auto end = std::chrono::system_clock::now(); auto res = std::chrono::duration_cast<std::chrono::nanoseconds>((end - start)).count(); std::cerr << "[Time:" << res << "ns  (" << res / (1.0e9) << "s)]\n"; }
// test
template<class T> using V = std::vector<T>;
template<class T> using VV = V<V<T>>;

template<typename S, typename T>
std::ostream& operator<<(std::ostream& os, std::pair<S, T> p) {
	os << "(" << p.first << ", " << p.second << ")"; return os;
}

#define random_shuffle "USE std::shuffle!";

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using PAIR = std::pair<int, int>;
using PAIRLL = std::pair<ll, ll>;
constexpr int INFINT = 1 << 30;                          // 1.07x10^ 9
constexpr int INFINT_LIM = (1LL << 31) - 1;              // 2.15x10^ 9
constexpr ll INFLL = 1LL << 60;                          // 1.15x10^18
constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62);  // 9.22x10^18
constexpr double EPS = 1e-6;
constexpr int MOD = 1000000007;
constexpr double PI = 3.141592653589793238462643383279;
template<class T, size_t N> void FILL(T(&a)[N], const T& val) { for (auto& x : a) x = val; }
template<class ARY, size_t N, size_t M, class T> void FILL(ARY(&a)[N][M], const T& val) { for (auto& b : a) FILL(b, val); }
template<class T> void FILL(std::vector<T>& a, const T& val) { for (auto& x : a) x = val; }
template<class ARY, class T> void FILL(std::vector<std::vector<ARY>>& a, const T& val) { for (auto& b : a) FILL(b, val); }
// ------------>8------------------------------------->8------------

ll powMod(ll n, ll p, ll mod) {
	ll res = 1;
	while (p) {
		if (p & 1) (res *= n) %= mod;
		(n *= n) %= mod;
		p >>= 1;
	}
	return res;
}

signed main() {
	INIT;

	VAR(int, n, q, k, d);
	--k; --d;

	auto move = [&](int x, int type) {
		int t = x / 2;
		int o = x & 1;
		return t + (type != o) * (n / 2);
	};
	auto move2 = [&](int x, int type) {
		return (2 * (x % (n / 2)) + type) % (n);
	};

	if (q == 1) {
		int ans = -1;
		REP(t, 2) if (move(k, t) == d) ans = t;
		OUT(ans)BR;
		return 0;
	}

	REP(T, 2) {
		[&] {
			int k1 = k / 2 + T * (n / 2);

			int r = 0;
			int mi = std::min(q - 1, 49LL);
			int now = powMod(2, mi, n / 2);
			FOR(i, mi, INFINT) {
				if (i >= q - 1) {
					int di = i - (q - 1);
					if (d < 1LL << di) break;
					if (d & 1LL << di) (r += now) %= n / 2;
				}
				(now *= 2) %= n / 2;
			}

			int bit = (k1 - r) % MOD;
			if (bit < 0) bit += n / 2;
			if (bit > (1LL << mi) - 1) return;

			V<int> preans;
			REP(_, mi) {
				preans.emplace_back(bit & 1);
				bit /= 2;
			}
			REP(i, q - 1 - mi) preans.emplace_back(0);

			V<int> num({ d });
			now = d;
			RREP(i, preans.size()) {
				now = move2(now, preans[i]);
				num.emplace_back(now);
			}
			num.emplace_back(k);
			std::reverse(ALL(num));

			V<int> ans;
			REP(i, num.size() - 1) {
				REP(t, 2) {
					if (move(num[i], t) == num[i + 1]) ans.emplace_back(t);
				}
			}
			if (ans.size() != q) return;

			REP(i, q) {
				OUT(ans[i])BR;
			}
			exit(0);
		}();
	}
	OUT(-1)BR;

	return 0;
}
accuracy: 0.16666666666666666
time_ms: 90
memory_kb: 32424
final_rank: 16

code_snippet: #include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

LL mod = 1000000007;

struct hoge{
  public:
  LL a, b, c, d;
  public:
  LL num;

public:
  hoge(LL a, LL b, LL c, LL d,LL num) : a(a), b(b), c(c), d(d),num(num) {}
};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  LL n, q, k, d;
  cin >> n >> q >> k >> d;

  k--;
  d--;

  vector<hoge> v;

  v.push_back(hoge(d, d, d, d, 1));

  FOR(i,1,q+1){
    hoge prev = v[i - 1];
    hoge nowhoge = hoge((prev.a * 2) % n, (prev.b * 2) % n, (prev.c * 2) % n, (prev.d * 2+1) % n, (prev.num * 2));

    if(nowhoge.d<nowhoge.a){
      nowhoge.d += n;
    }

    if (nowhoge.num >= n)
    {
      nowhoge.d += n;
      v.push_back(nowhoge);
      break;
    }
    v.push_back(nowhoge);
  }

  hoge last = v[v.size() - 1];

  LL now = k;

  if(last.num>=n){
    for (LL i = 0; i < q - v.size() + 1;++i)
    {
      if(now%2==0){
        cout << 0 << endl;
      }
      else
      {
        cout << 1 << endl;
      }
      now /= 2;
    }
  }

  REP(i,v.size()-1){
    hoge nowhoge = v[v.size() - i-1];
    hoge nexthoge = v[v.size() - i-2];

    bool flag = false;
    REP(j, 2)
    {
      //cout << nowhoge.a << " " << now << " " << nowhoge.d << endl;
      if (nowhoge.a <= now && now <= nowhoge.d)
      {

        bool a = now % 2 == 0;

        now = ((now - nowhoge.a) / 2 + nexthoge.a) % n;

        if(a ^ (now/(n/2)!=0))
        {
          cout << 0 << endl;
        }else{
          cout << 1 << endl;
        }

        flag = true;
        break;
      }
      now += n;
    }
    if(flag)
      continue;

    cout << -1 << endl;
    break;
  }
}
accuracy: 1
time_ms: 770
memory_kb: 3192
final_rank: 5