Permutation Game Hackerrank Python