public void sortAndCount(int[] array, int arrayLen) {
		if (arrayLen <= 1) {
			return;
		}

		int midIndex = (arrayLen - 1) / 2;

		/**
		 * left array: [0, (arrayLen-1)/2] right array: [arrayLen/2+1,
		 * arrayLen-1];
		 */
		int leftArrayLen = (arrayLen - 1) / 2 + 1;
		int rightArrayLen = arrayLen - leftArrayLen;
		
		int[] leftArray = new int[leftArrayLen];
		int[] rightArray = new int[rightArrayLen];
		
		for (int i = 0; i < leftArrayLen; i++) {
			leftArray[i] = array[i];
		}

		for (int i = 0; i < rightArrayLen; i++) {
			rightArray[i] = array[i + leftArrayLen];
		}

		this.sortAndCount(leftArray, leftArrayLen);
		this.sortAndCount(rightArray, rightArrayLen);

		int i = 0;
		int j = 0;
		int n = 0;
		while (i < leftArrayLen && j < rightArrayLen) {
			if (leftArray[i] <= rightArray[j]) {
				array[n] = leftArray[i];
				n++;
				i++;
			} else {
				array[n] = rightArray[j];
				n++;
				j++;
				this.count += midIndex - i + 1;
			}
		}

		// j reaches highIndex first
		for (; i < leftArrayLen; i++, n++) {
			array[n] = leftArray[i];
		}

		for (; j < rightArrayLen; j++, n++) {
			array[n] = rightArray[j];
		}

	}