#include <bits/stdc++.h>
using namespace std;
struct oper {
  char ch;
  int x;
} p[20 + 1];
char s[10];
int n, m, a[100 + 1], f[1 << 20 | 1];
int main(int argc, char *argv[]) {
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) scanf("%d", a + i);
  sort(a + 1, a + m + 1);
  reverse(a + 1, a + m + 1);
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s%d", s, &p[i].x);
    p[i].ch = s[0];
  }
  for (int x = (1 << n) - 2; x >= 0; --x) {
    int i = __builtin_popcount(x) + 1;
    int cur = p[i].x == 1 ? -34567890 : 34567890;
    for (int j = 1; j <= n; ++j)
      if (!(x >> j - 1 & 1)) {
        int w = f[x | (1 << j - 1)];
        if (p[i].x == 1) {
          if (p[i].ch == 'b')
            cur = max(cur, w);
          else
            cur = max(cur, w + a[j]);
        } else {
          if (p[i].ch == 'b')
            cur = min(cur, w);
          else
            cur = min(cur, w - a[j]);
        }
      }
    f[x] = cur;
  }
  printf("%d\n", f[0]);
  fclose(stdin);
  fclose(stdout);
  return 0;
}
