TopCoder srm144/300 problem definition and solution inculded.