#include <bits/stdc++.h>
using namespace std;
int d[1 << 20], n, m, a[101];
int q[20][2];
int f(int h) {
  if (!h) return 0;
  if (d[h] != 201823598) return d[h];
  int idx = 0;
  for (int i = 0; i < n; i++) {
    if ((h & (1 << i)) == 0) idx++;
  }
  int cur = q[idx][1], t = q[idx][0];
  if (idx == n - 1) {
    for (int i = 0; i < n; i++)
      if (h & (1 << i)) return d[h] = t * a[i];
  }
  int ret = -(1 << 30);
  for (int i = 0; i < n; i++)
    if (h & (1 << i)) {
      if (q[idx + 1][1] == cur) {
        ret = max(ret, a[i] * t + f(h ^ (1 << i)));
      } else {
        ret = max(ret, a[i] * t - f(h ^ (1 << i)));
      }
    }
  return d[h] = ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a + n);
  reverse(a, a + n);
  scanf("%d", &m);
  n = m;
  for (int i = 0; i < m; i++) {
    char c;
    int x;
    scanf(" %c %d", &c, &x);
    if (c == 'p')
      q[i][0] = 1;
    else
      q[i][0] = 0;
    q[i][1] = x - 1;
  }
  for (int i = 0; i < (1 << n); i++) d[i] = 201823598;
  int res = f((1 << n) - 1);
  if (q[0][1] == 1) res = -res;
  printf("%d\n", res);
  return 0;
}
