#include using namespace std; int main () { int N; cin >> N; vector A(N); A[0] = 0; int now; cin >> now; for (int i = 1; i < N; i ++) { int nxt; cin >> nxt; A[i] = A[i - 1] + (now > nxt ? -1 : 1); } long long ans = 0; for (int i = 0; i < N - 1; i ++) { ans += max(A[i], A[i + 1]) - max(i, A[N - 1] - (N - i - 1)); } cout << ans / 2 << endl; }