#include <bits/stdc++.h>
using namespace std;
int n;
int a[105];
int dp[1 << 21];
char c[22];
int t[22];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  sort(a, a + n);
  reverse(a, a + n);
  int ptr = 0;
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) scanf(" %c %d", &c[i], &t[i]);
  n = q;
  for (int i = 1; i < (1 << n); i++) {
    int turn = n - __builtin_popcount(i);
    dp[i] = (!(t[turn] - 1) ? -1e8 : 1e8);
    for (int j = 0; j < n; j++)
      if (i & (1 << j))
        if (!(t[turn] - 1))
          dp[i] = max(dp[i], (c[turn] == 'p' ? a[j] : 0) + dp[i ^ (1 << j)]);
        else
          dp[i] = min(dp[i], (c[turn] == 'p' ? -a[j] : 0) + dp[i ^ (1 << j)]);
  }
  printf("%d\n", dp[(1 << n) - 1]);
  return 0;
}
