#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 30) - 1;
const long double EPS = 1e-9;
const long double PI = fabsl(atan2l(0.0, -1.0));
int n;
int c[111];
int m;
int type[22];
int who[22];
void load() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &c[i]);
  }
  scanf("%d", &m);
  char buf[10] = {0};
  for (int i = 0; i < m; i++) {
    scanf("%s%d", buf, &who[i]);
    --who[i];
    type[i] = buf[0] == 'p' ? 0 : 1;
  }
}
int cnt;
int dp[20][1 << 20];
int f(int pos, int mask) {
  if (pos == m) {
    return 0;
  }
  int &res = dp[pos][mask];
  if (res != -1) {
    return res;
  }
  res = who[pos] == 0 ? -INF : INF;
  for (int i = 0; i < m; i++) {
    if ((((mask) & (1 << (i))) == 0 ? false : true)) {
      continue;
    }
    int cres = f(pos + 1, mask | (1 << i));
    if (type[pos] == 0) {
      cres += (who[pos] == 0 ? c[i] : -c[i]);
    }
    if (who[pos] == 0) {
      res = max(res, cres);
    } else {
      res = min(res, cres);
    }
  }
  return res;
}
void solve() {
  sort(c + 0, c + n, greater<int>());
  memset(dp, -1, sizeof(dp));
  printf("%d\n", f(0, 0));
}
int main() {
  clock_t start = clock();
  load();
  solve();
  ;
  return 0;
}
