MAX_RATING = 100000

INFINITY = MAX_RATING + 1


def GetRating(i, ratings):
  if i < 0 or i > len(ratings) - 1:
    return INFINITY
  return ratings[i] 

numPatients = int(raw_input())
ratings = [0] * numPatients
for i in range(numPatients):
    ratings[i] = int(raw_input())
valleys = []
for i in range(numPatients):
    if GetRating(i, ratings) <= GetRating(i - 1, ratings) \
      and GetRating(i, ratings) <= GetRating(i + 1, ratings):
      valleys.append(i)
tabs = [0] * numPatients
for valley_i in valleys:
    tabs[valley_i] = 1
    mountain_i = valley_i - 1
    while mountain_i >= 0 and ratings[mountain_i] > ratings[mountain_i+1]:
        tabs[mountain_i] = max(tabs[mountain_i], tabs[mountain_i+1] + 1)
    
        mountain_i -= 1

    mountain_i = valley_i + 1
    while mountain_i <= numPatients - 1 \
      and ratings[mountain_i] > ratings[mountain_i-1]:
      tabs[mountain_i] = tabs[mountain_i-1] + 1
      mountain_i += 1
  
print sum(tabs)