#C5038. Find Combination Sequence
Find Combination Sequence
Find Combination Sequence
You are given two sequences of strings. The first sequence represents a list of ingredients and the second sequence represents the final dish obtained by combining these ingredients in a specific alternating order. In this process, the combination is done by picking ingredients alternately from the beginning and the end of the remaining list. Formally, if there are n ingredients, then for every index i (0-indexed):
- If i is even, then the ingredient from the front (at index \(\lfloor i/2 \rfloor\)) is chosen.
- If i is odd, then the ingredient from the back (at index \(n - \lceil i/2 \rceil\)) is chosen.
Your task is to determine and print the sequence of original indices (0-indexed) from the ingredients list that corresponds to the final dish order.
Note: The input guarantees that the final dish is always a valid result of this alternating picking process.
inputFormat
The input is read from stdin
and has the following format:
n ingredient1 ingredient2 ... ingredientn final_dish1 final_dish2 ... final_dishn
where n is the number of ingredients (an integer), the second line contains n space-separated strings representing the ingredients in their original order, and the third line contains n space-separated strings representing the ingredients in the final dish order.
outputFormat
Output to stdout
a single line containing n space-separated integers representing the 0-indexed positions of the ingredients used to create the final dish following the alternating process.
For example, if the output is:
0 3 1 2
then it indicates that the order of indices used was 0, 3, 1, and 2 respectively.
## sample4
apple banana cherry date
apple date banana cherry
0 3 1 2
</p>