#include <bits/stdc++.h>
using namespace std;
struct s {
  char ac[2];
  int tm;
};
s inp[21];
bool vis[21][1048579];
int dp[21][1048579], s[103];
void solve(int x, int m, int bt) {
  int i;
  if (vis[x][bt]) return;
  vis[x][bt] = 1;
  if (x == m) {
    dp[x][bt] = 0;
    return;
  }
  if (inp[x].tm == 1)
    dp[x][bt] = -1000000000;
  else
    dp[x][bt] = 1000000000;
  for (i = 0; i < m; i++) {
    if (bt & (1 << i)) {
      solve(x + 1, m, bt - (1 << i));
      if (inp[x].ac[0] == 'p') {
        if (inp[x].tm == 1)
          dp[x][bt] = max(dp[x][bt], s[i] + dp[x + 1][bt - (1 << i)]);
        else
          dp[x][bt] = min(dp[x][bt], -s[i] + dp[x + 1][bt - (1 << i)]);
      } else {
        if (inp[x].tm == 1)
          dp[x][bt] = max(dp[x][bt], dp[x + 1][bt - (1 << i)]);
        else
          dp[x][bt] = min(dp[x][bt], dp[x + 1][bt - (1 << i)]);
      }
    }
  }
}
int main() {
  int n, i, m;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &s[i]);
  sort(s, s + n);
  scanf("%d", &m);
  for (i = 0; i < m; i++) scanf("%s%d", inp[i].ac, &inp[i].tm);
  for (i = n - m; i < n; i++) s[i - n + m] = s[i];
  solve(0, m, (1 << m) - 1);
  printf("%d\n", dp[0][(1 << m) - 1]);
  return 0;
}
