N=int(input()) P=list(map(int,input().split())) Q=[0]*N for i in range(N): Q[P[i]-1]=i def Binit(B,siz): while len(B)siz+1: del B[-1] for i in range(siz+1): B[i]=0 B.append(siz) def Badd(B,a,x): z=a while z<=B[-1]: B[z]+=x z+=(z&(-z)) def Bsum(B,a): r=0 z=a while z>0: r+=B[z] z-=(z&(-z)) return r BIT=[] Binit(BIT,N+3) ANS=0 for i in range(N): ANS+=i-Bsum(BIT,Q[i]+1) Badd(BIT,Q[i]+1,1) print(ANS)