Interval Partition Generator

No attempts yetTime limit1sMemory limit128 MB

Problem

Let S={1,2,,n}S = \{1, 2, \ldots, n\}. For integers aba \le b, the interval [a,b][a, b] is the set of consecutive integers {a,a+1,,b}\{a, a+1, \ldots, b\}. A partition of SS into intervals is a sequence of pairwise disjoint intervals whose union is exactly SS.

We simulate a generator that builds such a partition step by step. At every moment we keep the set TT of elements of SS that have not yet been placed into any interval; initially T=ST = S. In each iteration we choose one interval that is fully contained in TT, report it, and remove it from TT. We repeat until TT is empty.

The interval chosen in an iteration is identified by an index. Consider all intervals [a,b][a, b] contained in TT (that is, every integer from aa to bb belongs to TT). Number them from 00 in lexicographic order by the pair (start, end). For instance, when T={1,4,5}T = \{1, 4, 5\} the intervals in order are [1,1][1,1], [4,4][4,4], [4,5][4,5], [5,5][5,5], receiving indices 00, 11, 22, 33. The index of the chosen interval is given to your program through the input.

Input

The first line contains one integer nn (1n10000001 \le n \le 1000000).

The remaining input lists the chosen indices, one per iteration, in order. Starting from T={1,2,,n}T = \{1, 2, \ldots, n\}, repeat the following while TT is not empty:

  • Let LL be the number of intervals contained in the current TT.
  • Read one integer ll (0l<L0 \le l < L), the index of the chosen interval.
  • Remove the interval with index ll from TT.

The given indices are exactly enough to empty TT: it becomes empty right after the last index is used.

Output

For each iteration, in order, print two lines:

  • a line with LL, the number of intervals contained in TT at the start of that iteration;
  • a line with two integers aa and bb separated by a single space, the endpoints of the chosen interval [a,b][a, b].