Solved problem 1 round 3 GCJ 2013