/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;


/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	
	static long swapCount = 0;
	public static void main(String[] args) {

		// int[] input = new int[100000];
		// readInputIntoArray(input);

	 	int[] input = {6,5,4,3,2,1};	 
 		
		mergeSort(input);
		System.out.println(swapCount);
//		print("", input); 
	}
	 

	private static void print(String pre, int[] a) {
		System.out.println(pre);
		for (int i = 0; i < a.length; i++) {
			System.out.print(" " + a[i] + " ");
		}
		System.out.println();
	}

	private static void mergeSort(int[] a) {	
//		print("recusion input : ", a);
		if (a.length == 0 || a.length == 1)
			return;

		int mid = a.length / 2;
		int[] left = new int[mid];
		for (int i = 0; i < mid; i++) {
			left[i] = a[i];
		}
//		print("Before merge recursion left:", left);

		int[] right = new int[a.length - mid];		 
		int temp = mid;
		for (int i = 0; temp < a.length;) {
			right[i++] = a[temp++];			
		}
//		print("Before merge recursion right:", right);

		mergeSort(left);
		mergeSort(right);

//		print("Before left:", left);
//		print("Before right:", right);
 		 
		int i = 0;
		int j = 0;
		int k = 0;
		while (i < left.length && j < right.length) {
			if (left[i] <= right[j]) {
				a[k++] = left[i++];
			} else {
				a[k++] = right[j++];
				swapCount += (mid-i);
			}
		}

		while (i < left.length) {
			a[k++] = left[i++];
		}

		while (j < right.length) {
			a[k++] = right[j++];
		}
 
//		print("After merge:", a);
	}

	private static void readInputIntoArray(int[] input) {
		BufferedReader br = null;

		int i = 0;
		try {
			String sCurrentLine = null;
			br = new BufferedReader(new FileReader("input.text"));
			while ((sCurrentLine = br.readLine()) != null) {
				input[i++] = Integer.parseInt(sCurrentLine);
			}
		} catch (IOException e) {
			System.out.println("exception => " + e);
		}
	}
}
