Solved AOJ 1166