#include <bits/stdc++.h>
using namespace std;
const int MASK = (1 << 20) + 10;
const int N = 1e2 + 10;
int d[MASK], a[N];
int n, m;
vector<pair<char, int> > v;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a, a + n, greater<int>());
  cin >> m;
  char help1;
  int help2;
  for (int i = 0; i < m; ++i) {
    cin >> help1 >> help2;
    v.push_back(make_pair(help1, help2));
  }
  int help = min(n, m);
  d[0] = 0;
  int now;
  for (int i = 1; i < (1 << help); ++i) {
    help2 = help - __builtin_popcount(i);
    if (v[help2].second == 1) {
      d[i] = -1e8;
      for (int j = 0; j <= help; ++j)
        if (i & (1 << j)) {
          now = d[i - (1 << j)];
          if (v[help2].first == 'p') now += a[j];
          d[i] = max(d[i], now);
        }
      continue;
    }
    d[i] = 1e8;
    for (int j = 0; j <= help; ++j)
      if (i & (1 << j)) {
        now = d[i - (1 << j)];
        if (v[help2].first == 'p') now -= a[j];
        d[i] = min(d[i], now);
      }
  }
  cout << d[(1 << help) - 1];
}
