#include "triangles.h"

bool cmp(int p1, int p2, int p3, int p4, int p5, int p6)
{
    std::vector<Triangle> left = {Triangle(p1, p2, p3)};
    std::vector<Triangle> right = {Triangle(p4, p5, p6)};
    int compare_result = compare(left, right);
    return compare_result > 0;
}

std::vector<std::vector<int>> solve(int n)
{
    int b1 = 0, b2 = 1, b3 = 2;
    for (int i = 0; i < n; i++)
        for (int j = i+1; j < n; j++)
            for (int k = j+1; k < n; k++)
            {
                if (cmp(i, j, k, b1, b2, b3))
                {
                    b1 = i;
                    b2 = j;
                    b3 = k;
                }
            }
    int ot = 0;
    while (ot == b1 || ot == b2 || ot == b3)
        ot++;
    std::vector<Triangle> big = {Triangle(b1, b2, b3)};
    std::vector<Triangle> small = {Triangle(b1, b2, ot), Triangle(b1, b3, ot), Triangle(b2, b3, ot)};

    bool in = compare(big, small) == 0;

    std::vector<std::vector<int>> ans;
    if (in)
    {
        ans.push_back({b1, b2, b3});
    }
    else
    {
        std::vector<Triangle> one = {Triangle(0, 1, 2), Triangle(0, 1, 3)};
        std::vector<Triangle> two = {Triangle(0, 2, 1), Triangle(0, 2, 3)};
        std::vector<Triangle> three = {Triangle(0, 3, 1), Triangle(0, 3, 2)};
        if (compare(one, two) < 0)
        {
            if (compare(three, one) > 0)
            {
                ans.push_back({0, 3, 1});
                ans.push_back({0, 3, 2});
            }
            else
            {
                ans.push_back({0, 1, 2});
                ans.push_back({0, 1, 3});
            }
        }
        else
        {
            if (compare(three, one) < 0)
            {
                ans.push_back({0, 3, 1});
                ans.push_back({0, 3, 2});
            }
            else
            {
                ans.push_back({0, 2, 1});
                ans.push_back({0, 2, 3});
            }
        }
        // ans.push_back({2, 0, 3});
        // ans.push_back({1, 2, 3});
    }
    // ans.push_back(std::vector<int>(n));
    // for (int i = 0; i < n; ++i) {
    //     ans[0][i] = i;
    // }
    return ans;
}
