#include <bits/stdc++.h>
#include "code.h"

using namespace std;

vector<pair<int, int>> ZapisiTacke(int N){
    vector<pair<int, int>> tacke(N+1);
    for (int i = 1; i < N; i++) {
        tacke[i] = {i, 0};
    }
    tacke[N] = {0, 1};
    return tacke;
}

vector<int> Resi(int N, int Q){
    vector<int> resenje(N+1, 1e8);
    resenje[0] = 1;
    int a = 1, b = 2, c = -1;
    for (int i = 3; i <= N; i++) {
        if (Pitaj(a, b, i) != 0) {
            c = i;
            break;
        }
    }
    vector<int> v = {a, b, c};
    int p;
    for (int id = 0; id < 3; id++) {
        int ka = v[id];
        vector<int> ot;
        for (auto& e : v) {
            if (e != ka) {
                ot.push_back(e);
            }
        }
        int u = ot[0], v = ot[1];
        bool ok = true;
        for (int i = 1; i <= N; i++) {
            if (u == i || v == i || ka == i) {
                continue;
            }
            if (Pitaj(u, v, i) != 0) {
                ok = false;
                break;
            }
        }
        if (ok) {
            p = ka;
            break;
        }
    }
    vector<int> l;
    for (int i = 1; i <= N; i++) {
        if (i != p) {
            l.push_back(i);
        }
    }

    sort(l.begin(), l.end(), [&](int x, int y){return Pitaj(x, y, p) == 1;});
    for (int i = 0; i < N; i++) {
        resenje[l[i]] = i+1;
    }
    resenje[p] = N;
    return resenje;
}