Beauty and the Geek is a reality television series advertised as connecting female beauties and male geeks with the goal of creating "The Ultimate Social Experiment". This task is advertised as connecting reality TV and competitive programming with the goal of creating a fun task.
Our hero is a beauty Ena, trapped in a complete binary tree of depth
Ena knows an exact path from the root to the exit leaf. More precisely, she knows the correct sequence
of
The producers of the TV show will save the lost Ena if you, her geek partner, answer correctly to the
following question: What is the sum of leaf values where Ena can finish her trip, considering only leaves
with values of at least
Input Specification
The first line contains integers
In the second line there is a word containing L
(left) and R
(right) representing the
correct path from the root to the exit leaf.
The third line contains the number
The fourth line contains the number
Ena will be able to finish in leaves
Output Specification
Output the required sum as a decimal integer modulo
Constraints
Subtask | Points | Constraints |
---|---|---|
1 | 8 | |
2 | 14 | |
3 | 17 | |
4 | 61 | No additional constraints. |
Sample Input 1
3 0
LR
101
110
Sample Output 1
11
Explanation of Sample Output 1
Ena will never change her mind, but we don't know if she had the correct left/right sides in mind from the beginning. So, she might have followed the instructions correctly and go to the left, and then the right child. Or, she might have followed the inverse instructions, going first to the right child and then to the left child. The arriving leaves have values
Sample Input 2
4 2
LRR
1010
1110
Sample Output 2
37
Explanation of Sample Output 2
Possible Ena's paths:
Sample Input 3
5 2
RLLR
10010
10111
Sample Output 3
82
Comments