#include <bits/stdc++.h>
#include "code.h"
using namespace std;
#define fi first
#define sc second
typedef pair<int,int> t;

vector<t> tacke;

vector<t> ZapisiTacke(int N){
    tacke.resize(N+1);
    tacke[1] = {0, 1};

    for(int i = 2; i <= N; i++){
        tacke[i] = {i, 0};
    }

    return tacke;
}

vector<int> Resi(int N, int Q){
    int cc = 0;
    auto ask = [&](int a, int b, int c){
        cc++;
        return Pitaj(a, b, c);
    };
    auto add = [&](int x, int a){
        if((x+a)%N == 0) return N;
        return (x+a)%N;
    };


    int doktor;
    for(int i = 1; i <= N; i++){
        int a = i, b = add(i, 1), c = add(i, 2);
        if(ask(a,b,c) != 0){
            int nt = add(c, 1);
            if(ask(a, b, nt) == 0) doktor = c;
            else if(ask(a, nt, c) == 0) doktor = b;
            else doktor = a;

            break;
        }
    }
    vector<int> perm(N+1);
    iota(perm.begin(), perm.end(), 0);

    sort(perm.begin()+1, perm.end(), [&](int i, int j){
         if(i == doktor) return true;
         if(j == doktor) return false;
         if(ask(doktor, i, j) > 0) return true;
         return false;
         });

    vector<int> ans(N+1);

    for(int i = 1; i <= N; i++){
        ans[perm[i]] = i;
    }
    //cerr << "PITAO " << cc << '\n';
    return ans;
}