#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30);
int dp[1 << 21][21];
int a[111];
int n, m;
char ch[22];
int who[22];
int gao(int s, int p) {
  int& t = dp[s][p];
  if (t != -inf) return t;
  if (p == m) return t = 0;
  int v = 0;
  for (int i = 0; i < m; i++)
    if ((1 << i) & s) {
      int ns = s ^ (1 << i);
      if (ch[p] == 'p') v = a[i];
      if (who[p + 1] == who[p])
        t = max(t, v + gao(ns, p + 1));
      else
        t = max(t, v - gao(ns, p + 1));
    }
  return t;
}
int main() {
  while (cin >> n) {
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a, a + n);
    reverse(a, a + n);
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> ch[i] >> who[i];
    }
    fill(dp[0], dp[1 << 21], -inf);
    int t = gao((1 << m) - 1, 0);
    if (who[0] == 2) t *= -1;
    cout << t << endl;
  }
  return 0;
}
