Problem #3 ACM programming competition