#include <bits/stdc++.h>
using namespace std;
const int inf = 1e8;
int n, m;
int H[20];
int A[20];
int DP[(1 << 20) + 1];
bool ok[(1 << 20) + 1];
int solve(int mask) {
  if (n - __builtin_popcount(mask) == m) return 0;
  if (not ok[mask]) {
    ok[mask] = true;
    int action = A[n - __builtin_popcount(mask)];
    if (action == 0) {
      DP[mask] = -inf;
      for (int i = 0; i <= n; ++i)
        if (mask & (1 << i))
          DP[mask] = max(DP[mask], H[i] + solve(mask & (~(1 << i))));
    } else if (action == 1) {
      DP[mask] = inf;
      for (int i = 0; i <= n; ++i)
        if (mask & (1 << i))
          DP[mask] = min(DP[mask], -H[i] + solve(mask & (~(1 << i))));
    } else if (action == 2) {
      DP[mask] = -inf;
      for (int i = 0; i <= n; ++i)
        if (mask & (1 << i))
          DP[mask] = max(DP[mask], solve(mask & (~(1 << i))));
    } else {
      DP[mask] = inf;
      for (int i = 0; i <= n; ++i)
        if (mask & (1 << i))
          DP[mask] = min(DP[mask], solve(mask & (~(1 << i))));
    }
  }
  return DP[mask];
}
int main() {
  memset(DP, -1, ((1 << 20) + 1) * sizeof(int));
  memset(ok, false, (1 << 20) + 1);
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  sort(v.rbegin(), v.rend());
  for (int i = 0; i < min(n, 20); ++i) H[i] = v[i];
  cin >> m;
  for (int i = 0; i < m; ++i) {
    char act;
    int team;
    cin >> act >> team;
    if (act == 'p')
      A[i] = team == 1 ? 0 : 1;
    else
      A[i] = team == 1 ? 2 : 3;
  }
  n = min(n, 20);
  cout << solve((1 << n) - 1) << endl;
}
