#include #include #include #include #include #include #include #include #include #include using namespace std; struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<ostream &operator<<(ostream &o,const vector&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")< d; public: BIT(int64 _n=0) {n=_n; d=vector(n+1);} void add(int64 i, int64 x=1) { for (i++; i <= n; i += i&-i) d[i] += x; } int64 sum(int64 i) { int64 x = 0; for (i++; i; i -= i&-i) x += d[i]; return x; } }; int main() { int n; cin >> n; vector a(n,0); int a_max = 0; for (int i=0; i> a[i]; a_max = max(a_max, a[i]); } BIT bit1(a_max+1); vector l(n,0); for (int i=0; i=0; i--) { r[n-1-i] = (n-1-i) - bit2.sum(a[i]); bit2.add(a[i]); } int ans = 0; for (int i=1; i