#include <iostream>
#include <vector>
#include "triangles.h"
#define go compare_result = compare(left, right)
#define l left =
#define r right =
#define zero if (compare_result == 0)
#define one if (compare_result == 1)
#define neg if (compare_result == -1)
#define comp(x, y) l x; r y; go
using namespace std;
std::vector<std::vector<int>> solve(int n) {
    // Example of compare:
    // Пример использования функции compare:
    /*std::vector<Triangle> left = {Triangle(1, 2, 3)};
    std::vector<Triangle> right = {Triangle(0, 1, 2), Triangle(0, 2, 3), Triangle(0, 1, 3)};
    int compare_result = compare(left, right);
    if (compare_result == 0) {
        std::vector<std::vector<int>> ans;
        ans.push_back(std::vector<int>{0, 1, 2});
        ans.push_back(std::vector<int>{0, 2, 3});
        ans.push_back(std::vector<int>{0, 1, 3});
        return ans;
    }
    left = {Triangle(0, 2, 3)};
    right = {Triangle(1, 2, 3), Triangle(0, 1, 3), Triangle(0, 1, 2)};
    compare_result = compare(left, right);
    if (compare_result == 0) {
        std::vector<std::vector<int>> ans;
        ans.push_back(std::vector<int>{1, 2, 3});
        ans.push_back(std::vector<int>{0, 1, 3});
        ans.push_back(std::vector<int>{0, 1, 2});
        return ans;
    }
    left = {Triangle(0, 1, 3)};
    right = {Triangle(1, 2, 3), Triangle(0, 2, 3), Triangle(0, 1, 2)};
    compare_result = compare(left, right);
    if (compare_result == 0) {
        std::vector<std::vector<int>> ans;
        ans.push_back(std::vector<int>{1, 2, 3});
        ans.push_back(std::vector<int>{0, 2, 3});
        ans.push_back(std::vector<int>{0, 1, 2});
        return ans;
    }
    left = {Triangle(0, 1, 2)};
    right = {Triangle(0, 1, 3), Triangle(0, 2, 3), Triangle(1, 2, 3)};
    compare_result = compare(left, right);
    if (compare_result == 0) {
        std::vector<std::vector<int>> ans;
        ans.push_back(std::vector<int>{1, 2, 3});
        ans.push_back(std::vector<int>{0, 1, 3});
        ans.push_back(std::vector<int>{0, 2, 3});
        return ans;
    }

    ///--------------------------------------------------------------------------------;
    left = {Triangle(0, 1, 2), Triangle(0, 1, 3)};
    right = {Triangle(0, 2, 3), Triangle(1, 2, 3)};
    compare_result = compare(left, right);
    if (compare_result == 0) {
        std::vector<std::vector<int>> ans;
        ans.push_back(std::vector<int>{0, 1, 2});
        ans.push_back(std::vector<int>{0, 1, 3});
        return ans;
    }
    left = {Triangle(0, 2, 1), Triangle(0, 2, 3)};
    right = {Triangle(0, 1, 3), Triangle(1, 2, 3)};
    compare_result = compare(left, right);
    if (compare_result == 0) {
        std::vector<std::vector<int>> ans;
        ans.push_back(std::vector<int>{0, 2, 1});
        ans.push_back(std::vector<int>{0, 2, 3});
        return ans;
    }
    left = {Triangle(0, 3, 1), Triangle(0, 3, 2)};
    right = {Triangle(0, 1, 2), Triangle(3, 1, 2)};
    compare_result = compare(left, right);
    if (compare_result == 0) {
        std::vector<std::vector<int>> ans;
        ans.push_back(std::vector<int>{0, 1, 2});
        ans.push_back(std::vector<int>{3, 1, 2});
        return ans;
    }
    while (true) {
        int a = 20;
        a--;
    }
    //std::vector<std::vector<int>> ans;
    /*ans.push_back(std::vector<int>(n));
    for (int i = 0; i < n; ++i) {
        ans[0][i] = i;
    }*/
    //ans.push_back(std::vector<int>{0, 3, 3});
    //return ans;
    //return ans;*/
    vector<Triangle>left, right;
    int compare_result;

    vector<int>a = {0, 1, 2};
    for (int i = 3; i < n; ++i) {
        vector<Triangle>Triangle ABC(a[0], a[1], a[2]);
        Triangle ABD(a[0], a[1], i);
        Triangle ACD(a[0], i, a[2]);
        Triangle BCD(i, a[1], a[2]);
        l {ABC};
        r {ABD, ACD, BCD};
        go;
        zero {
            continue;
        }

        comp({ABD}, {BCD});
        one {
            comp({ABD}, {ACD});
            one {
                comp({ABD}, {ABC});
                one {
                    a = {a[0], a[1], i};
                }
            }
            else neg {
                comp({ACD}, {ABC});
                one {
                    a = {a[0], a[2], i};
                }
            }
        }
        else neg {
            comp({BCD}, {ACD});
            one {
                comp({BCD}, {ABC});
                one {
                    a = {a[0], a[1], i};
                }
            }
            else neg {
                comp({ACD}, {ABC});
                one {
                    a = {a[0], a[2], i};
                }
            }
        }
    }
    return {{a[0], a[1], a[2]}};
}
