#include #include using namespace std; const int N = 200005; int n, a[N]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; long long ans = 0; int p = n; while (1) { while (p > 1 && a[p] < a[p - 1]) p--; if (p == 1) { cout << ans << endl; return 0; } ans += n - p; p--, n--; } }