#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-6;
const int INF = 0x3fffffff;
const long long LINF = INF * 1ll * INF;
const double PI = acos(-1.0);
using namespace std;
int t[25];
int a[105];
char s[25][5];
int dp[20][1 << 20];
int n, m;
int count(int st) {
  int ans = 0;
  while (st) {
    ans += st % 2;
    st >>= 1;
  }
  return ans;
}
int dfs(int hero) {
  int idx = count(hero);
  if (idx == m) return 0;
  if (~dp[idx][hero]) return dp[idx][hero];
  int &ans = dp[idx][hero];
  if (t[idx] == 1)
    ans = -INF;
  else
    ans = INF;
  if (s[idx][0] == 'p') {
    for (int i = 0; i < m; i++) {
      if ((hero & (1 << i)) == 0) {
        if (t[idx] == 1)
          ans = max(ans, dfs(hero | (1 << i)) + a[i]);
        else
          ans = min(ans, dfs(hero | (1 << i)) - a[i]);
      }
    }
  } else {
    if (t[idx] == 1) {
      for (int i = 0; i < m; i++) {
        if ((hero & (1 << i)) == 0) {
          ans = max(ans, dfs(hero | (1 << i)));
        }
      }
    } else {
      for (int i = 0; i < m; i++) {
        if ((hero & (1 << i)) == 0) {
          ans = min(ans, dfs(hero | (1 << i)));
        }
      }
    }
  }
  return ans;
}
int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a + n);
  reverse(a, a + n);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) scanf("%s %d", s[i], &t[i]);
  memset(dp, -1, sizeof(dp));
  printf("%d\n", dfs(0));
}
