TopCoder smr144/300 solution