Given an array a = a_1, a_2, \ldots, a_n of integers, you are going to perform queries of the following types:
\boxed{+ \ x}: Insert into the array .
\boxed{- \ x}: Remove the last occurrence of from the array . (It is guaranteed that exists in at the time of the query.)
After each query, you are required to calculate the sum of subarrays for over all distinct permutations of . Since the answer may be very large, output it modulo 10^9 + 7.
NOTE: The effect of the queries is cumulative; they are not independent.
The first line contains two integers and (1 \le n, q \le 2 \cdot 10^5) — the initial length of the array and the number of queries.
The second line contains integers a_1, a_2, \ldots, a_n (-10^9 \le a_i \le 10^9) — the elements of the array .
Each of the next lines describes a query. Each query consists of either a character or denoting addition or removal, respectively, followed by an integer (-10^9 \le x \le 10^9) — the number to be added or removed.
It is guaranteed that for each test 0 \le \sum (n + q) \le 4 \cdot 10^5.
For each test, output q+1 lines: the answer for the initial array and the answers after each of the queries.
Example 1
The array is initially a = [1], which has only one permutation (), so the answer is .
After the first query - 1, we remove the last occurrence of . Now a = []; the answer is .
After the second query + 3, we have a=[3]; the answer is .
After the third query + 2, we have a=[3,2]:
For permutation : The sum is \sum([3]) + \sum([3,2]) + \sum([2]) = 10.
For permutation : The sum is \sum([2]) + \sum([2,3]) + \sum([3]) = 10.
Total answer: .
After the fourth query + 3, the array becomes a = [3, 2, 3]:
For permutation [3,2,3]: The sum is \sum([3]) + \sum([3,2]) + \sum([3,2,3]) + \sum([2]) + \sum([2,3]) + \sum([3]) = 26.
For permutation [2,3,3]: The sum is \sum([2]) + \sum([2,3]) + \sum([2,3,3]) + \sum([3]) + \sum([3,3]) + \sum([3]) = 27.
For permutation [3,3,2]: The sum is \sum([3]) + \sum([3,3]) + \sum([3,3,2]) + \sum([3]) + \sum([3,2]) + \sum([2]) = 27.
Total answer: .
After the fifth query + 2, the array becomes a = [3,2,3,2], and the answer is .
After the sixth query + 5, the array becomes a = [3,2,3,2,5], and the answer is .
After the seventh query - 3, the last occurrence of is removed; now a = [3,2,2,5], the answer is .
After the last query - 2, the last occurrence of is removed; now a = [3,2,5]. The answer is:
Permutation [3,2,5]: The sum is \sum([3]) + \sum([3,2]) + \sum([3,2,5]) + \sum([2]) + \sum([2,5]) + \sum([5]) = 32.
Permutation [3,5,2]: The sum is \sum([3]) + \sum([3,5]) + \sum([3,5,2]) + \sum([5]) + \sum([5,2]) + \sum([2]) = 35.
Permutation [2,5,3]: The sum is \sum([2]) + \sum([2,5]) + \sum([2,5,3]) + \sum([5]) + \sum([5,3]) + \sum([3]) = 35.
Permutation [2,3,5]: The sum is \sum([2]) + \sum([2,3]) + \sum([2,3,5]) + \sum([3]) + \sum([3,5]) + \sum([5]) = 33.
Permutation [5,2,3]: The sum is \sum([5]) + \sum([5,2]) + \sum([5,2,3]) + \sum([2]) + \sum([2,3]) + \sum([3]) = 32.
Permutation [5,3,2]: The sum is \sum([5]) + \sum([5,3]) + \sum([5,3,2]) + \sum([3]) + \sum([3,2]) + \sum([2]) = 33.
Total answer: .
Subtask ( points): All a_i=0 during the entire process.
Subtask ( points): n \le 6; q = 1.
Subtask ( points): a_1 = a_2 = \ldots = a_n and all operations are removals.
Subtask ( points): |a_i| \le 10^6 during the entire process.
Subtask ( points): q=1.
Subtask ( points): 1 \le n, q \le 1000.
Subtask ( points): No additional constraints.