置换解法

solution by substitution