link of problem is http://community.topcoder.com/stat?c=problem_statement&pm=1901&rd=4650 ?
In the bottom, they explain how to solve this problem.