My solution to an ACM competition problem.