TRICKY PERMUTATIONS TLE and run error

question = https://hack.codingblocks.com/contests/c/452/737
solution = https://ide.codingblocks.com/#/s/21382