#include <bits/stdc++.h>
using namespace std;
int n, s[105], m, team[25], dp[25][1 << 20];
char type[25];
bool vis[25][1 << 20];
bool cmp(int x, int y) { return x > y; }
int dfs(int Index, int now) {
  if (vis[Index][now]) return dp[Index][now];
  vis[Index][now] = 1;
  dp[Index][now] = -0x3f3f3f3f;
  if (type[Index] == 'p') {
    for (int i = 1; i <= m; i++) {
      if (!((1 << i - 1) & now)) {
        if (Index == m)
          dp[Index][now] = max(dp[Index][now], s[i]);
        else if (team[Index] == team[Index + 1])
          dp[Index][now] =
              max(dp[Index][now], s[i] + dfs(Index + 1, now | (1 << i - 1)));
        else
          dp[Index][now] =
              max(dp[Index][now], s[i] - dfs(Index + 1, now | (1 << i - 1)));
      }
    }
  } else {
    for (int i = 1; i <= m; i++) {
      if (!((1 << i - 1) & now)) {
        if (Index == m)
          dp[Index][now] = max(dp[Index][now], 0);
        else if (team[Index] == team[Index + 1])
          dp[Index][now] =
              max(dp[Index][now], dfs(Index + 1, now | (1 << i - 1)));
        else
          dp[Index][now] =
              max(dp[Index][now], -dfs(Index + 1, now | (1 << i - 1)));
      }
    }
  }
  return dp[Index][now];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) scanf("\n%c %d", &type[i], &team[i]);
  sort(s + 1, s + 1 + n, cmp);
  printf("%d\n", (team[1] == 1 ? 1 : -1) * dfs(1, 0));
  return 0;
}
