#include <bits/stdc++.h>
using namespace std;
const int maxM = 22;
const int INF = maxM * 1001000;
int mem[1 << maxM], plyr[maxM], mark[maxM], n, m;
char act[maxM];
vector<int> s;
int solve(int step) {
  if (step == m) return 0;
  int bitmask = 0, zarib = 1, ans;
  for (int i = 0; i < m; i++)
    if (mark[i]) bitmask |= 1 << i;
  if (mem[bitmask] != INF) return mem[bitmask];
  if (plyr[step] != 1) zarib = -1;
  ans = -zarib * INF;
  if (act[step] == 'p') {
    for (int i = 0; i < m; i++)
      if (!mark[i]) {
        mark[i] = 1;
        ans = solve(step + 1) + zarib * s[i];
        mark[i] = 0;
        return mem[bitmask] = ans;
      }
    cout << "Mkan nadare!!!" << endl;
  }
  for (int i = 0; i < m; i++)
    if (mark[i] == 0)
      if (plyr[step] == 1) {
        mark[i] = 1;
        ans = max(ans, solve(step + 1));
        mark[i] = 0;
      } else {
        mark[i] = 1;
        ans = min(ans, solve(step + 1));
        mark[i] = 0;
      }
  return mem[bitmask] = ans;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    s.push_back(a);
  }
  sort(s.begin(), s.end());
  reverse(s.begin(), s.end());
  cin >> m;
  for (int i = 0; i < m; i++) cin >> act[i] >> plyr[i];
  for (int bitmask = 0; bitmask < (1 << m); bitmask++) mem[bitmask] = INF;
  cout << solve(0) << endl;
}
