import sys from operator import itemgetter from collections import defaultdict, deque import heapq import bisect stdin=sys.stdin sys.setrecursionlimit(10 ** 8) ip=lambda: int(sp()) fp=lambda: float(sp()) lp=lambda:list(map(int,stdin.readline().split())) sp=lambda:stdin.readline().rstrip() Yp=lambda:print('Yes') Np=lambda:print('No') inf = 1 << 60 eps = 1e-9 sortkey = itemgetter(0) ############################################################### N = ip() A = lp() ans = 0 score = [0 for _ in range(N + 1)] for i in range(N): p = A[i] score[p] = i + 1 S = sum(score) for i in range(N, 0, -1): x = score[i] y = S - score[i] ans = max(ans, y - x) S -= score[i] print(ans)