#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100;
const int M = 20;
const int INF = 1e9;
int n, m;
int S[MAX_N];
bool seen[M + 10][1 << M];
int dp[M + 10][1 << M];
char c[M + 10];
int t[M + 10];
bool checkBetter(int& a, int b, int team) {
  if (team == 1) {
    if (a < b) {
      a = b;
      return true;
    }
    return false;
  }
  if (team == 2) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
  }
  return false;
}
int f(int i, int mask) {
  int& a = dp[i][mask];
  if (seen[i][mask]) return a;
  seen[i][mask] = true;
  if (i == n) return a = 0;
  int sign = (t[i] == 1 ? +1 : -1);
  a = (t[i] == 1 ? -INF : INF);
  int add = ((c[i] == 'p') ? 1 : 0) * sign;
  for (int j = 0; j < n; j++)
    if (!(((mask) >> (j)) & 1))
      checkBetter(a, f(i + 1, mask | (1 << j)) + add * S[j], t[i]);
  if (c[i] == 'b') checkBetter(a, f(i + 1, mask), t[i]);
  return a;
}
int main() {
  ios::sync_with_stdio(0);
  while (cin >> m) {
    for (int i = 0; i < m; i++) cin >> S[i];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> c[i] >> t[i];
    sort(S, S + m);
    reverse(S, S + m);
    for (int i = n - 1; i >= 0; i--) {
      for (int mask = 0; mask < (1 << n); mask++) {
        int& a = dp[i][mask];
        int sign = (t[i] == 1 ? +1 : -1);
        a = (t[i] == 1 ? -INF : INF);
        int add = ((c[i] == 'p') ? 1 : 0) * sign;
        for (int j = 0; j < n; j++)
          if (!(((mask) >> (j)) & 1))
            checkBetter(a, dp[i + 1][mask | (1 << j)] + add * S[j], t[i]);
        if (c[i] == 'b') checkBetter(a, dp[i + 1][mask], t[i]);
      }
    }
    printf("%d\n", dp[0][0]);
  }
  return 0;
}
