#include "triangles.h"
#include <set>
#include <algorithm>

using namespace std;
using ll = long long;

bool operator==(const Triangle a, const Triangle b) {
    vector<int> va = {a.i, a.j, a.k};
    vector<int> vb = {b.i, b.j, b.k};
    sort(va.begin(), va.end());
    sort(vb.begin(), vb.end());
    return va == vb;
}

vector<int> vec(Triangle a) {
    return {a.i, a.j, a.k};
}

bool operator<(const Triangle a, const Triangle b) {
    return compare({a}, {b}) == -1;
}

vector<vector<int>> solve(int n) {
    vector<Triangle> triangles;
    for (int i = 0; i < n; ++i) {
        Triangle cur(i, (i + 1) % n, (i + 2) % n);
        triangles.push_back(cur);
    }
    sort(triangles.begin(), triangles.end());
    if (compare({triangles[0], triangles[1], triangles[2]}, {triangles[3]}) == 0) {
        return {{triangles[3].i, triangles[3].j, triangles[3].k}};
    }
    if (compare({triangles[0], triangles[1]}, {triangles[2], triangles[3]}) == 0) {
        return {{vec(triangles[0])},{vec(triangles[1])}};
    }
    while (next_permutation(triangles.begin(), triangles.end())) {
        if (compare({triangles[0], triangles[1]}, {triangles[2], triangles[3]}) == 0) {
            return {{vec(triangles[0])},{vec(triangles[1])}};
        }   
    }
}
