#include <bits/stdc++.h>
using namespace std;
const int N = int(2e6);
const int inf = int(1e9);
int n, m;
int a[200], b[200];
char second[200];
int dp[N];
bool was[N];
int rec(int v, int mask) {
  if (v > n) return 0;
  if (was[mask]) return dp[mask];
  was[mask] = 1;
  if (b[v] == 1) {
    int res = -inf;
    for (int i = 0; i < n; i++) {
      if (!(mask & (1 << i))) {
        int nmask = (mask | (1 << i));
        res = max(res, (second[v] == 'p') * a[i] + rec(v + 1, nmask));
      }
    }
    return dp[mask] = res;
  }
  int res = inf;
  for (int i = 0; i < n; i++) {
    if (!(mask & (1 << i))) {
      int nmask = (mask | (1 << i));
      res = min(res, rec(v + 1, nmask) - (second[v] == 'p') * a[i]);
    }
  }
  return dp[mask] = res;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  reverse(a, a + n);
  cin >> m;
  n = m;
  for (int i = 1; i <= n; i++) {
    cin >> second[i] >> b[i];
  }
  cout << rec(1, 0);
  return 0;
}
