#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100 + 10, MAX_M = 20, UND = ~0U >> 1;
int n, m, s[MAX_N];
char cmd[MAX_M];
int who[MAX_M];
int dp[MAX_M + 1][1 << MAX_M];
bool saved[MAX_M + 1][1 << MAX_M];
void update(int& r, int w, int d) {
  if (r == UND)
    r = d;
  else {
    if (w == 1)
      r = max(r, d);
    else
      r = min(r, d);
  }
}
int calc(int i, int cant) {
  if (i == m) return 0;
  int& ret = dp[i][cant];
  if (saved[i][cant]) return ret;
  saved[i][cant] = true;
  ret = UND;
  if (cmd[i] == 'p') {
    for (int k = 0; k < m; ++k)
      if (~cant >> k & 1) {
        update(ret, who[i],
               (who[i] == 1 ? s[k] : -s[k]) + calc(i + 1, cant ^ (1 << k)));
      }
  } else {
    update(ret, who[i], calc(i + 1, cant));
    for (int k = 0; k < m; ++k)
      if (~cant >> k & 1) {
        update(ret, who[i], +calc(i + 1, cant ^ (1 << k)));
      }
  }
  return ret;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  cin >> m;
  for (int i = 0; i < m; ++i) {
    scanf(" ");
    scanf("%c", &cmd[i]);
    scanf("%d", who + i);
  }
  sort(s, s + n);
  reverse(s, s + n);
  for (int i = 0; i < (1 << m); ++i) {
    dp[m][i] = 0;
  }
  for (int i = m - 1; i >= 0; --i) {
    for (int j = 0; j < (1 << m); ++j) {
      int& ret = dp[i][j] = UND;
      int cant = j;
      if (cmd[i] == 'p') {
        for (int k = 0; k < m; ++k)
          if (~cant >> k & 1) {
            update(ret, who[i],
                   (who[i] == 1 ? s[k] : -s[k]) + dp[i + 1][cant ^ (1 << k)]);
          }
      } else {
        update(ret, who[i], dp[i + 1][cant]);
        for (int k = 0; k < m; ++k)
          if (~cant >> k & 1) {
            update(ret, who[i], dp[i + 1][cant ^ (1 << k)]);
          }
      }
    }
  }
  cout << dp[0][0] << endl;
}
