题目描述
Problem Description
The two-player game "Saitoon" is popular on the streets.
This year, the "Maximum-Saitoon-cup" tournament (unrelated to Maximum-cup-2018) has successfully concluded with great enthusiasm.
Saito, one of the organizers of this tournament, is about to start verifying the match results sent by the record keeper.
The tournament match results are managed using BNF notation as follows:
<CompetitionLog> $ ::= $ <GameResults> <GameResults> $ ::= $ <PlayerData><PlayerData> <PlayerData> $ ::= $ \[<PlayerID><WinningOrLosing>\] <PlayerID> $ ::= $ (<GameResults>) | (<number>) <WinningOrLosing> $ ::= $ o | x <number> $ ::= $ <digit> | <number><zero> | <number><digit> <digit> $ ::= $ 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 <zero> $ ::= $ 0
Additionally, the details of the tournament match results are as follows:
- The tournament is conducted in a knockout format.
- The match results are sent as <CompetitionLog>.
- Each match in the tournament is represented by <GameResults>, and each match always results in one win and one loss.
- The opponents in each match are represented by adjacent <PlayerData>.
- <PlayerID> represents the unique ID of the player. When it contains <number>, it is that number; when it contains <GameResults>, it is the <PlayerID> of the winner of that match.
- <WinningOrLosing> indicates whether the player won or lost the match, where 'o' means win and 'x' means loss.
- The IDs of participating players are assigned from 1 to N based on the order of their <number>-represented <PlayerID> from left to right in the match results.
Saito is about to verify these match results against the "data on how many wins each player has" he has on hand, and if they match, his job will be complete.
However, Saito has noticed a serious issue: some of the match results information has been lost.
Fortunately, he has the "data on how many wins each player has," so it seems possible to restore the results, but it seems too difficult for Saito.
Therefore, Saito has decided to ask you, an excellent programmer, to restore the match results.
Your task is to restore the match results assuming the "data on how many wins each player has" is correct.
The missing parts are represented by "?", so please find out what was originally there.
Input Format
The input is given from the standard input in the following format:
$ S $ $ N $ $ a_{1} $ $ a_{2} $ $ ... $ $ a_{N} $
The first line contains the match results with missing information.
The second line contains the number of participating players.
The third line contains the information on how many wins each player from 1 to N has, given as $ a_{1} $ to $ a_{N} $.
Output Format
Output the correct match results in one line.
Sample Input and Output
Sample Input #1
[([(1)o][(2)x]??][([(?)x][(4)o])x]
4
2 0 0 1
Sample Output #1
[([(1)o][(2)x])o][([(3)x][(4)o])x]
Sample Input #2
?([?[(?)o]?(?([(2?o]??[?3)o][?4?x??x])?]??5)x??x???][????])x?[??)o?
7
1 2 1 0 0 1 1
Sample Output #2
[([([(1)o][([([(2)o][([(3)o][(4)x])x])o][(5)x])x])x][(6)o])x][(7)o]
Notes/Hints
Constraints
- $12 \leq |S| \leq 200$
- $2 \leq N \leq 16$
- The number of '?' is between 1 and $min(\frac{|S|}{2}, 50)$.
- It is guaranteed that the match results can be uniquely restored.
Sample Explanation 1
Since the player IDs are assigned from left to right from 1 to N, the third "?" should be "3". The restored match results show that player 1 has 2 wins, player 2 has 0 wins, player 3 has 0 wins, and player 4 has 1 win, which matches the data on hand.
Sample Explanation 2
The restoration is always uniquely determined.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分