#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, m, Q, ans, a[N], p[N], t[N], f[22][1 << 20];
char opr[5];
bool cmp(const int i, const int j) { return i > j; }
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  sort(a, a + n, cmp);
  scanf("%d", &m), n = min(n, m);
  for (int i = 0; i < m; ++i) scanf("%s%d", opr, t + i), p[i] = *opr == 'p';
  for (int i = m - 1; i >= 0; --i) {
    memset(f[i], 200, sizeof(f[i]));
    for (int j = 0; j < 1 << m; ++j)
      for (int k = 0; k < m; ++k)
        if (!(j >> k & 1))
          f[i][j] =
              max(f[i][j], (t[i] == t[i + 1] ? 1 : -1) * f[i + 1][j | 1 << k] +
                               (p[i] ? a[k] : 0));
  }
  ans = f[0][0];
  if (t[0] == 2) ans = -ans;
  printf("%d\n", ans);
  return 0;
}
