// LLP-CountInversions: count inversions to the left of each index. class LLPCountInversions { void LLPCountInversions(int[] A) { int[] G = 0; forbidden (j) : G[j] < countLeft(A, j) => advance : G[j] = countLeft(A, j); } int countLeft(int[] A, int j) { int count = 0; int i = 0; while (i < j) { if (A[i] > A[j]) { count = count + 1; }; i = i + 1; }; return count; } }