#include <bits/stdc++.h>
using namespace std;
bool check(int n, int pos) { return (n & (1 << pos)) >> pos; }
int on(int n, int pos) { return n | (1 << pos); }
const int M = 100010;
int n;
int A[M];
int who[M];
int pick[M];
int dp[(1 << 20) + 10];
bool visited[(1 << 20) + 10];
int call(int mask) {
  if (mask == ((1 << n) - 1)) return 0;
  if (visited[mask]) return dp[mask];
  visited[mask] = true;
  int first = __builtin_popcount(mask);
  if (who[first] == 0) {
    int maxx = -1111111111;
    for (int i = 0; i < n; i++) {
      if (!check(mask, i)) {
        int temp = call(on(mask, i));
        if (pick[first]) temp += A[i];
        maxx = max(maxx, temp);
      }
    }
    return dp[mask] = maxx;
  } else {
    int minn = 1111111111;
    for (int i = 0; i < n; i++) {
      if (!check(mask, i)) {
        int temp = call(on(mask, i));
        if (pick[first]) temp -= A[i];
        minn = min(minn, temp);
      }
    }
    return dp[mask] = minn;
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  int i, j, k, m;
  char a[10];
  scanf("%d", &m);
  for (i = 0; i < m; i++) scanf("%d", &A[i]);
  sort(A, A + m, greater<int>());
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s", a);
    if (a[0] == 'p')
      pick[i] = 1;
    else
      pick[i] = 0;
    scanf("%d", &k);
    who[i] = k - 1;
  }
  memset((visited), (0), sizeof(visited));
  printf("%d\n", call(0));
  return 0;
}
