public static Set<List<Integer>> permutationCycles(final List<Integer> inputPerm) {
        permutationCheck(inputPerm);
        final List<Integer> indicesToVisit = new ArrayList<>();
        for (int i = 0; i < inputPerm.size(); ++i)
            indicesToVisit.add(i);
        
        final Set<List<Integer>> result = new HashSet<>();
        List<Integer> currentPerm = new ArrayList<>();
        int i = 0;
        while (!indicesToVisit.isEmpty()) {
            if (!indicesToVisit.contains(i))    // Already visited this index
                i = indicesToVisit.get(0);      // Move to next index
            
            indicesToVisit.remove((Integer)i);  // Object i, not object on index i
            final int element = inputPerm.get(i);
            if (currentPerm.isEmpty())
                currentPerm.add(i + 1);
            if (currentPerm.contains(element)) {// End of cycle
                if (currentPerm.size() > 1)     // Do not include id's in result
                    result.add(currentPerm);
                currentPerm = new ArrayList<>();
                continue;
            }
            currentPerm.add(element);
            i = element - 1;
        }
        return result;
    }