#include <bits/stdc++.h>
using namespace std;
pair<int, int> memo[2][(1 << 20) + 5];
char op[22], t[22];
int main() {
  int n;
  scanf("%d", &n);
  vector<int> vec(n);
  for (int i = 0; i < n; ++i) scanf("%d", &vec[i]);
  sort(vec.rbegin(), vec.rend());
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) scanf(" %c %d", op + i, t + i);
  int na, nb;
  for (int i = m - 1; ~i; --i) {
    int id = i & 1, nid = id ^ 1;
    for (int msk = 0; msk < (1 << m); ++msk) {
      int &a = memo[id][msk].first, &b = memo[id][msk].second;
      a = b = 0;
      if (t[i] == 1)
        b = 1e9;
      else
        a = 1e9;
      if (op[i] == 'b') {
        a = memo[nid][msk].first, b = memo[nid][msk].second;
        for (int l = 0; l < m; ++l) {
          if ((msk >> l) & 1) {
            na = memo[nid][msk ^ (1 << l)].first,
            nb = memo[nid][msk ^ (1 << l)].second;
            if (t[i] == 1) {
              if (na - nb > a - b) {
                a = na;
                b = nb;
              }
            } else {
              if (nb - na > b - a) {
                a = na;
                b = nb;
              }
            }
          }
        }
      } else {
        for (int l = 0; l < m; ++l) {
          if ((msk >> l) & 1) {
            na = memo[nid][msk ^ (1 << l)].first,
            nb = memo[nid][msk ^ (1 << l)].second;
            if (t[i] == 1) {
              na += vec[l];
              if (na - nb > a - b) {
                a = na;
                b = nb;
              }
            } else {
              nb += vec[l];
              if (nb - na > b - a) {
                a = na;
                b = nb;
              }
            }
          }
        }
      }
    }
  }
  printf("%d", memo[0][(1 << m) - 1].first - memo[0][(1 << m) - 1].second);
}
