n = int(input()) a = list(map(int, input().split())) a = sorted([(val, idx) for idx, val in enumerate(a)]) ans = 0 win = 0 for i in range(n - 1): win += a[i][1] + 1 lose = a[i + 1][1] + 1 ans = max(win - lose, ans) print(ans)