answered problem35, but it's too slow