import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) sys.setrecursionlimit(10**7) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### n = ni() p = na() a = [-1]*n for i in range(n): a[p[i]-1] = i+1 ans = 0 s = n*(n+1)//2 for i in range(n): ans = max(ans, s-2*a[-1-i]) #print(s-2*a[-1-i]) s-=a[-1-i] print(ans)