// ConsoleApplication3.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include "triangles.h"

using namespace std;
using ll = long long;

// checks that d is in triangle a,b,c
bool check(int a, int b, int c, int d)
{
	Triangle t = { a,b,c };
	Triangle x = { d,a,b };
	Triangle y = { d,b,c };
	Triangle z = { d,a,c };
	if (compare({ t }, { x,y,z }) == 0)
		return true;
	return false;
}

// -1: a < b
// 0 a = b
// 1 : a > b
int cmp(Triangle a, Triangle b)
{
	return compare({ a }, { b });
}

int cmp(vector<Triangle> a, vector<Triangle> b)
{
	return compare(a, b);
}

vector <int> normal(Triangle t)
{
	return { t.i,t.j,t.k };
}

vector <vector <int>> normal(vector<Triangle> t)
{
	vector <vector<int>> res;
	for (auto& i : t)
	{
		res.push_back(normal(i));
	}
	return res;
}

vector <vector<int>> solve(int n)
{
	assert(n == 4);
	if (check(0, 1, 2, 3))
		return { {0,1,2} };
	if (check(0, 1, 3, 2))
		return { {0,1,3} };
	if (check(0, 2, 3, 1))
		return { {0,2,3} };
	if (check(1, 2, 3, 0))
		return { {1,2,3} };
	vector< vector<Triangle>> vars;
	vars.push_back({ Triangle{ 0,1,2 }, Triangle{ 3,1,2 } });
	vars.push_back({ Triangle{ 0,1,3 }, Triangle{ 3,1,2 } });
	vars.push_back({ Triangle{ 0,1,3 }, Triangle{ 0,1,2 } });
	sort(vars.begin(), vars.end(), [](auto x, auto y) {return cmp(x, y) > 0; });
	return normal(vars.back());
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
