#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read1() {
  T t = 0;
  char k = getchar();
  bool flag = 0;
  while ('0' > k || k > '9') {
    if (k == '-') flag = 1;
    k = getchar();
  }
  while ('0' <= k && k <= '9')
    t = (t << 3) + (t << 1) + (k ^ 48), k = getchar();
  return flag ? -t : t;
}
int Max(int a, int b) { return a > b ? a : b; }
int Min(int a, int b) { return a < b ? a : b; }
int s, a[105], m, t[1048577], w[22], o[3] = {0, -(1 << 30), 1 << 30},
                                     dp[1048577];
char str[22];
int (*x[3])(int, int) = {NULL, Max, Min};
int main() {
  s = read1<long long>();
  for (int i = 1; i <= s; ++i) a[i] = read1<long long>();
  m = read1<long long>();
  sort(a + 1, a + s + 1);
  reverse(a + 1, a + s + 1);
  for (int i = 1; i <= m; ++i) cin >> str[i] >> w[i];
  for (int i = 1; i < (1 << m); ++i) {
    t[i] = t[i & i - 1] + 1;
    int te = m - t[i] + 1;
    dp[i] = o[w[te]];
    int l = str[te] == 'b' ? 0 : w[te] & 1 ? 1 : -1;
    for (int j = 0; j < m; ++j)
      if ((1 << j) & i)
        dp[i] = x[w[te]](dp[i], dp[i ^ (1 << j)] + l * a[j + 1]);
  }
  printf("%d", dp[(1 << m) - 1]);
  return 0;
}
