Library

책 N권의 좌우 순서를 뒤집힘을 구분하지 않고 알아내야 하는 인터랙티브 문제로, 주어진 부분집합을 통째로 집어내는 데 필요한 최소 연속 구간 수를 묻는 질의를 20000번까지 보낼 수 있다.

어려움8완전 탐색구현그리디아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

After several hundred years had passed, JOI city became a ruined city. IOI-chan, an explorer, is now exploring the area where the library was built. According to the results of exploration, the following are known:

  • There were N books in the bookshelf of the library in JOI city. The N books were placed in the bookshelf in a line from left to right.
  • The N books were numbered from 1 to N. But, the order of books in the bookshelf might be different from the order of the numbers of the books.
  • By a single operation, it was possible to take contiguously placed books from the bookshelf at once.

Unfortunately, IOI-chan could not find old books in the library. But she found a machine which managed operations of the bookshelf of the library. If we specify one or more than one books by their numbers and send a query to the machine, it answers the minimum number of operations required to take only these books from the bookshelf.

IOI-chan wants to know the order of the books in the bookshelf by sending queries to the machine. However, because the answers from the machine would be the same if the order of the N books are reversed, she does not need to specify whether the books were placed from left to right or from right to left.

Because the machine is old, she can send at most 20 000 queries to the machine.

Write a program which specifies the order of the books in the bookshelf by sending at most 20 000 queries to the machine. It is not necessary to specify whether the books were placed from left to right or from right to left.

제한

  • 1 ≤ N ≤ 1 000.
  • 1 ≤ Ai ≤ N (1 ≤ i ≤ N).
  • Ai ≠ Aj (1 ≤ i < j ≤ N).