#include <bits/stdc++.h>
using namespace std;
int s[105];
pair<char, int> op[25];
int dp[1 << 20][23];
int m;
int DFS(int state, int p) {
  if (p == m + 1) return dp[state][p] = 0;
  if (dp[state][p] != -1) return dp[state][p];
  if (op[p].first == 'p') {
    int Max = 0;
    int Maxid;
    for (int i = 0; i < m; i++) {
      if (((state >> i) & 1) && s[i] > Max) {
        Max = s[i];
        Maxid = i;
      }
    }
    int nstate = state ^ (1 << Maxid);
    if (op[p].second == 1)
      return dp[state][p] = DFS(nstate, p + 1) + Max;
    else
      return dp[state][p] = DFS(nstate, p + 1) - Max;
  } else {
    if (op[p].second == 1) {
      int Max = -0x7fffffff;
      for (int i = 0; i < m; i++) {
        if ((state >> i) & 1) {
          Max = max(Max, DFS((state ^ (1 << i)), p + 1));
        }
      }
      return dp[state][p] = Max;
    } else {
      int Min = 0x7fffffff;
      for (int i = 0; i < m; i++) {
        if ((state >> i) & 1) {
          Min = min(Min, DFS((state ^ (1 << i)), p + 1));
        }
      }
      return dp[state][p] = Min;
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &s[i]);
  }
  sort(s, s + n);
  reverse(s, s + n);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    char x;
    int num;
    cin >> x >> num;
    op[i] = make_pair(x, num);
  }
  int state = (1 << m) - 1;
  memset(dp, -1, sizeof dp);
  int ans = DFS(state, 1);
  cout << ans << endl;
  return 0;
}
