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

using namespace std;

vector<vector<int>> memo;

vector<pair<int, int>> ZapisiTacke(int n){
    vector<pair<int, int>> v(n+1);
    v[1] = {0, 0};

    for(int i = 2; i <= n; i++){
        v[i] = {i-2, 1};
    }
    return v;
}

void Resi(int n, vector<int>& ans, vector<int>& v, int r, int kec, int& br){
    if(br == n) return;

    vector<int> levo, desno;
    int d = 0;
    sort(v.begin(), v.end());
    int poz = v[v.size()/2];
    for(int j = 0; j < v.size(); j++){
        if(poz == v[j]) continue;

        if(memo[poz][v[j]] == 67){
            memo[poz][v[j]] = Pitaj(kec, poz, v[j]);
            memo[v[j]][poz] = -memo[poz][v[j]];
        }
        if(memo[poz][v[j]] == -1) d++;

        if(memo[poz][v[j]] == 1) levo.push_back(v[j]);
        else desno.push_back(v[j]);
    }
    ans[poz] = r-d;
    br++;

    /*cout << r-d << " : ";
    for(auto b : levo) cout << b << ' ';
    cout << "\n    ";
    for(auto b : desno) cout << b << ' ';
    cout << "\n\n";*/

    if(levo.size() != 0) Resi(n, ans, levo, r-d-1, kec, br);
    if(desno.size() != 0) Resi(n, ans, desno, r, kec, br);
}

vector<int> Resi(int n, int q){
    int kec = 1;
    if(Pitaj(1, 2, 3) == 0){
        for(int i = 4; i <= n; i++){
            if(Pitaj(i-2, i-1, i) != 0){
                kec = i; break;
            }
        }
    }
    else if(Pitaj(2, 3, 4) == 0){
        kec = 1;
    }
    else if(Pitaj(3, 4, 5) == 0){
        kec = 2;
    }
    else{
        kec = 3;
    }


    vector<int> ans(n+1);
    ans[0] = 0;
    ans[kec] = 1;
    int br = 1;

    memo.resize(n+1);
    for(int i = 0; i <= n; i++){
        memo[i].resize(n+1);
    }
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            memo[i][j] = 67;
        }
    }

    vector<int> v(n-1); int p = 0;
    for(int i = 1; i <= n; i++){
        if(i != kec) v[p++] = i;
    }
    Resi(n, ans, v, n, kec, br);

    //cout << kec << '\n';

    return ans;
}