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