december long 2016

I was solving some past contest problems. I cant get the editorial for this particular problem! Can someone help me with this problem

Problem