#include<iostream>
using namespace std;
template<typename TYPE>
void find(TYPE a[], size_t N) {
TYPE c1, c2, c3;
size_t n1 = 0, n2 = 0, n3 = 0;
for (int i = 0; i < N; i++) {
if (n1 == 0) {
c1 = a[i], n1 = 1;
} else if(c1 == a[i]) {
n1++;
} else if( n2 == 0) {
c2 = a[i], n2 = 1;
} else if(c2 == a[i]) {
n2++;
} else if (n3 == 0) {
c3 = a[i], n3 = 1;
} else if (c3 == a[i]) {
n3++;
} else {
--n1;
--n2;
--n3;
}
}
cout << c1 << " " << c2 << " " << c3 << endl;
}
int main() {
int a[16] = {1, 1, 3, 4, 3, 2, 1, 2, 2, 3, 5, 6, 3, 2, 1, 7};
find(a, 16);
return 0;
}