TopCoder SRM621_div2_3.py correction