#include <bits/stdc++.h>
using namespace std;
int strength[110];
int m, n;
char action_type[20];
int action_team[20];
int dp[1 << 21] = {0};
int max_diff(unsigned int bit, int round) {
  if (round == m) {
    return 0;
  }
  if (dp[bit] != (25 * 1000000)) {
    return dp[bit];
  }
  if (action_type[round] == 'p') {
    int best = (action_team[round] == 1) ? -(25 * 1000000) : (25 * 1000000);
    for (int i = 0; i < m; i++) {
      if (!(bit & (1 << i))) {
        if (action_team[round] == 1) {
          return dp[bit] = strength[i] + max_diff(bit | (1 << i), round + 1);
        } else {
          return dp[bit] = -strength[i] + max_diff(bit | (1 << i), round + 1);
        }
      }
    }
    return dp[bit] = best;
  } else if (action_type[round] == 'b') {
    int best = (action_team[round] == 1) ? -(25 * 1000000) : (25 * 1000000);
    for (int i = 0; i < m; i++) {
      if (!(bit & (1 << i))) {
        if (action_team[round] == 1) {
          best = max(best, max_diff(bit | (1 << i), round + 1));
        } else {
          best = min(best, max_diff(bit | (1 << i), round + 1));
        }
      }
    }
    return dp[bit] = best;
  } else {
    cout << "fel";
  }
  return (25 * 1000000);
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> strength[i];
  }
  sort(strength, strength + n);
  reverse(strength, strength + n);
  cin >> m;
  for (int i = 0; i < (1 << (m + 1)); i++) {
    dp[i] = (25 * 1000000);
  }
  for (int i = 0; i < m; i++) {
    string s;
    cin >> s >> action_team[i];
    action_type[i] = s[0];
  }
  cout << max_diff(0u, 0);
  return 0;
}
