N=int(raw_input())
scores=[int(raw_input()) for x in xrange(N)]

tablet=[0]*N

tablet[0]=1

for i in xrange(1,N):
    if scores[i]>scores[i-1]:
        tablet[i]=tablet[i-1]+1

    else:
        tablet[i]=1



for i in xrange(N-2,-1,-1):

    if scores[i]>scores[i+1] and tablet[i]<=tablet[i+1]:
        tablet[i]=tablet[i+1]+1



print sum(tablet)