2003' ACM/ICPCѵϰ 17

D: The Book-shelver's Problem