Eastern NEERC2014, Problem C, Accepted