AOJ 1156 Twirling Robot http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1156&lang=jp