Solve AOJ1167