I implemented an iterative backtracking algorithm with AT&T syntax, on x86 Arhitecture. Given a permutation, I generated the smallest Permutation in the lexicographic sense where each element appears exactly three times. Given a m, the distance between two equal elements must be m.