#include "triangles.h"

using namespace std;

int getmod(int x) {
    return (x % n + n) % n;
}

vector<vector<int>> solve(int n) {
    for (int i = 0; i < n; i++) {
        vector<Triangle> left = {Triangle(i, getmod(i - 2), getmod(i - 1)), Triangle(getmod(i), getmod(i + 1), getmod(i - 1)), Triangle(i, getmod(i + 1), getmod(i + 2))};
        vector<Triangle> right = {Triangle(getmod(i + 3), getmod(i + 1), getmod(i + 2))};
        int x = compare(left, right);
        if (x == 0) {
            vector<vector<int>> ans;
            for (auto [a, b, c] : left) {
                ans.push_back({a, b, c});
            }
            return ans;
        }
    }
    for (int i = 1; i <= 3; i++) {
        vector<Triangle> left = {Triangle(getmod(i - 3), getmod(i - 2), getmod(i - 1)), Triangle(3, 1, 2)};
        vector<Triangle> right;
        if (i != 3) {
            right.push_back(Triangle(0, i, 3));
        }
        if (i != 1) {
            right.push_back(Triangle(0, i, 1));
        }
        if (i != 2) {
            right.push_back(Triangle(0, i, 2));
        }
        int x = compare(left, right);
        if (x == 0) {
            vector<vector<int>> ans;
            for (auto [a, b, c] : left) {
                ans.push_back({a, b, c});
            }
            return ans;
        }
    }
}