solution for codejam tourist's solution).