#P10987. [2015杭电多校]Expression
[2015杭电多校]Expression
Expression
Problem Description
Teacher Mai has numbers and operators("+", "-" or "*"), which are arranged in the form . He wants to erase numbers one by one. In -th round, there are numbers remained. He can erase two adjacent numbers and the operator between them, and then put a new number (derived from this one operation) in this position. After rounds, there is the only one number remained. The result of this sequence of operations is the last number remained. He wants to know the sum of results of all different sequences of operations. Two sequences of operations are considered different if and only if in one round he chooses different numbers. For example, a possible sequence of operations for "" is $1+4*6-8*3\to 1+4*(-2)*3\to 1+(-8)*3\to (-7)*3\to -21$.
Input
There are multiple test cases. For each test case, the first line contains one number . The second line contains integers . The third line contains a string with length consisting "+","-" and "*", which represents the operator sequence.
Output
For each test case print the answer modulo .
Sample Input
3
3 2 1
-+
5
1 4 6 8 3
+*-*
Sample Output
2
999999689
Hint
Two numbers are considered different when they are in different positions.
Author
xudyh
Source
2015 Multi-University Training Contest 9