#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(size1) ret = comp(hoge(v[pos*2+1],a), hoge(v[pos*2+2],a)); return ret; } val x; x = get(l,r, a, lb,(lb+ub)/2, pos*2+1); val y; y = get(l,r, a, (lb+ub)/2, ub, pos*2+2); val ret = comp(x,y); return ret; } val get(int l, int r, int a){ return get(l,r, a, 0,size,0); } }; template 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