#include <bits/stdc++.h>
using namespace std;
const int rozmiar_kubelka = 356;
int n, m;
vector<int> her;
vector<pair<char, int> > mov;
int dp[(1 << 20)];
void policz() {
  dp[0] = 0;
  int a = 1;
  for (; a < (1 << m); a++) {
    int c = __builtin_popcount(a);
    c = m - c;
    auto akt = mov[c];
    if (akt.second == 1)
      dp[a] = -1000000000;
    else
      dp[a] = 1000000000;
    if (akt == make_pair('p', 1)) {
      int it = 0;
      for (int i = 1; true; i *= 2) {
        if (i & a) {
          dp[a] = dp[a ^ i] + her[it];
          break;
        }
        it++;
      }
    }
    if (akt == make_pair('p', 2)) {
      int it = 0;
      for (int i = 1; true; i *= 2) {
        if (i & a) {
          dp[a] = dp[a ^ i] - her[it];
          break;
        }
        it++;
      }
    }
    if (akt == make_pair('b', 1)) {
      int it = m - 1;
      for (int i = 1; i <= a; i *= 2) {
        it--;
        if (i & a) {
          dp[a] = max(dp[a], dp[a ^ i]);
        }
      }
    }
    if (akt == make_pair('b', 2)) {
      int it = m - 1;
      for (int i = 1; i <= a; i *= 2) {
        it--;
        if (i & a) {
          dp[a] = min(dp[a], dp[a ^ i]);
        }
      }
    }
  }
}
int main() {
  vector<int> vec;
  scanf("%d", &n);
  for (int i = 0; i < (n); ++i) {
    int a;
    scanf("%d", &a);
    vec.push_back(a);
  }
  scanf("%d", &m);
  sort(vec.begin(), vec.end());
  for (int i = ((int)(n)) - 1; i >= (n - m); --i) her.push_back(vec[i]);
  for (int i = 0; i < (m); ++i) {
    char p;
    int a;
    scanf("%c%c%d", &p, &p, &a);
    mov.push_back({p, a});
  }
  policz();
  printf("%d", dp[(1 << m) - 1]);
}
