#include <bits/stdc++.h>
using namespace std;
bool debug = 1;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long ln, lk, lm;
int dp[1 << 20], s[105], t[105];
string ac[105];
int main() {
  scanf("%d", &n);
  for (int(i) = 0; (i) < (int)(n); (i)++) scanf("%d", s + i);
  sort(s, s + n);
  reverse(s, s + n);
  scanf("%d", &m);
  for (int(i) = 0; (i) < (int)(m); (i)++) cin >> ac[i] >> t[i];
  for (int i = 1; i < (1 << m); i++) {
    int id = m - __builtin_popcount(i);
    dp[i] = t[id] == 1 ? -(1e8) : ((1e8));
    for (int j = 0; j < m; j++) {
      if ((1 << j) & i) {
        if (t[id] == 1) {
          dp[i] = max(dp[i], (ac[id] == "p" ? s[j] : 0) + dp[i - (1 << j)]);
        } else {
          dp[i] = min(dp[i], (ac[id] == "p" ? -s[j] : 0) + dp[i - (1 << j)]);
        }
      }
    }
  }
  cout << dp[(1 << m) - 1] << endl;
  return 0;
}
