TopCoder's SRM 233 DIV 1 500 points problem.