Google Code Jam 2014, Qualification Round, problems A and B solved.