TopCoder SRM 658 Div1 Hard DancingForever

実装はラクという意味で850ptだけど、理解は難しい。 http://community.topcoder.com/stat?c=problem_statement&pm=13760