#include <bits/stdc++.h>
using namespace std;
struct node {
  int ty, id;
} p[110];
int n, m, a[110], inf = 1000000000, f[21][1050000];
char s[2];
void read(int &x) {
  char ch = getchar();
  int mark = 1;
  for (; ch != '-' && (ch < '0' || ch > '9'); ch = getchar())
    ;
  if (ch == '-') mark = -1, ch = getchar();
  for (x = 0; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48;
  x *= mark;
}
inline bool cmp(int a, int b) { return a > b; }
inline int Get(int x, int y) { return (x >> y) & 1; }
int dfs(int i, int st) {
  if (i == m + 1) return 0;
  if (f[i][st] != -inf) return f[i][st];
  if (p[i].id == 2) {
    if (p[i].ty) {
      int Min = inf;
      for (int j = 0; j < m; j++)
        if (Get(st, j)) Min = min(Min, dfs(i + 1, st ^ (1 << j)));
      if (Min != inf) f[i][st] = Min;
    } else {
      int Min = inf;
      for (int j = 0; j < m; j++)
        if (Get(st, j)) Min = min(dfs(i + 1, st ^ (1 << j)) - a[j + 1], Min);
      if (Min != inf) f[i][st] = Min;
    }
  } else {
    if (p[i].ty) {
      for (int j = 0; j < m; j++)
        if (Get(st, j)) f[i][st] = max(f[i][st], dfs(i + 1, st ^ (1 << j)));
    } else {
      for (int j = 0; j < m; j++)
        if (Get(st, j))
          f[i][st] = max(f[i][st], dfs(i + 1, st ^ (1 << j)) + a[j + 1]);
    }
  }
  return f[i][st];
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) read(a[i]);
  read(m);
  sort(a + 1, a + n + 1, cmp);
  for (int i = 1; i <= m; i++) {
    scanf("%s", s);
    read(p[i].id);
    if (s[0] == 'b') p[i].ty = 1;
  }
  for (int i = 1; i <= m; i++)
    for (int j = 0; j < (1 << m); j++) f[i][j] = -inf;
  printf("%d\n", dfs(1, (1 << m) - 1));
  return 0;
}
