solving problem 417