HDOJ 4624 2013 Multi-University Training Contest 3 Problem D Endless Spin