#include <bits/stdc++.h>
using namespace std;
int s[111], team[21], dp[1 << 20];
char mv[21];
int main() {
  int n, m;
  scanf("%d", &n);
  for (int i = 0; i < int(n); i++) scanf("%d", s + i);
  sort(s, s + n);
  reverse(s, s + n);
  scanf("%d ", &m);
  for (int i = 0; i < int(m); i++) scanf("%c %d ", mv + i, team + i);
  int S = 1 << (n = m);
  dp[0] = 0;
  for (int st = 1; st < S; st++) {
    dp[st] = -1e9;
    int j = n - __builtin_popcount(st);
    for (int i = 0; i < int(n); i++)
      if (st & (1 << i)) {
        int tmp = (team[j + 1] == team[j] ? 1 : -1) * dp[(1 << i) ^ st];
        if (mv[j] == 'p') tmp += s[i];
        dp[st] = max(dp[st], tmp);
      }
  }
  printf("%d\n", team[0] == 2 ? -dp[S - 1] : dp[S - 1]);
}
