#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int n, m, a[105], f[1 << 20], cnt[1 << 20];
vector<int> v[20];
struct point {
  string opt;
  int is;
} p[20];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n, greater<int>());
  cin >> m;
  for (int i = 0; i < (1 << m); i++) {
    cnt[i] = __builtin_popcount(i);
    v[cnt[i]].push_back(i);
  }
  for (int i = 0; i < m; i++) cin >> p[i].opt >> p[i].is;
  for (int kase = 0; kase < m; kase++) {
    for (auto u : v[kase + 1]) {
      if (p[m - 1 - kase].is == 1)
        f[u] = -inf;
      else
        f[u] = inf;
      if (p[m - 1 - kase].opt[0] == 'b') {
        for (int j = 0; j < m; j++) {
          if ((u >> j) & 1) {
            if (p[m - 1 - kase].is == 1)
              f[u] = max(f[u], f[u ^ (1 << j)]);
            else
              f[u] = min(f[u], f[u ^ (1 << j)]);
          }
        }
      } else {
        for (int j = 0; j < m; j++) {
          if ((u >> j) & 1) {
            if (p[m - 1 - kase].is == 1)
              f[u] = max(f[u], f[u ^ (1 << j)] + a[j]);
            else
              f[u] = min(f[u], f[u ^ (1 << j)] - a[j]);
          }
        }
      }
    }
  }
  cout << f[(1 << m) - 1] << endl;
  return 0;
}
