solved problem 393 but it's too slow
solved problem 414