#include <bits/stdc++.h>
using namespace std;
int readInt() {
  int x;
  scanf("%d", &x);
  return x;
}
char readChar() {
  char ch = ' ';
  while (ch != 'p' && ch != 'b') scanf("%c", &ch);
  return ch;
}
int n;
vector<int> s;
vector<pair<char, int> > p;
vector<int> d, nd;
int kolBits(int x) {
  int ans = 0;
  while (x) {
    ans += (x & 1);
    x /= 2;
  }
  return ans;
}
int main() {
  n = readInt();
  s.resize(n);
  for (int i = 0; i < n; ++i) s[i] = readInt();
  n = readInt();
  sort(s.begin(), s.end());
  reverse(s.begin(), s.end());
  s.resize(n);
  p.resize(n);
  for (int i = 0; i < n; ++i) {
    p[i].first = readChar();
    p[i].second = readInt();
  }
  d.assign(1 << n, 0);
  for (int mask = ((1 << n) - 2); mask >= 0; --mask) {
    int num = kolBits(mask);
    char code = p[num].first;
    int player = p[num].second;
    if (player == 1)
      d[mask] = -1000000000;
    else
      d[mask] = 1000000000;
    for (int i = 0; i < n; ++i) {
      if (mask & (1 << i)) continue;
      int nd = d[mask + (1 << i)];
      if (code == 'p') {
        if (player == 1)
          nd += s[i];
        else
          nd -= s[i];
      }
      if (player == 1)
        d[mask] = max(d[mask], nd);
      else
        d[mask] = min(d[mask], nd);
    }
  }
  printf("%d\n", d[0]);
  return 0;
}
