////////////////////////////////////////
//ALDS1_5_D:   The Number of Inversions
//
//BIT: Binary Indexed Tree??§?????±?????????
//
//N???10????????¨???WA????????£???????????£??????????§£?±?
//http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2542172#2
////////////////////////////////////////

#include <iostream>
#include <algorithm> // next_permutation
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <list>
#include <numeric> //accumulate
//#include <unordered_map> //???????????\??¢??°
#include <fstream> //ifstream, ofstream

#define NDEBUG //NDEBUG???#include <cassert>???????????????????????????????????´???assert?????????????????????????????????NDEBUG????????????????????¨
#include <cassert> //assert


using namespace std;

//???????????°??????TEST????????????????????¬???????????????????????????????????¢????????????
#define TEST //*******************************************************************************************************************************************
//?????????????????¨??§?????\????????????????????????????????°?????????????¨???????????????????dout???????????????????????§???????????¬??????????????????????????????????????????
//??????????????????????????????????????????????????????????§?CPU???????£??????????????????§???TLE?????????????????????????????????????????§????????¨???                           ????????????????????????cerr????????£????????????????????????????????????
#ifdef TEST
#define dout cout
#else
stringstream dummy; //???????????°??????dout?????????????????????????????????
#define dout dummy.str(""); dummy.clear(stringstream::goodbit); dummy //dummy?????????????????????????????????????????¨?????¢?????¢???????????????
//???????????¨??????????????????goodbit?????????????????????????????¨???????????´????????????????????????????????¨?????°?????????????????§???????????????????????????????????? http://d.hatena.ne.jp/linden/20060427/p1
#endif

//?¨??????????????????????????????????????????????????????´??????OUTPUT2TEXTFILE????????????????????¬???????????????????????????????????¢????????????
//#define OUTPUT2TEXTFILE //*******************************************************************************************************************************************
#ifdef OUTPUT2TEXTFILE
#define dout outputfile //??¨????????????TLE????????§?????????dout?????¨??¨??????????????¢????????????????????????????????????????????§????¨????????????´??????????????£??????????????????????¨?????????????????????????????????????????????§?????????????????????
//TEST??????????????????????????¨???outputfile??????????????????????????????
#define OUTPUTFILENAME "output.txt"
ofstream outputfile(OUTPUTFILENAME);
#define OutputFilePath "/Users/Nag/Documents/Prgm/Test/DerivedData/Test/Build/Products/Debug/output.txt"
#endif

#define disp(A) dout << #A << " = " << (A) << endl
#define disP(A) dout << setw(3) << (A) << " " // << setw(3) ??????????????\????????????
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)

#define dispAll(A,n) dout << #A << " = "; rep(j, 0, (n)) {disP(A[j]);} dout << endl

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

const int INF = 1e9+999;

//const int maxLength = 200000;
//int a[maxLength+1];
//int b[maxLength+1];
//int BIT[maxLength+1];

int N; //Num of input data
vi BIT; //Binary Indexed Tree


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


int sum(int i) {
    int sum = 0;
    
    while( i > 0 ) {
        sum += BIT[i];
        i -= i&-i;
    }
    
    return sum;
}



int main(){
    
    cin >> N;
    
    vector<pii> a; //??°?????¨??????index????????¢???????????????
    int aa;
    rep(i,0,N) {
        cin >> aa;
        a.push_back( make_pair(aa,i) );
    }
    
    //sort once
    sort(a.begin(),a.end());
    
    //normalization within 1 - 200,000 (N_MAX)
    // 1 3 3 5 6 ??? 1 2 2 3 4 ???????????????
    // a??????????????????????????£????????§????????¢?????????index??????????????????????????§b[]???????????????
    //??????????????????????????¨??§???a_max <= 10^9 ?????£????????????b_max <= N ??????????????????BIT[N]??§????????§???????????????????????????????????????N=200,000????????§???
    
    vi b(N); //???????????£???????????????????????????????????????????????§????´???????
    //???????????\??????????????¨????????£?????????????????§????????¢??°???????????°???????????????????????????????????¨??¨??????
    
    int currentNumber = 1;
    int previousNumber = a[0].first;

    b[ a[0].second ] = currentNumber;

    rep(i,1,N) {
        if( a[i].first == previousNumber ) {
            ;
        } else {
            currentNumber++;
        }
        
        b[ a[i].second ] = currentNumber;
        previousNumber = a[i].first;
    }
    
//    dispAll(b, N);
    
    
    
    //initialize BIT
    rep(i,0,N+1) {
        BIT.push_back(0);
    }
    
//    dispAll(BIT, N+1);
    
    
    
    //count inversion
    ll numOfInversion = 0;
    for(int i=N-1; i>=0; i--) { //b[]???????????????????????????
        
        numOfInversion += sum(b[i]-1); //?????§???????????????????????????????°?????????°????´?????????° = b[]??§????????????????????????????????????????°?????????°????????° = ?????¢??°????????°
        add(b[i], 1); //1?????????????????¨??§?´?????????°???+1??????

//        disp(i);
//        disp(b[i]);
//        disp(sum(b[i]-1));
//        disp(numOfInversion);
//        dispAll(BIT, N+1);
//        dout <<"--------------------------------------------------------------------BIT\n";
        
    }
    
    cout << numOfInversion << endl;
    
    
#ifdef OUTPUT2TEXTFILE
    outputfile.close();
    cout << "\"" << OutputFilePath << "\"" << endl;
#endif
    
    return 0;
}

Measured memory_bytes: 7008