Solved AOJ 0583