#include <bits/stdc++.h>
using namespace std;
int n, m, str[102], who[22];
string act[22];
int dp[20][1 << 20];
int get(int move, int ban) {
  if (move == m) return 0;
  if (dp[move][ban] != -1) return dp[move][ban];
  int &res = dp[move][ban];
  if (act[move] == "p") {
    int k = 0;
    for (int i = 0; i < m; i++) {
      if ((ban & (1 << i)) == 0) {
        k = str[i];
        ban = ban | (1 << i);
        break;
      }
    }
    return res = get(move + 1, ban) + (who[move] == 1 ? k : -k);
  }
  if (who[move] == 1)
    res = -1e9;
  else
    res = 1e9;
  for (int i = 0; i < m; i++) {
    if ((ban & (1 << i)) == 0) {
      if (who[move] == 1)
        res = max(res, get(move + 1, ban | (1 << i)));
      else
        res = min(res, get(move + 1, ban | (1 << i)));
    }
  }
  return res;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> str[i];
  sort(str, str + n);
  reverse(str, str + n);
  cin >> m;
  for (int i = 0; i < m; i++) cin >> act[i] >> who[i];
  for (int i = 0; i < 20; i++)
    for (int j = 0; j < (1 << 20); j++) dp[i][j] = -1;
  cout << get(0, 0);
  return 0;
}
