Solution for Google Code-In 2014 task