#include <bits/stdc++.h>
using namespace std;
const int INF = 10000000;
int d[1 << 20];
vector<pair<char, int> > v;
int s[110];
int main() {
  int n, m;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s, s + n);
  reverse(s, s + n);
  cin >> m;
  for (int i = 0; i < (1 << m); i++) {
    d[i] = -INF;
  }
  for (int i = 0; i < m; i++) {
    char type;
    int x;
    cin >> type >> x;
    v.push_back(make_pair(type, x));
  }
  d[0] = 0;
  for (int mask = 1; mask < (1 << m); mask++) {
    int t = __builtin_popcount(mask);
    t = m - t;
    char type = v[t].first;
    int x = v[t].second;
    if (x == 1) {
      d[mask] = -INF;
      for (int j = 0; j < m; j++) {
        if (((mask >> j) & 1) == 0) continue;
        int mask2 = mask - (1 << j);
        int t2 = d[mask2];
        if (type == 'p') {
          t2 += s[j];
        }
        d[mask] = max(d[mask], t2);
      }
    } else {
      d[mask] = INF;
      for (int j = 0; j < m; j++) {
        if (((mask >> j) & 1) == 0) continue;
        int mask2 = mask - (1 << j);
        int anss = d[mask2];
        if (type == 'p') {
          anss -= s[j];
        }
        d[mask] = min(d[mask], anss);
      }
    }
  }
  cout << d[(1 << m) - 1] << endl;
}
