n=int(raw_input())
val=1
lis=[]
lol=[1]
lol1=[1]
for i in xrange(n):
	lis.append(int(raw_input()))
for i in range(1,n):
	if lis[i]>lis[i-1]:
		lol.append(lol[-1]+1)
	else:
		lol.append(1)
#print lol
for i in range(n-2,-1,-1):
	if lis[i]>lis[i+1]:
		lol1.append(lol1[-1]+1)
	else:
		lol1.append(1)
lol1=lol1[::-1]
#print lol1
for i in xrange(n):
	lol[i]=max(lol[i],lol1[i])
print sum(lol)