N = input()
A = [input() for i in xrange(N)]
depth = [1] * N
for i in xrange(N - 1, 0, -1): #greedily setting the tablets for decreasing ratings
	if A[i - 1] > A[i]: 
		depth[i - 1] = depth[i] + 1 # "higher rating must get more tablets"
		
tablets = [1] * N
tablets[0] = max(tablets[0], depth[0])
for i in xrange(1, N):
	if A[i] > A[i - 1]:
		tablets[i] = max(tablets[i - 1] + 1, depth[i]) # at peak /\ we check the max of tablet of decreasing and increasing rating
	else:
		tablets[i] = depth[i]
		
print sum(tablets)