#include <bits/stdc++.h>
using namespace std;
int f[1100000], p[1100000], n, m, a[110], b[30], c[30];
char cc;
bool cmp(int a, int b) { return a > b; }
void init() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n, cmp);
  scanf("%d\n", &n);
  for (int i = (0); i <= (n - 1); ++i) {
    scanf("%c%d\n", &cc, &b[i]);
    c[i] = (cc == 'p');
  }
  m = (1 << n) - 1;
  p[0] = 0;
  for (int i = (1); i <= (m); ++i) p[i] = p[i >> 1] + (i & 1);
}
void work() {
  int x, y;
  f[m] = 0;
  for (int i = (m - 1); i >= (0); --i) {
    x = p[i];
    f[i] = b[x] == 2 ? 100000000 : -100000000;
    for (int j = (1); j <= (n); ++j) {
      y = 1 << (j - 1);
      if (i & y) continue;
      if (b[x] == 1) {
        if (c[x])
          f[i] = max(f[i], a[j] + f[i ^ y]);
        else
          f[i] = max(f[i], f[i ^ y]);
      } else {
        if (c[x])
          f[i] = min(f[i], f[i ^ y] - a[j]);
        else
          f[i] = min(f[i], f[i ^ y]);
      }
    }
  }
  cout << f[0];
}
int main() {
  init();
  work();
  return 0;
}
