#include <bits/stdc++.h>
using namespace std;
const int inf = 200000000;
int f[25][1200000], g[120], h[120];
char c[120];
int i, j, k, m, n;
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &g[i]);
  sort(g + 1, g + n + 1);
  scanf("%d", &m);
  for (i = 1; i <= m; i++) {
    getchar(), c[i] = getchar();
    scanf("%d", &h[i]);
  }
  for (i = m; i > 0; i--) {
    if (h[i] == 1) {
      for (j = 0; j < (1 << m) - 1; j++) f[i][j] = -inf;
      for (j = 0; j < (1 << m) - 1; j++)
        if (c[i] == 'p') {
          for (k = 0; k < m; k++)
            if (!(j & (1 << k)))
              f[i][j] = max(f[i][j], f[i + 1][j | (1 << k)] + g[n - k]);
        } else {
          f[i][j] = max(f[i][j], f[i + 1][j]);
          for (k = 0; k < m; k++)
            if (!(j & (1 << k))) f[i][j] = max(f[i][j], f[i + 1][j | (1 << k)]);
        }
    } else {
      for (j = 0; j < (1 << m) - 1; j++) f[i][j] = inf;
      for (j = 0; j < (1 << m) - 1; j++)
        if (c[i] == 'p') {
          for (k = 0; k < m; k++)
            if (!(j & (1 << k)))
              f[i][j] = min(f[i][j], f[i + 1][j | (1 << k)] - g[n - k]);
        } else {
          f[i][j] = min(f[i][j], f[i + 1][j]);
          for (k = 0; k < m; k++)
            if (!(j & (1 << k))) f[i][j] = min(f[i][j], f[i + 1][j | (1 << k)]);
        }
    }
  }
  printf("%d", f[1][0]);
  return 0;
}
