#include <bits/stdc++.h>
using namespace std;
const int unvisited = 0x7F7F7F7F;
const int inf = 0x5FFFFFFF;
int n, m;
std::vector<int> H;
char C[25];
int pl[25];
int state[1 << 20];
int game(int turn, int st) {
  if (state[st] != unvisited) return state[st];
  int& sol = state[st];
  sol = 0;
  if (C[turn] == 'p') {
    for (int i = 0; i < m; ++i)
      if (1 << i & ~st)
        return sol =
                   game(turn + 1, st | 1 << i) + (pl[turn] == 1 ? H[i] : -H[i]);
  } else {
    if (pl[turn] == 1) {
      sol = -inf;
      for (int i = 0; i < m; ++i)
        if (1 << i & ~st) sol = max(sol, game(turn + 1, st | 1 << i));
    } else {
      sol = inf;
      for (int i = 0; i < m; ++i)
        if (1 << i & ~st) sol = min(sol, game(turn + 1, st | 1 << i));
    }
  }
  return sol;
}
int main() {
  memset(state, 0x7F, sizeof state);
  scanf("%d", &n);
  for (int a, i = 0; i < n; ++i) {
    scanf("%d", &a);
    H.push_back(a);
  }
  scanf("%d", &m);
  state[(1 << m) - 1] = 0;
  for (int i = 0; i < m; ++i) scanf(" %c %d", C + i, pl + i);
  sort(H.begin(), H.end(), std::greater<int>());
  if (H.size() > m) H.resize(m);
  printf("%d\n", game(0, 0));
}
