#include "bits/stdc++.h" using namespace std; //Fenwick木を使う online; AC struct FenwickTree { typedef int T; vector v; void init(int n) { v.assign(n, T()); } int size() const { return (int)v.size(); } void add(int i, T x) { for(; i < size(); i |= i + 1) v[i] += x; } T sum(int i) const { T r = T(); for(-- i; i >= 0; i = (i & (i + 1)) - 1) r += v[i]; return r; } T sum(int left, int right) const { //[left, right) return sum(right) - sum(left); } void push_back(T x) { int i = size(); for(int w = 1; i & w; w <<= 1) x += v[i - w]; v.push_back(x); } }; int main() { int N; scanf("%d", &N); vector L(N); for(int i = 0; i < N; ++ i) scanf("%d", &L[i]); int T; scanf("%d", &T); struct Contestant { int totalScore; int lastTime; int subIndex; Contestant() : totalScore(0), lastTime(0), subIndex(-1) {} }; std::map contestants; std::vector count(N, 0); const int MaxScore = 15600; FenwickTree mainFT; mainFT.init(MaxScore + 1); vector subFTs(MaxScore + 1); std::vector scoreCount(MaxScore + 1); for(int i = 0; i < T; ++ i) { char name[17], P[2]; scanf("%s%s", name, P); if(*P != '?') { int p = *P - 'A'; assert(0 <= p && p < N); int stars = L[p]; int rank = ++ count[p]; int score = 50 * stars + 50 * stars * 10 / (8 + 2 * rank); assert(score > 0); auto &c = contestants[name]; if(c.totalScore != 0) { mainFT.add(c.totalScore, -1); subFTs[c.totalScore].add(c.subIndex, -1); } c.totalScore += score; c.lastTime = i + 1; assert(c.totalScore <= MaxScore); mainFT.add(c.totalScore, 1); c.subIndex = subFTs[c.totalScore].size(); subFTs[c.totalScore].push_back(1); } else { auto &c = contestants[name]; int ans = 0; ans += (int)contestants.size() - mainFT.sum(c.totalScore + 1); ans += subFTs[c.totalScore].sum(c.subIndex); printf("%d\n", ans + 1); } } return 0; }