Topcoder practice solution.