#include <bits/stdc++.h>
using namespace std;
const int MAXN = 21, INFTY = 0x3f3f3f3f;
int dp[1 << MAXN], v[MAXN], op[MAXN][2], N;
bool comp(int a, int b) { return (a > b); }
int f(int bitmask) {
  if (dp[bitmask] != -INFTY) return dp[bitmask];
  int cur = N - __builtin_popcount(bitmask) + 1;
  if (cur == N + 1) return dp[bitmask] = 0;
  if (op[cur][1] == 1) {
    int ans = -INFTY;
    if (op[cur][0] == 1) {
      for (int i = 0; i < N; i++) {
        if (bitmask & (1 << i)) ans = max(ans, f(bitmask - (1 << i)));
      }
    } else {
      for (int i = 0; i < N; i++) {
        if (bitmask & (1 << i)) ans = max(ans, f(bitmask - (1 << i)) + v[i]);
      }
    }
    dp[bitmask] = ans;
  } else {
    int ans = INFTY;
    if (op[cur][0] == 1) {
      for (int i = 0; i < N; i++) {
        if (bitmask & (1 << i)) ans = min(ans, f(bitmask - (1 << i)));
      }
    } else {
      for (int i = 0; i < N; i++) {
        if (bitmask & (1 << i)) ans = min(ans, f(bitmask - (1 << i)) - v[i]);
      }
    }
    dp[bitmask] = ans;
  }
  return dp[bitmask];
}
int main() {
  int M;
  char x, y;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%d", &v[i]);
  scanf("%d", &M);
  for (int i = 1; i <= M; i++) {
    scanf(" %c %c", &x, &y);
    if (x == 'p')
      op[i][0] = 0;
    else
      op[i][0] = 1;
    op[i][1] = y - '0';
  }
  sort(v, v + N, comp);
  N = M;
  for (int bitmask = 0; bitmask < (1 << N); bitmask++) dp[bitmask] = -INFTY;
  printf("%d\n", f((1 << N) - 1));
  return 0;
}
