cswork / OAOpen practice workspace

UberOA #63

Tournament Rounds by Rank

Estimated EasyJudge-ready

Topics (AI-labelled)Simulation

Adjacent pairs of players compete, and the one with the smaller rank number advances. When a round has an odd number of players, the last one advances automatically. Output the list after each round, keeping the original match order, until only one player remains; do not output the initial list.

This site has made the standard input and output explicit.

Input

The first line contains n, and the second line contains n distinct ranks. On this site 1≤n≤200000 and 1≤rank≤10⁹.

Output

The first line is the number of rounds R; then one line per round, giving the number of advancing players followed by their ranks.

Example 1

Input:

8
1 2 3 4 5 6 7 8

Output:

3
4 1 3 5 7
2 1 5
1 1

Example 2

Input:

3
3 1 2

Output:

2
2 1 2
1 1

Example 3

Input:

1
5

Output:

0

Example notes

Example 1: the three rounds are 1 3 5 7, 1 5, and 1. Example 2: in the first round 1 beats 3 and 2 gets a bye, giving 1 2; in the second round 1 advances. Example 3: only one player remains from the start, so there are no knockout rounds; output 0 rounds.

Editorial

Loading solution…