#include <bits/stdc++.h>
using namespace std;
int in[105];
struct node {
  int a, b;
} ac[25];
int n, m;
bool cmp(int a, int b) { return a > b; }
int DP[25][1050000], done[25][1050000];
int cal(int cur, int s) {
  if (done[cur][s] == 1) return DP[cur][s];
  if (cur >= n) return 0;
  done[cur][s] = 1;
  int sum, t, i, j, x;
  if (ac[cur].b == 1)
    t = -1999999999;
  else
    t = 1999999999;
  if (ac[cur].a == 1) {
    for (x = 1, i = 0; i < m; x = x << 1, i++) {
      if ((s | x) != s) {
        if (ac[cur].b == 1) {
          t = max(t, cal(cur + 1, s | x) + in[i]);
        } else if (ac[cur].b == 2) {
          t = min(t, cal(cur + 1, s | x) - in[i]);
        }
      }
    }
  } else {
    for (x = 1, i = 0; i < m; x = x << 1, i++) {
      if ((s | x) != s) {
        if (ac[cur].b == 1)
          t = max(t, cal(cur + 1, s | x));
        else
          t = min(t, cal(cur + 1, s | x));
      }
    }
  }
  DP[cur][s] = t;
  return t;
}
int main() {
  int i, j, k, a, b;
  char o[5];
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &in[i]);
  sort(in, in + n, cmp);
  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    scanf("%s %d", o, &ac[i].b);
    if (o[0] == 'p')
      ac[i].a = 1;
    else
      ac[i].a = 2;
  }
  n = min(n, m);
  m = n;
  printf("%d", cal(0, 0));
  scanf(" ");
  return 0;
}
