#include <bits/stdc++.h>
using namespace std;
const int LOGN = 20;
const int N = (1 << 20);
int memo[LOGN][N], str[N], n, m;
char op[25], team[25];
bool vis[LOGN][N];
int solve(int pos, int ban) {
  if (pos == m) return 0;
  if (vis[pos][ban]) return memo[pos][ban];
  vis[pos][ban] = 1;
  int res = -1e9 + 7;
  for (int i = 0; i < n; i++) {
    if (!((ban >> i) & 1)) {
      int nxt = solve(pos + 1, ban | (1 << i));
      int currStr = (op[pos] == 'p' ? str[i] : 0);
      if (pos + 1 < m && team[pos + 1] != team[pos])
        nxt = currStr - nxt;
      else
        nxt = currStr + nxt;
      res = max(res, nxt);
    }
  }
  return memo[pos][ban] = res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(memo, -1, sizeof(memo));
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> str[i];
  }
  sort(str, str + n, greater<int>());
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> op[i] >> team[i];
  }
  n = m;
  int ans = solve(0, 0);
  if (team[0] == '2') ans *= -1;
  cout << ans << "\n";
  return 0;
}
