P29708 [洛谷] [COCI2016-2017#6] Turnir
普及+
题目描述

Problem Description

Given a sequence of $2^N$ positive integers. In each round, these numbers are compared in the given order, with the larger number remaining and the smaller number being eliminated, until only one number remains.

You are given the initial order of these $2^N$ numbers. Please determine the maximum round number each number can survive to.

Input Format

The first line contains an integer $N$.

The second line contains $2^N$ integers $A_i$, representing the sequence of numbers.

Output Format

A single line containing $2^N$ integers, each representing the maximum round number the $i$-th number can survive to.

Sample Input and Output

Sample Input #1

2
1 4 3 2

Sample Output #1

2 0 1 1

Sample Input #2

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

Sample Output #2

1 2 2 1 1 0 1 3 2 1 2 2 1 1 0 3

Sample Input #3

1
1 1

Sample Output #3

0 0

Notes

[Sample Explanation #2]

Explanation Image

[Data Range]

For $100\%$ of the data, $1 \le N \le 20$, $0 \le A_i \le 1 \times 10^9$.

[Notes]

This problem is scored according to the original COCI settings, with a full score of $100$.

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

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 1 4 3 2
样例输出
2 0 1 1