#include <bits/stdc++.h>
using namespace std;
long long int n, m, team[105], a[105], dp[(1 << 20) + 5], vis[(1 << 20) + 5];
char type[105];
long long int solve(long long int mask) {
  if (__builtin_popcount(mask) == m) return 0;
  if (vis[mask]) return dp[mask];
  vis[mask] = 1;
  long long int x = __builtin_popcount(mask);
  long long int best;
  if (team[x] == 1)
    best = -1000000000000000000;
  else
    best = 1000000000000000000;
  for (long long int i = 0; i < m; i++) {
    if (mask & (1 << i)) continue;
    long long int now = solve(mask | (1 << i));
    if (type[x] == 'p') {
      if (team[x] == 1)
        now += a[i];
      else
        now -= a[i];
    }
    if (team[x] == 1)
      best = max(best, now);
    else
      best = min(best, now);
  }
  dp[mask] = best;
  return best;
}
int main() {
  ios::sync_with_stdio(false);
  ;
  cin.tie(0);
  ;
  long long int i, j;
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  reverse(a, a + n);
  cin >> m;
  for (i = 0; i < m; i++) cin >> type[i] >> team[i];
  cout << solve(0);
  return 0;
}
