#include <bits/stdc++.h>
using namespace std;
enum class Action { BAN, PICK };
enum class Player { GOOD, BAD };
const int INF = 1e9;
int rec(const vector<int>& heroes, const vector<pair<Action, Player>>& actions,
        vector<int>& dp, int used, int pos) {
  if (pos >= (int)actions.size()) return 0;
  int& ret = dp[used];
  if (ret != INF) return ret;
  for (int n = 0; n < (int)actions.size(); n++)
    if (!(used & (1 << n))) {
      int cur = rec(heroes, actions, dp, used | (1 << n), pos + 1);
      if (actions[pos].first == Action::PICK)
        cur += (actions[pos].second == Player::GOOD ? 1 : -1) * heroes[n];
      if (ret == INF)
        ret = cur;
      else if (actions[pos].second == Player::GOOD && cur > ret)
        ret = cur;
      else if (actions[pos].second == Player::BAD && cur < ret)
        ret = cur;
      if (actions[pos].first == Action::PICK) break;
    }
  return ret;
}
int main() {
  int num_heroes, num_actions;
  cin >> num_heroes;
  vector<int> heroes(num_heroes);
  for (int n = 0; n < num_heroes; n++) cin >> heroes[n];
  sort(heroes.begin(), heroes.end(), greater<int>());
  cin >> num_actions;
  heroes.resize(min(num_heroes, num_actions));
  vector<pair<Action, Player>> actions(num_actions);
  for (int n = 0; n < num_actions; n++) {
    char action;
    int player;
    cin >> action >> player;
    if (action == 'b')
      actions[n].first = Action::BAN;
    else
      actions[n].first = Action::PICK;
    if (player == 1)
      actions[n].second = Player::GOOD;
    else
      actions[n].second = Player::BAD;
  }
  vector<int> dp(1 << heroes.size(), INF);
  cout << rec(heroes, actions, dp, 0, 0) << endl;
  return 0;
}
