#include <bits/stdc++.h>
using namespace std;
int s[200], n, m;
vector<pair<char, int> > ve;
int res[21][1 << 21];
int cam(const void *x, const void *y) { return *(int *)y - *(int *)x; }
int dp(int step, int val) {
  pair<char, int> pi = ve[step];
  int maxnum = -1, index = -1, i, ans;
  for (i = 0; i <= 20; i++) {
    if ((val & (1 << i)) && maxnum == -1) {
      maxnum = s[i];
      index = i;
    }
  }
  if (step == m) return 0;
  if (res[step][val] != 1000000000) return res[step][val];
  if (pi.first == 'p') {
    if (pi.second == 1) {
      res[step][val] = maxnum + dp(step + 1, val ^ (1 << index));
      return res[step][val];
    } else {
      return res[step][val] = -maxnum + dp(step + 1, val ^ (1 << index));
    }
  } else {
    if (pi.second == 1) {
      ans = -1000000000;
      for (i = 0; i <= 20; i++) {
        if (val & (1 << i)) {
          ans = max(ans, dp(step + 1, val ^ (1 << i)));
        }
      }
    } else {
      ans = 1000000000;
      for (i = 0; i <= 20; i++) {
        if (val & (1 << i)) {
          ans = min(ans, dp(step + 1, val ^ (1 << i)));
        }
      }
    }
  }
  return res[step][val] = ans;
}
int main() {
  memset(res, -1, sizeof(res));
  int i, j, x;
  char str[20];
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &s[i]);
  }
  qsort(s, n, sizeof(s[0]), cam);
  if (n > 20) n = 20;
  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    for (j = 0; j < (1 << n); j++) {
      res[i][j] = 1000000000;
    }
  }
  for (i = 0; i < m; i++) {
    scanf("%s %d", str, &x);
    ve.push_back(make_pair(str[0], x));
  }
  printf("%d\n", dp(0, (1 << n) - 1));
  return 0;
}
