#include <bits/stdc++.h>
using namespace std;
const int N = 1050000;
const int M = 105;
const int INF = 1e9;
int n, m, v[N], h[M], order[N][2], rec[N];
bool cmp(int a, int b) { return a > b; }
int dp(int s, int d) {
  if (v[s]) return rec[s];
  if (d >= m) return 0;
  int &ans = rec[s];
  v[s] = 1;
  ans = 0;
  while (d < m) {
    if (order[d][1]) {
      int id;
      for (id = 0; id < n; id++)
        if ((s & (1 << id)) == 0) break;
      s += (1 << id);
      order[d][0] == 1 ? ans += h[id] : ans -= h[id];
    } else {
      int tmp = order[d][0] == 1 ? -INF : INF;
      for (int i = 0; i < n; i++)
        if ((s & (1 << i)) == 0) {
          int t = dp(s + (1 << i), d + 1);
          if (order[d][0] == 1)
            tmp = max(tmp, t);
          else
            tmp = min(tmp, t);
        }
      ans += tmp;
      break;
    }
    d++;
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &h[i]);
  sort(h, h + n, cmp);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    char s[6];
    scanf("%s%d", &s, &order[i][0]);
    order[i][1] = (s[0] == 'p');
  }
  n = min(n, 20);
  printf("%d\n", dp(0, 0));
}
