#include <bits/stdc++.h>
using namespace std;
const int inf = ~0U >> 1;
const long long INF = ~0ULL >> 1;
template <class T>
inline void read(T &n) {
  char c;
  for (c = getchar(); !(c >= '0' && c <= '9'); c = getchar())
    ;
  n = c - '0';
  for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) n = n * 10 + c - '0';
}
int Pow(int base, int n, int mo) {
  if (n == 0) return 1;
  if (n == 1) return base % mo;
  int tmp = Pow(base, n >> 1, mo);
  tmp = (long long)tmp * tmp % mo;
  if (n & 1) tmp = (long long)tmp * base % mo;
  return tmp;
}
int n, m, a[200], team[200], dp[22][(1 << 20) + 10];
char ty[200];
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1, greater<int>());
  if (n > 20) n = 20;
  scanf("%d", &m);
  for (int i = (1); i <= (m); ++i) cin >> ty[i] >> team[i];
  for (int i = (m); i >= (1); --i)
    for (int j = (0); j <= ((1 << n) - 1); ++j) {
      dp[i][j] = -inf;
      if (ty[i] == 'p') {
        for (int k = (1); k <= (n); ++k)
          if (!((1 << k - 1) & j))
            dp[i][j] = max(dp[i][j], ((team[i + 1] == team[i]) ? 1 : -1) *
                                             (dp[i + 1][j | (1 << k - 1)]) +
                                         a[k]);
      } else {
        for (int k = (1); k <= (n); ++k)
          if (!((1 << k - 1) & j))
            dp[i][j] = max(dp[i][j], ((team[i + 1] == team[i]) ? 1 : -1) *
                                         dp[i + 1][j | (1 << k - 1)]);
      }
    }
  if (team[1] == 1)
    printf("%d\n", dp[1][0]);
  else
    printf("%d\n", -dp[1][0]);
  return 0;
}
