import math
import os
import random
import re
import sys

# Complete the candies function below.
def candies(n, arr):
    minArr1 = [1 for i in range(n)]
    minArr2 = [1 for i in range(n)]
    finalArr = []

    for i in range(1,len(arr)):
        if arr[i] > arr[i-1]:
            minArr1[i]=minArr1[i-1]+1
        else:
            minArr1[i] = 1

    for j in range(len(arr)-2,-1,-1):
        if arr[j] > arr[j+1]:
            minArr2[j] = minArr2[j+1] +1
        else:
            minArr2[j] = 1

    for i in range(len(arr)):
        finalArr.append(max(minArr1[i], minArr2[i]))

    return sum(finalArr)

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    n = int(input())

    arr = []

    for _ in range(n):
        arr_item = int(input())
        arr.append(arr_item)

    result = candies(n, arr)

    fptr.write(str(result) + '\n')

    fptr.close()
