#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long infLL = 0x3f3f3f3f3f3f3f3fLL;
const int hash_mod = 1000037;
const double eps = 1e-10;
const double pi = acos(-1);
const int maxn = 100 + 5;
const int maxm = 20 + 5;
const int maxs = (1 << 20) + 5;
int n, m;
int a[maxn];
char op[maxm];
int t[maxm];
bool vis[maxs];
int opt[maxs];
bool cmp(int x, int y) { return x > y; }
void dp(int dep, int S) {
  if (vis[S]) return;
  vis[S] = true;
  if (dep == m) {
    opt[S] = 0;
    return;
  }
  if (op[dep] == 'p') {
    for (int i = 0; i < n; ++i)
      if (S & (1 << i)) {
        int S0 = S ^ (1 << i);
        dp(dep + 1, S0);
        opt[S] = opt[S0] + (t[dep] == 1 ? a[i] : -a[i]);
        break;
      }
  } else {
    if (t[dep] == 1) {
      opt[S] = -inf;
      for (int i = 0; i < n; ++i)
        if (S & (1 << i)) {
          int S0 = S ^ (1 << i);
          dp(dep + 1, S0);
          opt[S] = max(opt[S], opt[S0]);
        }
    } else {
      opt[S] = inf;
      for (int i = 0; i < n; ++i)
        if (S & (1 << i)) {
          int S0 = S ^ (1 << i);
          dp(dep + 1, S0);
          opt[S] = min(opt[S], opt[S0]);
        }
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  sort(a, a + n, cmp);
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    char buf[2];
    scanf("%s%d", buf, &t[i]);
    op[i] = buf[0];
  }
  int all = (1 << m) - 1;
  dp(0, all);
  printf("%d\n", opt[all]);
  return 0;
}
