#include #include #include #include #include #include #include #include #include #include using namespace std; struct node{ int cnt; int l; int m; node():cnt(0),l(0),m(0){} bool operator < (const node& x) const{ return cnt < x.cnt; } bool operator == (const node& x) const{ return (cnt == x.cnt) && (l == x.l) && (m == x.m); } }; struct val{ node a[3]; val(){ a[0] = a[1] = a[2] = node(); } val operator +(const val& x){ val ret; vector tmp(6); for(int i=0; i<3; i++){ tmp[2*i] = a[i]; tmp[2*i+1] = x.a[i]; } sort(tmp.rbegin(), tmp.rend()); tmp.erase( unique(tmp.begin(), tmp.end()), tmp.end()); vector used(tmp.size(),false); ret.a[0] = tmp[0]; used[0] = true; for(int i=1; i tmp(6); for(int i=0; i<3; i++){ tmp[2*i] = x.a[i]; tmp[2*i+1] = y.a[i]; } sort(tmp.rbegin(), tmp.rend()); tmp.erase( unique(tmp.begin(), tmp.end()), tmp.end()); for(int i=0; i<3 && i v; int size; seg(int n){ size = 1; while(size vector compress(vector a, int& size){ auto b = a; sort(b.begin(), b.end()); b.erase( unique(b.begin(), b.end()), b.end()); for(int i=0; i int main(){ int n; cin >> n; vector a(n); for(int i=0; i