#include <bits/stdc++.h>
using namespace std;
int n, m, a[105], t[25], op[25], dp[1 << 20];
char ch;
inline int Count(int x) { return x == 0 ? 0 : (x & 1) + Count(x >> 1); }
int main() {
  scanf("%d", &n);
  for (register int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + 1 + n);
  scanf("%d", &m);
  for (register int i = 0; i < m; i++) {
    scanf("\n%c %d", &ch, &t[i]);
    op[i] = (ch == 'p');
  }
  dp[(1 << m) - 1] = 0;
  for (register int i = (1 << m) - 2; i >= 0; i--) {
    int cur = Count(i);
    if (t[cur] == 1) {
      dp[i] = -1000000005;
      for (register int j = 0; j < m; j++) {
        if ((i & (1 << j)) == 0) {
          dp[i] = max(dp[i], dp[i | (1 << j)] + op[cur] * a[n - j]);
        }
      }
    } else {
      dp[i] = 1000000005;
      for (register int j = 0; j < m; j++) {
        if ((i & (1 << j)) == 0) {
          dp[i] = min(dp[i], dp[i | (1 << j)] - op[cur] * a[n - j]);
        }
      }
    }
  }
  printf("%d\n", dp[0]);
  return 0;
}
