#include using namespace std; map bit; void add(int k, int v) { for (k++; k < 1e9; k += k & -k) bit[k] += v; } int sum(int k) { int res = 0; for (k++; k > 0; k &= k - 1) res += bit[k]; return res; } int main() { int n, T; cin >> n; vector L(n); for (int i = 0; i < n; i++) scanf("%d", &L[i]); cin >> T; map> score; vector cnt(n); for (int ii = T - 1; ii >= 0; ii--) { string name, prob; cin >> name >> prob; if (prob[0] == '?') { printf("%d\n", score.size() - sum(score[name].first * T + score[name].second - 1)); } else { int id = prob[0] - 'A'; cnt[id]++; int s = score[name].first; int t = score[name].second; int ss = s + 50 * L[id] + 500 * L[id] / (8 + 2 * cnt[id]); int tt = ii; if (s > 0) add(s * T + t, -1); add(ss * T + tt, 1); score[name].first = ss; score[name].second = tt; } } }