In a tournament, 2m teams compete for the championship title. The tournament consists of…
- User
In a tournament, 2m teams compete for the championship title. The tournament consists of 2m−1 matches, organized as follows: in the initial round, teams are paired up: team 1 faces team 2, team 3 faces team 4, and so on (resulting in 2m−1 matches). Each match eliminates one team (no ties occur). After this phase, only 2m−1 teams remain. If there is only one team left, it is declared the champion; otherwise, the next phase begins, where 2m−2 matches occur. The winner of "1 vs 2" competes against the winner of "3 vs 4," and so on. This continues until one team remains.
The skill level of the i -th team is qi , where q is a permutation of the integers 1,2,…,2m (a permutation means each value from 1 to 2m appears exactly once).
You are given a string r consisting of m characters. These characters indicate the outcome of matches in each phase as follows:
If ri is equal to 0 , then in the i -th phase (the phase with 2m−i matches), the team with the lower skill level wins each match. If ri is equal to 1 , then in the i -th phase (the phase with 2m−i matches), the team with the higher skill level wins each match. Determine all integers k that could potentially win the tournament by finding a permutation q such that the team with skill k wins. List these integers in ascending order.
Input The first line contains one integer m (1≤m≤18 ).
The second line contains the string r of length m , consisting of characters 0 and/or 1.
Output Print all winning integers k in ascending order.
- Assistant