code: private static int[] inverse(int[] perm) {
          int[] inv = new int[perm.length];
          for (int i = 0, len = perm.length; i < len; i++)
              inv[perm[i]] = i;
          return inv;
      }
docs: calculate the inverse of a permutation