#include <bits/stdc++.h>
using namespace std;
vector<int> solution(int n, int max, const vector<int>& array) {
map<int , int> p;
for(auto t : array)
if(t == 1) p[14] ++;
else p[t] ++;
vector<int> a , b;
for(auto [k , v] : p)
if(v >= 3) a.push_back(k) , b.push_back(k);
else if(v >= 2) b.push_back(k);
sort(a.begin() , a.end() , greater<int>());
sort(b.begin() , b.end() , greater<int>());
for(auto ta : a)
for(auto tb : b)
if(ta != tb)
{
if(ta == 14) ta = 1;
if(tb == 14) tb = 1;
int sum = ta * 3 + tb * 2;
if(sum <= max)
return {ta , tb};
}
return {0, 0};
}
int main() {
vector<int> result1 = solution(9, 34, {6, 6, 6, 8, 8, 8, 5, 5, 1});
cout << (result1 == vector<int>{8, 5}) << endl;
vector<int> result2 = solution(9, 37, {9, 9, 9, 9, 6, 6, 6, 6, 13});
cout << (result2 == vector<int>{6, 9}) << endl;
vector<int> result3 = solution(9, 40, {1, 11, 13, 12, 7, 8, 11, 5, 6});
cout << (result3 == vector<int>{0, 0}) << endl;
return 0;
}