#include <bits/stdc++.h>
using namespace std;
vector<int> A;
string op[25];
int player[25];
int memo[21][1 << 21];
bool done[21][1 << 21];
int n;
int dp(int pos, int mask) {
  if (pos == n) return 0;
  int &dev = memo[pos][mask];
  if (!done[pos][mask]) {
    done[pos][mask] = 1;
    if (player[pos] == 2)
      dev = 1000000000;
    else
      dev = -1000000000;
    if (op[pos] == "p") {
      if (player[pos] == 2) {
        for (int i = 0; i < n; ++i)
          if (mask & (1 << i))
            dev = min(dev, -A[i] + dp(pos + 1, mask ^ (1 << i)));
      } else {
        for (int i = 0; i < n; ++i)
          if (mask & (1 << i))
            dev = max(dev, A[i] + dp(pos + 1, mask ^ (1 << i)));
      }
    } else {
      if (player[pos] == 2) {
        for (int i = 0; i < n; ++i)
          if (mask & (1 << i)) dev = min(dev, dp(pos + 1, mask ^ (1 << i)));
      } else {
        for (int i = 0; i < n; ++i)
          if (mask & (1 << i)) dev = max(dev, dp(pos + 1, mask ^ (1 << i)));
      }
    }
  }
  return dev;
}
int main() {
  int m;
  while (cin >> m) {
    A.resize(m);
    for (int i = 0; i < m; ++i) cin >> A[i];
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> op[i] >> player[i];
    memset(done, 0, sizeof(done));
    printf("%d\n", dp(0, (1 << n) - 1));
  }
}
