N=int(input()) P=list(map(lambda x:x-1,map(int, input().split()))) Q=[0]*N for i,p in enumerate(P): Q[p]=i res=0 S=N*(N+1)//2 for n in range(N)[::-1]: res=max(S - 2*(Q[n]+1),res) S-=Q[n]+1 print(res)