Correct solution to Problem A of the Programming Team 2014 Tryouts