import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static Scanner sc = new Scanner(System.in);
public static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws Exception {
int n = sc.nextInt();
int[] arr = new int[n];
for(int i=0;i<n;i++){
arr[i] = sc.nextInt();
}
int[] help = new int[n];
Arrays.fill(help,1);
// -> 右边大,则必须比左边多1个
for(int i=1;i<n;i++){
if(arr[i] > arr[i-1] && help[i] <= help[i-1]){
help[i] = help[i-1] + 1;
}
}
// <- 左边大,则必须比右边多1个
for(int i=n-2;i>=0;i--){
// 可能出现既大于左边,又大于右边的情况,则取加大值的那个
if(arr[i] > arr[i+1] && help[i] <= help[i+1]){
help[i] = Math.max(help[i+1] + 1, help[i]);
}
}
int sum = 0;
for(int i=0;i<n;i++){
sum += help[i];
}
System.out.println(sum);
}
}
/*
6
1 4 5 9 3 2
1 2 3 4 2 1
*/