#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[105], b[105];
char op[105][5];
int dp[22][(1 << 20) + 5];
char vis[22][(1 << 20) + 5];
inline int dfs(int x, int B) {
  if (vis[x][B]) return dp[x][B];
  if (x == m) return 0;
  vis[x][B] = 1;
  dp[x][B] = -(1 << 30);
  int sgn = (b[x + 1] == b[x] ? 1 : -1);
  if (op[x][0] == 'b') {
    for (int i = (0); i < (m); i++)
      dp[x][B] = max(dp[x][B], dfs(x + 1, B | (1 << i)) * sgn);
  } else {
    for (int i = (0); i < (m); i++)
      if ((B & (1 << i)) == 0) {
        dp[x][B] = max(dp[x][B], a[i] + dfs(x + 1, B | (1 << i)) * sgn);
        break;
      }
  }
  return dp[x][B];
}
int main() {
  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", op[i], &b[i]);
  if (b[0] == 1)
    printf("%d\n", dfs(0, 0));
  else
    printf("%d\n", -dfs(0, 0));
  return 0;
}
