#include using namespace std; using ll = long long; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define all(c) begin(c), end(c) #define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl #include #include #include using namespace __gnu_pbds; using Key = ll; typedef tree< Key, null_type, less, rb_tree_tag, tree_order_statistics_node_update> ordered_set; int N; int star[30]; int T; int solved[30]; // user-> int score[100010], lastsub[100010]; unordered_map f; int main(){ cin.tie(0); ios::sync_with_stdio(0); while(cin >> N){ memset(solved, 0, sizeof solved); memset(lastsub, 0, sizeof lastsub); memset(score, 0, sizeof score); rep(i,N) cin >> star[i]; cin >> T; int id = 0; ordered_set tree; rep(i,T){ string name; cin >> name; auto res = f.emplace(name, id); if(res.second) res.first->second = id++; int man = res.first->second; char str[10]; cin >> str; Key cur = -score[man]*1000000000LL + lastsub[man]; if(str[0] == '?'){ int ord = tree.order_of_key(cur); cout << ord + 1 << '\n'; } else { int prob = str[0] - 'A'; int s = 50*star[prob] + 50*star[prob] / (0.8 + 0.2*(solved[prob]+1)); ++solved[prob]; score[man] += s; lastsub[man] = i; auto nxt = -score[man]*1000000000LL +lastsub[man]; tree.erase(cur); tree.insert(nxt); } } } }