#include <bits/stdc++.h>
using namespace std;
string temp;
long n, m, mv[2000];
long tp[2000];
char ans1[22][1100000];
long ans2[22][1100000];
long cost[2000];
long solve(long a, long b) {
  if (a == m) return 0;
  if (ans1[a][b]) return ans2[a][b];
  ans1[a][b] = 1;
  long qbest;
  if (mv[a] == 1)
    qbest = -1e9;
  else
    qbest = 1e9;
  long tscore;
  for (int i = 0; i < m; i++)
    if ((b & (1 << i)) == 0) {
      tscore = solve(a + 1, b | (1 << i));
      if (tp[a] == 1) {
        if (mv[a] == 1)
          tscore += cost[i];
        else
          tscore -= cost[i];
      }
      if (mv[a] == 1)
        qbest = max(tscore, qbest);
      else
        qbest = min(tscore, qbest);
    }
  ans2[a][b] = qbest;
  return qbest;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> cost[i];
  sort(cost, cost + n);
  reverse(cost, cost + n);
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> temp;
    if (temp == "p")
      tp[i] = 1;
    else
      tp[i] = 2;
    cin >> mv[i];
  }
  cout << solve(0, 0) << endl;
  cin.get();
  cin.get();
  return 0;
}
