CF BUDDY
← Problems·

1767D · Playoff

1500 · combinatorics, constructive algorithms, dp

Problem: 2n2^n teams participate in a playoff tournament. The tournament consists of 2n12^n - 1 games. They are held as follows: in the first phase of the tournament, the teams are split into pairs: team 11 plays against team 22, team 33 plays against team 44, and so on (so, 2n12^{n-1} games are played in that phase). When a team loses a game, it is eliminated, and each game results in elimination of one team (there are no ties). After that, only 2n12^{n-1} teams remain. If only one team remains, it is declared the champion; otherwise, the second phase begins, where 2n22^{n-2} games are played: in the first one of them, the winner of the game "11 vs 22" plays against the winner of the game "33 vs 44", then the winner of the game "55 vs 66" plays against the winner of the game "77 vs 88", and so on. This process repeats until only one team remains.

The skill level of the ii-th team is pip_i, where pp is a permutation of integers 11, 22, ..., 2n2^n (a permutation is an array where each element from 11 to 2n2^n occurs exactly once).

You are given a string ss which consists of nn characters. These characters denote the results of games in each phase of the tournament as follows:

  • if sis_i is equal to 0, then during the ii-th phase (the phase with 2ni2^{n-i} games), in each match, the team with the lower skill level wins;
  • if sis_i is equal to 1, then during the ii-th phase (the phase with 2ni2^{n-i} games), in each match, the team with the higher skill level wins.

Let's say that an integer xx is winning if it is possible to find a permutation pp such that the team with skill xx wins the tournament. Find all winning integers.

Input Format: The first line contains one integer nn (1n181 \le n \le 18).

The second line contains the string ss of length nn consisting of the characters 0 and/or 1.

Output Format: Print all the winning integers xx in ascending order.

Sample Cases

Case 1

Input

3
101

Output

4 5 6 7

Case 2

Input

1
1

Output

2

Case 3

Input

2
01

Output

2 3

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback