solving hardest problem
306