link of problem is TopCoder Statistics - Problem Statement ?
In the bottom, they explain how to solve this problem.