the source file in topcoder SRM, coded by AcOnFingers