import sys input = sys.stdin.readline N=int(input()) P=list(map(int,input().split())) P2=[(P[i],i+1) for i in range(N)] P2.sort(reverse=True) SUM=[0] for x,y in P2[::-1]: SUM.append(SUM[-1]+y) SUM.reverse() ANS=0 for i in range(1,N): ANS=max(ANS,SUM[i]-P2[i-1][1]) print(ANS)