#include <bits/stdc++.h>
using namespace std;
const int MAXN = -1;
int n, m;
vector<long long> S;
vector<pair<int, bool> > T;
int G[(1 << 22)];
long long sol(int bm) {
  int turn = __builtin_popcount(bm);
  if (turn == m) return 0;
  int &ret = G[bm];
  if (ret != -1) return ret;
  vector<long long> PS;
  for (int i = (0); i < (int)(m); i++)
    if ((bm & (1 << i)) == 0) {
      long long act =
          sol(bm + (1 << i)) + (T[turn].second ? (S[i] * T[turn].first) : 0LL);
      PS.push_back(act);
    }
  assert(PS.size());
  long long mx = PS[0], mn = PS[0];
  for (int i = (1); i < (int)(PS.size()); i++) {
    mx = max(mx, PS[i]);
    mn = min(mn, PS[i]);
  }
  return ret = (T[turn].first == 1 ? mx : mn);
}
int main() {
  while (scanf("%d", &n) == 1) {
    S.resize(n);
    for (int i = (0); i < (int)(n); i++) scanf("%lld", &S[i]);
    sort(S.begin(), S.end());
    reverse(S.begin(), S.end());
    scanf("%d", &m);
    S.resize(m);
    T.resize(m);
    for (int i = (0); i < (int)(m); i++) {
      int a;
      string s;
      cin >> s >> a;
      T[i].first = (a == 1 ? 1 : -1);
      T[i].second = (s == "p");
    }
    for (int i = (0); i < (int)(1 << 22); i++) G[i] = -1;
    printf("%lld\n", sol(0));
  }
  return 0;
}
