Problem 1197 solution