#include #include using namespace std; int B[200200]; int N,P[200200]; vector G[200200]; long long ans; void in(int x, int p) { while (x <= N){ B[x] += p; x += x & (-x); } } int out(int x) { int r = 0; while (x){ r += B[x]; x -= x & (-x); } return r; } void go(int x){ ans += out(x); in(x,1); for (auto y : G[x]) go(y); in(x,-1); } int main() { scanf ("%d",&N); for (int i=1;i