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

using namespace std;

vector<pair<int, int>> ZapisiTacke(int N){
    vector<pair<int, int>> tacke(N+1);
    tacke[1]={-1, 0};
    tacke[2]={0, 0};
    tacke[3]={1, 0};
    for(int i = 4; i <= N; i++){
        tacke[i]={i, i*i};
    }

    return tacke;
}

vector<int> Resi(int N, int Q){
    vector<int> resenje(N+1);

    for(int i = 1; i <= N; i++) resenje[i]=i;
    vector<int> degree(N+1, 0);

    if(N<=50){
        int col[4];
        for(int i = 1; i <= N; i++){
            for(int j = i+1; j <= N; j++){
                for(int k = j+1; k <= N; k++){
                    if(Pitaj(i, j, k)==0){
                        col[1]=i;
                        col[2]=j;
                        col[3]=k;
                    }
                }
            }
        }
        degree[col[1]]=-1;
        degree[col[2]]=-1;
        degree[col[3]]=-1;

        for(int i = 1; i <= N; i++){
            if(i==col[1] || i==col[2] || i==col[3]) continue;
            for(int j = i+1; j <= N; j++){
                if(j==col[1] || j==col[2] || j==col[3]) continue;
                int res = Pitaj(col[1], i, j);
                if(res>0) degree[j]++;
                else if(res<0) degree[i]++;
            }
        }

        int nx = -1;
        for(int i = 1; i <= N; i++){
            if(degree[i]==0) nx = i;
            if(degree[i]!=-1) resenje[i]=degree[i]+4;
        }
        for(int i = 1; i <= 3; i++){
            int sum = 0;
            for(int j = 1; j <=3; j++){
                if(i==j) continue;
                int res = Pitaj(col[i], nx, col[j]);
                sum+=res;
            }
            if(sum==0) resenje[col[i]]=2;
            if(sum==2) resenje[col[i]]=3;
            if(sum==-2) resenje[col[i]]=1;
        }

    } else if(N<=200){
        for(int i = 2; i <= N; i++){
            for(int j = i+1; j <= N; j++){
                int res = Pitaj(1, i, j);
                if(res>0) degree[j]++;
                else degree[i]++;
            }
        }

        for(int i = 2; i <= N; i++){
            resenje[i]=degree[i]+2;
        }
    }

    return resenje;
}