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

std::vector<std::vector<int>> solve(int n) {
    std::vector<std::vector<int>> t;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            for (int k = j + 1; k < n; ++k) {
                t.push_back({i, j, k});
            }
        }
    }
    std::sort(t.begin(), t.end(), [&](const std::vector<int>& a, const std::vector<int>& b) {
        int pon = compare({Triangle(a[0], a[1], a[2])}, {Triangle(b[0], b[1], b[2])});
        return pon == -1;
    });
    // for (auto &x : t) {
    //     for (auto &y : x) std::cout << y << ' ';
    //     std::cout << endl;
    // } 
    std::vector<std::vector<int>> ans;
    if (!compare({Triangle(t[0][0], t[0][1], t[0][2]), Triangle({t[1][0], t[1][1], t[1][2]}), Triangle({t[2][0], t[2][1], t[2][2]})}, {Triangle({t[3][0], t[3][1], t[3][2]})})) {
        for (int i = 0; i < 3; ++i) {
            ans.push_back(t[i]);
        }
    } else {
        ans.push_back(t[0]);
        for (int i = 1; i < n; ++i) {
            int cnt = 0;
            for (int j = 0; j < 3; ++j) {
                if (ans[0][j] == t[i][j]) {
                    cnt++;
                }
            }
            if (cnt >= 2) {
                ans.push_back(t[i]);
                break;
            }
        }
    }
    return ans;
} 