#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define lsb(x) (x & (-x))
#define vi vector<int>
#define YES { cout << "YES" << endl; return; }
#define NO { cout << "NO" << endl; return; }
using ll = long long;
using pii = std::pair<int, int>;
const int NMAX = 3e5;
const int VMAX = 1e6;
using namespace std;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
namespace DS {
unordered_map<int, int, custom_hash> fr;
int water_level = 0;
int sum = 0;
int cnt_obj = 0;
int get_freq(int x) {
return fr[x - water_level];
}
inline void add_object(int x, int ap) {
cnt_obj += ap;
sum += (x - water_level) * ap;
fr[x - water_level] += ap;
}
inline void remove_object(int x, int ap) {
cnt_obj -= ap;
sum -= (x - water_level) * ap;
fr[x - water_level] -= ap;
}
inline void add_val(int x) {
water_level += x;
}
inline void set(int x, int y) {
int f = get_freq(x);
add_object(y, f);
remove_object(x, f);
}
inline int get() {
return sum + water_level * cnt_obj;
}
}
string op;
int a[NMAX + 5], n, q;
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
DS::add_object(a[i], 1);
}
cin >> q;
for (int i = 0, x, y; i < q; ++i) {
cin >> op;
if (op == "INFLATION") {
cin >> x;
DS::add_val(x);
}
if (op == "SET") {
cin >> x >> y;
DS::set(x, y);
}
cout << DS::get() << '\n';
}
return 0;
}