Time limit: 2 seconds Memory limit: 256 MB After Mahdi helped the prisoners dig the…
- User
Time limit: 2 seconds Memory limit: 256 MB After Mahdi helped the prisoners dig the tunnel, the prisoners started asking Mahdi questions to increase their trust in Mahdi.
They gave Mahdi a piece of code related to the merge sort algorithm and told him that a permutation of the numbers 1 to n sorted n according to the given code and also given the output produced by the code (note the couts in the code).
The code is as follows:
image
Now they want Mehdi to tell them the initial permutation they gave as input to the algorithm according to the code they gave him and according to the generated output.
Because the prisoners don't have enough time to check your answer, they ask you to give the desired permutation as input to the following function and tell them the output of the function.
image
input The first line of input contains the number n n is the length of permutation given as input to the code.
The second line is the string corresponding to the output produced by the code, which consists of numbers 1 and 2.
2 ≤ n ≤ 10
000 2≤n≤10,000
output In the only output line, output the number you got as an output from the checksum function in the code above.
Example Sample entry 1 4 12212 Plain text Sample output 1 987041 Plain text The initial permutation is equal to 2, 4, 3, 1.
Sample entry 2 2 1 Plain text Sample output 2 994 Plain text The initial permutation is equal to 1, 2.
Sample entry 3 2 2 Plain text Sample output 3 1024 Plain text The initial permutation is equal to 2, 1.
- Assistant