#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int hero[maxn], dp[1 << 20];
bool vis[1 << 20];
int n, m;
struct ope {
  int type, id;
} op[25];
char str[3];
bool cmp(int a, int b) { return a > b; }
int solve(int pos, int step) {
  if (step == m) return 0;
  if (vis[pos]) return dp[pos];
  vis[pos] = 1;
  int res = -0x3f3f3f3f;
  if (step < m - 1 && op[step + 1].id != op[step].id) {
    if (op[step].type) {
      for (int i = 0; i < m; ++i)
        if (pos & (1 << i)) {
          res = hero[i] - solve(pos ^ (1 << i), step + 1);
          break;
        }
    } else {
      for (int i = 0; i < m; ++i)
        if (pos & (1 << i)) {
          res = max(res, -solve(pos ^ (1 << i), step + 1));
        }
    }
  } else {
    if (op[step].type) {
      for (int i = 0; i < m; ++i)
        if (pos & (1 << i)) {
          res = hero[i] + solve(pos ^ (1 << i), step + 1);
          break;
        }
    } else {
      for (int i = 0; i < m; ++i)
        if (pos & (1 << i)) {
          res = max(res, solve(pos ^ (1 << i), step + 1));
        }
    }
  }
  return dp[pos] = res;
}
int main() {
  scanf("%d", &n);
  int i;
  for (i = 0; i < n; ++i) scanf("%d", hero + i);
  sort(hero, hero + n, cmp);
  scanf("%d", &m);
  for (i = 0; i < m; ++i) {
    scanf("%s%d", str, &op[i].id);
    op[i].type = (str[0] == 'p');
  }
  memset(vis, 0, sizeof(vis));
  solve((1 << m) - 1, 0);
  if (op[0].id == 1)
    printf("%d\n", dp[(1 << m) - 1]);
  else
    printf("%d\n", -dp[(1 << m) - 1]);
  return 0;
}
