#P7787. [COCI 2016/2017 #6] Turnir

[COCI 2016/2017 #6] Turnir

Description

You are given a sequence of 2N2^N positive integers. In each round, these numbers are compared in the given order: the larger number stays, and the smaller number is eliminated, until only one number remains.

Now you are given the initial order of these 2N2^N numbers. Please find, for each number, the maximum round it can survive to.

Input Format

The first line contains an integer NN.

The second line contains 2N2^N integers AiA_i, representing the numbers in the sequence.

Output Format

Output one line with 2N2^N integers, where the ii-th integer represents the round that the ii-th number can survive to.

2
1 4 3 2
2 0 1 1
4
5 3 2 6 4 8 7 1 2 4 3 3 6 4 8 1
1 2 2 1 1 0 1 3 2 1 2 2 1 1 0 3
1
1 1
0 0

Hint

[Sample Explanation #2]

[Constraints]

For 100%100\% of the testdata, 1N201\le N\le 20, 0Ai1×1090\le A_i\le 1\times 10^9.

[Note]

The scoring of this problem follows the original COCI settings, with a full score of 100100.

This problem is translated from COCI2016_2017 CONTEST #6 T3 TURNIR.

Translated by ChatGPT 5