def invNum(d,A):

    if d < 0 or len(A) < 2: return 0

    cnt = 0

    L = []

    R = []

    for ai in A:

        if ai < 2**d:

            L.append(ai)

            cnt += len(R)

        else:

            R.append(ai-2**d)

    return cnt + invNum(d-1,L) + invNum(d-1,R)

 

if __name__=='__main__':

    n = int(eval(input())) 

    print((invNum(29,list(map(int,input().split())))))
cnt = 0

def merge(L,R):

    global cnt

    n = len(L)+len(R)

    lenL = len(L)

    A = []

    i = j = 0

    L.append(-1)

    R.append(-1)

    for _ in range(n):

        if L[i] > R[j]:

            A.append(L[i])

            i += 1

        else:

            A.append(R[j])

            j += 1

            cnt += lenL-i

    return A



def mergeSort(A):

    if len(A)==1: return A

    m = len(A)//2

    return merge(mergeSort(A[:m]),mergeSort(A[m:])) 



if __name__=='__main__':

    n = int(eval(input())) 

    A = list(map(int,input().split()))

    mergeSort(A[::-1])

    print(cnt)
def invNum(d, A):
    if d < 0 or len(A) < 2:
        return 0
    cnt = 0
    L = []
    R = []
    for ai in A:
        if ai < 2**d:
            L.append(ai)
            cnt += len(R)
        else:
            R.append(ai - 2**d)
    return cnt + invNum(d - 1, L) + invNum(d - 1, R)


if __name__ == "__main__":
    n = int(eval(input()))
    print((invNum(29, list(map(int, input().split())))))

cnt = 0


def merge(L, R):
    global cnt
    n = len(L) + len(R)
    lenL = len(L)
    A = []
    i = j = 0
    L.append(-1)
    R.append(-1)
    for _ in range(n):
        if L[i] > R[j]:
            A.append(L[i])
            i += 1
        else:
            A.append(R[j])
            j += 1
            cnt += lenL - i
    return A


def mergeSort(A):
    if len(A) == 1:
        return A
    m = len(A) // 2
    return merge(mergeSort(A[:m]), mergeSort(A[m:]))


if __name__ == "__main__":
    n = int(eval(input()))
    A = list(map(int, input().split()))
    mergeSort(A[::-1])
    print(cnt)

-def invNum(d, A): -    if d < 0 or len(A) < 2: -        return 0 -    cnt = 0 -    L = [] -    R = [] -    for ai in A: -        if ai < 2**d: -            L.append(ai) -            cnt += len(R) +cnt = 0 + + +def merge(L, R): +    global cnt +    n = len(L) + len(R) +    lenL = len(L) +    A = [] +    i = j = 0 +    L.append(-1) +    R.append(-1) +    for _ in range(n): +        if L[i] > R[j]: +            A.append(L[i]) +            i += 1 -            R.append(ai - 2**d) -    return cnt + invNum(d - 1, L) + invNum(d - 1, R) +            A.append(R[j]) +            j += 1 +            cnt += lenL - i +    return A + + +def mergeSort(A): +    if len(A) == 1: +        return A +    m = len(A) // 2 +    return merge(mergeSort(A[:m]), mergeSort(A[m:])) -    print((invNum(29, list(map(int, input().split()))))) +    A = list(map(int, input().split())) +    mergeSort(A[::-1]) +    print(cnt)