#include <cstdio>
#include <iostream>
#include <algorithm>
#define SENTINEL 2e9
using namespace std;
 
long long  cnt;
void Merge(int* A, int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;
  int *L,*R;
  L = new int[n1+1]; R=new int[n2+1];
  for(int i=0;i<n1;i++){
      L[i] = A[left + i];
  }
  for(int i = 0; i< n2;i++){
      R[i] = A[mid + i];
  }
  L[n1] = SENTINEL;
  R[n2] = SENTINEL;
  int i = 0;
  int j = 0;
  for(int k = left; k < right; k++){
    if(L[i] <= R[j]){
        A[k] = L[i];
        i = i + 1;
    } else {
		cnt += n1-i;
        A[k] = R[j];
        j = j + 1;
    }
  }
}
 
void Merge_Sort(int* A, int left, int right){
  if(left+1 < right){
    int mid = (left + right)/2;
    Merge_Sort(A, left, mid);
    Merge_Sort(A, mid, right);
    Merge(A, left, mid, right);
  }
}
          
int main(){
    int *a;
    int n;
    cnt = 0;
    scanf("%d",&n);
    a = new int[n];
    for(int i=0;i<n;i++){
        scanf(" %d",&a[i]);
    }
    Merge_Sort(a, 0, n);
    cout << cnt << endl;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

template <typename T>
class FenwickTree
{
public:
  int N;
  vector<T> dat;

  FenwickTree(int n, T m = 0)
  {
    init(n, m);
  }

  void init(int n, int m)
  {
    N = n;
    dat.resize(n + 1);
    for (int i = 0; i < dat.size(); i++)
    {
      dat[i] = m;
    }
  }

  int64_t sum(int i)
  {
    T s = 0;
    while (i > 0)
    {
      s += dat[i];
      i -= i & -i;
    }
    return s;
  }

  void add(int i, T x)
  {
    while (i <= N)
    {
      dat[i] += x;
      i += i & -i;
    }
  }
};

int main()
{
  int n;
  cin >> n;
  vector<int64_t> A(n);
  for (int i = 0; i < n; i++)
  {
    cin >> A.at(i);
  }
  vector<int64_t> copy = A;
  map<int64_t, int64_t> mp;
  sort(copy.begin(), copy.end());
  copy.erase(unique(copy.begin(), copy.end()), copy.end());
  int m = copy.size();
  for (int i = 0; i < m; i++)
  {
    mp[copy[i]] = i + 1;
  }
  for (int i = 0; i < n; i++)
  {
    A[i] = mp[A[i]];
  }
  int64_t ans = 0;
  FenwickTree<int64_t> ft(m + 1);
  for (int i = 0; i < n; i++)
  {
    ans += i - ft.sum(A[i]);
    ft.add(A[i], 1);
  }
  cout << ans << endl;
}
