#include <bits/stdc++.h>
using namespace std;
int inf = 1000000000, j, s, mask, tmp, m, q[21], w[21], i, n, a[101],
    dp[1 << 20 + 1];
int cnt(int x) {
  int y = 0;
  while (x > 0) {
    y += (x & 1);
    x = x >> 1;
  }
  return y;
}
int main() {
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  reverse(a, a + n);
  cin >> m;
  for (i = 0; i < m; i++) {
    string s;
    cin >> s >> w[i];
    if (s[0] == 'p')
      q[i] = 1;
    else
      q[i] = 0;
  }
  s = (1 << m) - 1;
  for (mask = s; mask >= 0; mask--) {
    tmp = cnt(mask);
    if (tmp == m) {
      dp[mask] = 0;
      continue;
    }
    if (w[tmp] == 1) {
      dp[mask] = -inf;
      for (j = 0; j < m; j++)
        if ((mask & (1 << j)) == 0)
          dp[mask] = max(dp[mask], dp[mask + (1 << j)] + q[tmp] * a[j]);
    }
    if (w[tmp] == 2) {
      dp[mask] = inf;
      for (j = 0; j < m; j++)
        if ((mask & (1 << j)) == 0)
          dp[mask] = min(dp[mask], dp[mask + (1 << j)] - q[tmp] * a[j]);
    }
  }
  cout << dp[0];
}
