#include <stdio.h>
#include <stdlib.h>

int main() {
  int N;
  while (scanf("%d", &N) != EOF) {
    int* scores = (int*) malloc(N * sizeof(int));
    for (int i = 0; i < N; i++) {
      scanf("%d", &scores[i]);
    }

    int* bonuses = (int*) malloc(N * sizeof(int));
    for (int i = 0; i < N; i++) {
      bonuses[i] = 1;  // 每个组至少发1w的奖金
    }

    // 从左到右遍历,确保比左边成绩高的组获得更高的奖金
    for (int i = 1; i < N; i++) {
      if (scores[i] > scores[i - 1]) {
        bonuses[i] = bonuses[i - 1] + 1;
      }
    }

    // 从右到左遍历,确保比右边成绩高的组获得更高的奖金
    for (int i = N - 2; i >= 0; i--) {
      if (scores[i] > scores[i + 1] && bonuses[i] <= bonuses[i + 1]) {
        bonuses[i] = bonuses[i + 1] + 1;
      }
    }

    int totalBonuses = 0;
    for (int i = 0; i < N; i++) {
      totalBonuses += bonuses[i];
    }

    printf("%d\n", totalBonuses);

    free(scores);
    free(bonuses);
  }

  return 0;
}