#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int maxn = 1e2 + 5;
int s[maxn], dp1[(1 << 20) + 5], dp2[(1 << 20) + 5], team[21];
char act[21];
int n, m, ans, ninf;
pii dfs(int x, int dep) {
  if (dep == m + 1) return pii(0, 0);
  if (dp1[x] != ninf) return pii(dp1[x], dp2[x]);
  for (int i = 0; i < m; ++i) {
    if (x & (1 << i)) continue;
    int nx = x | (1 << i);
    pii nv = dfs(nx, dep + 1);
    if (act[dep] == 'p') {
      if (team[dep] == 1)
        nv.first += s[i];
      else
        nv.second += s[i];
    }
    if (dp1[x] == ninf)
      dp1[x] = nv.first, dp2[x] = nv.second;
    else if (team[dep] == 1) {
      if (dp1[x] - dp2[x] < nv.first - nv.second)
        dp1[x] = nv.first, dp2[x] = nv.second;
    } else {
      if (dp1[x] - dp2[x] > nv.first - nv.second)
        dp1[x] = nv.first, dp2[x] = nv.second;
    }
  }
  return pii(dp1[x], dp2[x]);
}
int main() {
  memset(dp1, 0x80, sizeof(dp1));
  memset(dp2, 0x80, sizeof(dp2));
  ans = ninf = dp1[0];
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  sort(s, s + n, greater<int>());
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> act[i] >> team[i];
  }
  pii v0 = dfs(0, 1);
  ans = v0.first - v0.second;
  cout << ans << endl;
}
