Problem: You are given a sequence , where its elements are either in the form + x or -, where is an integer.
For such a sequence where its elements are either in the form + x or -, define as follows:
- iterate through 's elements from the first one to the last one, and maintain a multiset as you iterate through it.
- for each element, if it's in the form + x, add to ; otherwise, erase the smallest element from (if is empty, do nothing).
- after iterating through all 's elements, compute the sum of all elements in . is defined as the sum.
The sequence is a subsequence of the sequence if can be derived from by removing zero or more elements without changing the order of the remaining elements. For all 's subsequences , compute the sum of , modulo .
Input Format: The first line contains an integer () — the length of .
Each of the next lines begins with an operator + or -. If the operator is +, then it's followed by an integer (). The -th line of those lines describes the -th element in .
Output Format: Print one integer, which is the answer to the problem, modulo .
Note: In the first example, the following are all possible pairs of and :
- {}, .
- {-}, .
- {+ 1, -}, .
- {-, + 1, -}, .
- {+ 2, -}, .
- {-, + 2, -}, .
- {-}, .
- {-, -}, .
- {+ 1, + 2}, .
- {+ 1, + 2, -}, .
- {-, + 1, + 2}, .
- {-, + 1, + 2, -}, .
- {-, + 1}, .
- {+ 1}, .
- {-, + 2}, .
- {+ 2}, .
The sum of these values is .