#include <bits/stdc++.h>
using namespace std;
long long power(long long n, long long m) {
  long long p = 1;
  if (m == 0) return 1;
  p = (power(n, m / 2) % 1000000007);
  p = (p % 1000000007 * p % 1000000007) % 1000000007;
  return (m & 1 ? ((p % 1000000007 * n % 1000000007) % 1000000007)
                : (p % 1000000007));
}
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long sum = 0;
  long long b[n];
  memset(b, 0, sizeof(b));
  for (long long i = 0; i < n; i++) {
    if (i == 0) {
      b[i] = 0;
      continue;
    }
    if (a[i] < a[i - 1]) {
      b[i] += b[i - 1] + 1;
    } else if (a[i] == a[i - 1]) {
      b[i] = b[i - 1];
    } else
      b[i] = 0;
  }
  for (long long i = 0; i < n; i++) sum += b[i];
  cout << sum;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
  cerr << (float)clock() / CLOCKS_PER_SEC * 1000 << " ms"
       << "\n";
  return 0;
}
