
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")

// #pragma clang __attribute__(optimize("O3,unroll-loops"))
// #pragma clang __attribute__(target("avx2,bmi,bmi2,popcnt,lzcnt"))

#include "triangles.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef __int128 lll;

const ll inf=1e18+1,mod=998244353;
const ld eps=1e-9,pi=acos(-1);
#define all(a) a.begin(), a.end()
#define mpp make_pair
#define F first
#define S second

mt19937_64 rng(234);

// You should implement
// Вам необходимо реализовать

ll in(Triangle t0,ll j) {
    ll i0=t0.i,i1=t0.j,i2=t0.k;
    if (i0==j||i1==j||i2==j)
        return -1;
    Triangle a(i0,i1,j);
    Triangle b(i0,i2,j);
    Triangle c(i2,i1,j);
    return (compare({t0},{a,b,c})==0);
}

std::vector<std::vector<int>> solve(int n) {
    vector<Triangle>trn(1,Triangle(0,1,2));
    for (ll i=3;i<n;i++) {
        bool out=1;
        for (auto it:trn)
            if (in(it,i)) {
                out=0;
                break;
            }
        if (out) {
            for (auto tr:trn)
                for (ll sd=0;sd<3;sd++) {
                    Triangle trr=tr;
                    if (sd==0)
                        trr.i=i;
                    if (sd==1)
                        trr.j=i;
                    if (sd==2)
                        trr.k=i;
                    bool ok=1;
                    for (auto ch:trn) {
                        if (in(trr,ch.i)==1) {
                            ok=0;
                            break;
                        }
                        if (in(trr,ch.j)==1) {
                            ok=0;
                            break;
                        }
                        if (in(trr,ch.k)==1) {
                            ok=0;
                            break;
                        }
                    }
                    if (ok==1) {
                        trn.push_back(trr);
                        goto end;
                    }
                }
        }
        end:
    }
    vector<vector<int>>ans;
    for (auto i:trn)
        ans.push_back({i.i,i.j,i.k});
    return ans;
}