#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7f7f7f7f;
int n, m, s[105], dp[(1 << 20) + 5];
int t[(1 << 20) + 5], d[105];
char c[105];
bool cmp(int x, int y) { return x > y; }
signed main() {
  for (int i = 0; i <= 1 << 19; i++) t[i * 2] = t[i], t[i * 2 + 1] = t[i] + 1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
  scanf("%d", &m);
  sort(s + 1, s + n + 1, cmp);
  for (int i = 1; i <= m; i++) scanf("\n%c %d", &c[i], &d[i]);
  for (int i = 1; i < (1 << m); i++) {
    int j = m - t[i] + 1;
    dp[i] = (d[j] == 1) ? -INF : INF;
    for (int k = 1; k <= m; k++)
      if (i & (1 << k - 1)) {
        int tmp = (c[j] == 'p' ? s[k] : 0);
        if (d[j] == 1)
          dp[i] = max(dp[i], dp[i ^ (1 << k - 1)] + tmp);
        else
          dp[i] = min(dp[i], dp[i ^ (1 << k - 1)] - tmp);
      }
  }
  printf("%d", dp[(1 << m) - 1]);
  return 0;
}
