#include <bits/stdc++.h>
using namespace std;
int n;
int s[200];
int m;
char a[200];
int t[200];
int memcomputa[20][1 << 20];
int calculado[20][1 << 20];
int computa(int indice, int c) {
  if (indice == m) return 0;
  int &mem = memcomputa[indice][c];
  if (calculado[indice][c]) return mem;
  calculado[indice][c] = 1;
  if (a[indice] == 'p') {
    int b = __builtin_ctz(c);
    if (indice + 1 == m or t[indice + 1] == t[indice])
      mem = s[b] + computa(indice + 1, c ^ (1 << b));
    else
      mem = s[b] - computa(indice + 1, c ^ (1 << b));
  } else {
    int cc = c;
    mem = -1000000000;
    if (indice + 1 == m or t[indice + 1] == t[indice]) {
      while (cc) {
        int b = __builtin_ctz(cc);
        cc ^= 1 << b;
        mem = max(mem, computa(indice + 1, c ^ (1 << b)));
      }
    } else {
      while (cc) {
        int b = __builtin_ctz(cc);
        cc ^= 1 << b;
        mem = max(mem, -computa(indice + 1, c ^ (1 << b)));
      }
    }
  }
  return mem;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i];
  sort(s, s + n);
  reverse(s, s + n);
  cin >> m;
  for (int i = 0; i < m; i++) cin >> a[i] >> t[i];
  if (t[0] == 1)
    cout << computa(0, (1 << m) - 1) << endl;
  else
    cout << -computa(0, (1 << m) - 1) << endl;
}
