#include #include #include using namespace std; int main() { using boost::multiprecision::cpp_int; cin.tie(0); ios_base::sync_with_stdio(false); int n; cin >> n; vector p(n), bit(n); vector a(n), b(n); for (int i = 0; i < n; i++) cin >> p[i]; for (int i = n - 1; i >= 0; i--) { int x = 0; for (int j = p[i] - 1; j >= 1; j -= j & (-j)) x += bit[j]; for (int j = p[i]; j < n; j += j & (-j)) bit[j]++; a[n - i - 1] = x; b[i] = i + 1; } for (int i = 1; i < n; i <<= 1) { for (int j = 0; j + i < n; j += 2 * i) { a[j] = a[j] + b[j] * a[j + i]; b[j] = b[j] * b[j + i]; } } cout << a[0] + 1 << endl; return 0; }