Problem #3 ACM competition.