Lovely choice of datastructure for this problem.