#include "triangles.h"

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

bool cmp(Triangle a, Triangle b) {
    int tmp = compare({a}, {b});
    if (tmp == 1 || tmp == 0)
        return 0;
    return 1;
}
std::vector<std::vector<int>> solve(int n) {
    assert(n == 4);
    bool vipukl = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            for (int k = j + 1; k < n; ++k) {
                int x = 0;
                if (i != 1 && j != 1 && k != 1)
                    x = 1;
                if (i != 0 && j != 0 && k != 0)
                    x = 0;
                if (i != 2 && j != 2 && k != 2)
                    x = 2;
                if (i != 3 && j != 3 && k != 3)
                    x = 3;

                bool f = 1;
                int f1 = compare({Triangle(i, j, k)}, {Triangle(i, j, x), Triangle(i, k, x)});

                if (f1 == 1) {
                    vipukl = 0;
                    if (compare({Triangle(i, j, k)}, {Triangle(j, k, x)}) == 1)
                        return {{i, j, k}, {i, k, x}, {x, j, i}};
                    else
                        return {{i, j, x}, {i, k, x}, {x, j, k}};
                }
            }
        }
    }
    if (!vipukl) {
        vector<Triangle> ans;

        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                for (int k = j + 1; k < n; ++k) {
                    ans.push_back(Triangle(i, j, k));
                }
            }
        }

        sort(ans.begin(), ans.end(), cmp);
        return {
            {ans[0].i, ans[0].j, ans[0].k}};
    } else {
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                for (int k = j + 1; k < n; ++k) {
                    Triangle a(i, j, k);
                    int x = 0;
                    if (i != 1 && j != 1 && k != 1)
                        x = 1;
                    if (i != 0 && j != 0 && k != 0)
                        x = 0;
                    if (i != 2 && j != 2 && k != 2)
                        x = 2;
                    if (i != 3 && j != 3 && k != 3)
                        x = 3;
                    Triangle b1(i, j, x);
                    Triangle c1(i, k, x);
                    Triangle c2(j, k, x);
                    int tmp = compare({a, b1}, {c1, c2});
                    if (tmp == 0) {
                        return {{i, k, j, x}};
                    }
                }
            }
        }
    }
}
