code optemization

Can any one help me with code optimization

well this is the hackerearth.com september circuits’s question.
cannot answer an online contest problem. please remove.
ask after the contest gets over.