#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e2 + 5;
const double eps = 1e-9;
using namespace std;
int a[MAXN];
pair<int, int> vis[21][1 << 20];
pair<int, int> b[MAXN];
char x;
int t;
pair<int, int> dfs(int m, int mask, int d) {
  if (d == m) return {0, 0};
  if (vis[d][mask].first != -1) return vis[d][mask];
  if (b[d].first == 0)
    for (int i = m - 1; i >= 0; i--)
      if (mask & (1 << i)) {
        pair<int, int> nx = dfs(m, mask ^ (1 << i), d + 1);
        if (b[d].second == 1)
          nx.first += a[i];
        else
          nx.second += a[i];
        return vis[d][mask] = nx;
      }
  pair<int, int> ret = dfs(m, mask, d + 1);
  for (int i = m - 1; i >= 0; i--) {
    if (mask & (1 << i)) {
      pair<int, int> nx = dfs(m, mask ^ (1 << i), d + 1);
      if (b[d].second == 1 && ret.first - ret.second < nx.first - nx.second)
        ret = nx;
      else if (b[d].second == 2 &&
               ret.second - ret.first < nx.second - nx.first)
        ret = nx;
    }
  }
  return vis[d][mask] = ret;
}
int main() {
  for (int i = 0; i < (1 << 20); i++)
    for (int j = 0; j < 21; j++) vis[j][i] = {-1, -1};
  int n, m;
  scanf("%d", &n);
  for (int i = 0; i < (n); i++) scanf("%d", &(a)[i]);
  scanf("%d", &m);
  sort(a, a + n);
  reverse(a, a + n);
  reverse(a, a + m);
  int cnt = 0, tmp = 0;
  for (int i = 0; i < m; i++) {
    scanf(" %c %d", &x, &t);
    if (x == 'b')
      b[i] = {1, t};
    else
      b[i] = {0, t};
  }
  pair<int, int> ans = dfs(m, (1 << m) - 1, 0);
  printf("%d\n", ans.first - ans.second);
  return 0;
}
