#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
const int inf = 0x3f3f3f3f;
int dp[1 << 20][20][2];
int n, m, s[maxn], op[maxn], ca[maxn];
int dfs1(int st, int x);
int dfs2(int st, int x);
int dfs(int st, int x) {
  if (ca[x] == 2) return dfs2(st, x);
  return dfs1(st, x);
}
int dfs1(int st, int x) {
  if (x >= m) return 0;
  if (dp[st][x][0] != -1) return dp[st][x][0];
  int ret = -inf;
  if (op[x]) {
    for (int i = 0; i < m; i++) {
      if (st & (1 << i)) {
        ret = max(ret, dfs(st - (1 << i), x + 1));
      }
    }
  } else {
    for (int i = 0; i < m; i++) {
      if (st & (1 << i)) {
        ret = dfs(st - (1 << i), x + 1) + s[i];
        break;
      }
    }
  }
  return (dp[st][x][0] = ret);
}
int dfs2(int st, int x) {
  if (x >= m) return 0;
  if (dp[st][x][1] != -1) return dp[st][x][1];
  int ret = inf;
  if (op[x]) {
    for (int i = 0; i < m; i++) {
      if (st & (1 << i)) {
        ret = min(ret, dfs(st - (1 << i), x + 1));
      }
    }
  } else {
    for (int i = 0; i < m; i++) {
      if (st & (1 << i)) {
        ret = dfs(st - (1 << i), x + 1) - s[i];
        break;
      }
    }
  }
  return (dp[st][x][1] = ret);
}
bool cmp(int x, int y) { return x > y; }
int main() {
  memset(dp, -1, sizeof(dp));
  char ch;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &s[i]);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf(" %c %d", &ch, &ca[i]);
    if (ch == 'b') op[i] = 1;
  }
  sort(s, s + n, cmp);
  printf("%d\n", dfs((1 << m) - 1, 0));
  return 0;
}
