Inflation

Time limit: 3s Memory limit: 128MB Input: Output:

People in southern Sweden are known to eat falafel a lot. The price of falafel is highly volatile, and the best way to analyze the state of the economy is to go to the same falafel place every day and add up all the prices on their menu.

A falafel place has NN different dishes on their menu. The iith dish has price pip_i.

Every day, one of the following events happen:

  • INFLATION x: The integer xx is added to all prices.
  • SET x y: Every dish with price xx gets its price set to yy.

Your task is to process QQ days, and after each day print the sum of all prices pip_i.

Input

The first line contains one integer NN, the number of dishes.

The second line contains NN integers p1p_1, p2p_2 ,..., pNp_N.

The third line contains one integer QQ, the number of days.

The following QQ lines each contain a string ss followed by either one or two integers.

If ss is INFLATION, then one integer xx follows. This means that xx is added to all prices on this day.

If ss is SET, then two integers xx and yy follow. This means that all dishes with price xx get their price set to yy on this day.

Output

Print QQ lines, the sum of all prices pip_i after each day.

Constraints and Scoring

  • 1N31051 \leq N \leq 3 \cdot 10^5
  • 1pi1061 ≤ p_i ≤ 10^6 (for each ii such that 1iN1 ≤ i ≤ N)
  • 1Q1051 ≤ Q ≤ 10^5
  • 1x,y1061 ≤ x, y ≤ 10^6 for all days

Note: The answer may not fit in a 3232-bit integer, so be aware of overflows if you are using C++.

Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group you need to solve all test cases in the test group.

# Score Limits
1 14 N=1N = 1
2 28 N,Q,pi,x,y100N, Q, p_i, x, y \leq 100
3 19 There are only INFLATION events
4 23 There are only SET events
5 16 No additional constraints.

Example 1

stdin

5
2 1 1 2 5
6
INFLATION 1
SET 3 2
SET 5 2
INFLATION 4
SET 6 1
SET 10 1

stdout

16
14
14
34
14
5

Explication

This figure corresponds to the first two days of sample 11. Note that the sum of prices after the first day is 1616, so the first integer in the output is 1616.

Example 2

stdin

3
1 4 1
5
SET 1 1
SET 3 4
INFLATION 2
SET 3 1
SET 6 4

stdout

6
6
12
8
6

Log in or sign up to be able to send submissions!