TopCoder coin Reversing problem