'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
'''

n = int(raw_input())
score = [-1]*n
for i in range(n):
	score[i] = int(raw_input())
tabs = [1]*n

def mini(pos):	
	if score[pos]>score[pos+1]:
		tabs[pos] = max(tabs[pos+1]+1,tabs[pos])
		mini(pos-1)
	elif score[pos]<score[pos+1]:
		tabs[pos+1] = max(tabs[pos]+1,tabs[pos+1])
		
for i in range(n-1):
	mini(i)
	
#print tabs
print sum(tabs)