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

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''

pills = [1]*input()
health= [input() for _ in range(len(pills))]

correct = False
while correct != True:
	correct = True
	for j in range(len(pills)-1):
		if (health[j] > health[j+1]) and (pills[j] <= pills[j+1]):
			correct = False
			pills[j] += 1
		elif (health[j] < health[j+1]) and (pills[j] >= pills[j+1]):
			correct = False
			pills[j+1] += 1

print sum(pills)