reduce the recursion of one level for problem 31