#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5, nax = 1e6 + 5;
char rodz[25];
int id[25];
int res[2 * nax];
int cob(int a) {
  if (a) return (a % 2 ? 1 : 0) + cob(a / 2);
  return 0;
}
int pro() {
  int n;
  cin >> n;
  vector<int> w;
  for (int _ = 1, _n = (n); _ <= _n; ++_) {
    int a;
    cin >> a;
    w.push_back(a);
  }
  sort(w.begin(), w.end());
  reverse(w.begin(), w.end());
  cin >> n;
  for (int i = 0, _n = (n); i < _n; ++i) cin >> rodz[i] >> id[i];
  for (int m = 0, _n = (1 << n); m < _n; ++m)
    if (m) {
      int jed = cob(m), zer = n - jed;
      if (id[zer] == 1) {
        res[m] = -inf;
        if (rodz[zer] == 'p') {
          for (int i = 0, _n = (n); i < _n; ++i)
            if (m & (1 << i)) res[m] = max(res[m], (res[m ^ (1 << i)] + w[i]));
        } else
          for (int i = 0, _n = (n); i < _n; ++i)
            if (m & (1 << i)) res[m] = max(res[m], (res[m ^ (1 << i)]));
      } else {
        res[m] = inf;
        if (rodz[zer] == 'p') {
          for (int i = 0, _n = (n); i < _n; ++i)
            if (m & (1 << i)) res[m] = min(res[m], (res[m ^ (1 << i)] - w[i]));
        } else
          for (int i = 0, _n = (n); i < _n; ++i)
            if (m & (1 << i)) res[m] = min(res[m], (res[m ^ (1 << i)]));
      }
    }
  cout << res[(1 << n) - 1];
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  int z = 1;
  for (int _ = 1, _n = (z); _ <= _n; ++_) pro();
  return 0;
}
