Solve SRM 629 DIV 2 1000

Change-Id: I353cb3af0539ade05d968bab58c6e3ad40d8638d