#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
int s[maxn];
int dp[1 << 21];
int op[25], a[25];
int gett(int x) {
  int res = 0;
  for (; x; res++) x &= x - 1;
  return res;
}
int count(int x) { return x == 0 ? 0 : (x & 1) + count(x >> 1); }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &s[i]);
  }
  sort(s + 1, s + 1 + n);
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    char ch;
    scanf("\n%c%d", &ch, &a[i]);
    op[i] = (ch == 'p');
  }
  dp[(1 << m) - 1] = 0;
  for (int i = (1 << m) - 2; i >= 0; i--) {
    int num = count(i);
    if (a[num] == 1) {
      dp[i] = -0x3f3f3f3f;
      for (int j = 0; j < m; j++) {
        if ((i & (1 << j)) == 0)
          dp[i] = max(dp[i], dp[i | (1 << j)] + op[num] * s[n - j]);
      }
    } else {
      dp[i] = 0x3f3f3f3f;
      for (int j = 0; j < m; j++) {
        if ((i & (1 << j)) == 0)
          dp[i] = min(dp[i], dp[i | (1 << j)] - op[num] * s[n - j]);
      }
    }
  }
  printf("%d\n", dp[0]);
  return 0;
}
