#include <bits/stdc++.h>
using namespace std;
int N, M;
int S[200];
int DP[2000000];
bool OK[2000000];
char sp[2000000];
int tm[2000000];
int DFS(int O, int P) {
  if (OK[O]) return DP[O];
  for (int bi = 0, di = 1; bi < N; bi++, di *= 2) {
    int p = 0;
    if (sp[P] == 'p') p = S[bi];
    if (O & di) {
      int t = DFS(O - di, P + 1);
      if (tm[P] == 1) {
        if (!OK[O] || DP[O] < t + p) DP[O] = t + p, OK[O] = true;
      } else {
        if (!OK[O] || DP[O] > t - p) DP[O] = t - p, OK[O] = true;
      }
    }
  }
  return DP[O];
}
int main() {
  scanf("%d", &N);
  for (int Ni = 0; Ni < N; Ni++) scanf("%d", &S[Ni]);
  sort(S, S + N, greater<int>());
  N = min(N, 20);
  scanf("%d", &M);
  for (int Mi = 0; Mi < M; Mi++) cin >> sp[Mi] >> tm[Mi];
  OK[0] = true;
  printf("%d\n", DFS((1 << N) - 1, 0));
}
