n = input()
data, dp = [input() for N in range(n)], [0]*n
dp[0] = 1
for i in range(1, n):
    dp[i] = dp[i-1] + 1 if data[i] > data[i-1] else 1
for i in range(n-2, -1, -1):
    dp[i] = max(dp[i], dp[i+1] + 1) if data[i] > data[i+1] else dp[i]
print sum(dp)