代码:
import java.util.Scanner;
public class grand {
static int t = 0;
public static void main(String[] args) {
int N=new Scanner(System.in).nextInt();
int[] a = new int[N];
int[] b = new int[N];
for (int i = 0; i < a.length; i++) {
a[i] = new Scanner(System.in).nextInt();
}
for (int i = 0; i < a.length; i++) {
int m = 0;
for (int j = 0; j < a.length-1; j++) {
if(b[j+1]!=0){
continue;
}
if(a[j+1]<a[j]){
m = j+1;
}
}
b[m]++;
if((m-1)>=0&&b[m-1]!=0&&a[m-1]!=a[m]){
b[m] = b[m-1]+1;
}
if((m+1)<N&&b[m+1]>=b[m]&&a[m+1]!=a[m]){
if(b[m+1]==b[m]){
b[m] = b[m+1]+1;
}else{
b[m] = b[m+1]+1;
}
}
}
for (int i = 0; i < b.length; i++) {
t += b[i];
}
System.out.println(t);
}
}
//7,2,3,1,6,5,4,1
//2,1,2,1,4,3,2,1