# https://yukicoder.me/problems/no/1525 def main(): N = int(input()) A = list(map(int, input().split())) a_list = [(i, a) for i, a in enumerate(A)] a_list.sort(key=lambda x : x[1]) left = N right = -1 answer = 0 for i, _ in a_list: left = min(left, i) right = max(right, i) ans = (left + 1) * (N - right) answer += ans print(answer) if __name__ == "__main__": main()