#include <bits/stdc++.h>
using namespace std;
int a[105];
int b[105];
int m;
vector<pair<char, int> > v;
int dp[1 << 21];
int bdp[1 << 21];
int rec(int mask) {
  if (mask == ((1 << m) - 1)) {
    return 0;
  }
  if (bdp[mask] != 0) return dp[mask];
  int x = __builtin_popcount(mask);
  char t = v[x].first;
  int id = v[x].second;
  int ans = -1e9 + 5;
  for (int i = 0; i < m; i++) {
    if (!(mask & (1 << i))) {
      int mask1 = mask;
      mask1 ^= (1 << i);
      if (t == 'p') {
        if (id == 1) {
          ans = max(ans, b[i + 1] + rec(mask1));
        } else {
          ans = max(ans, -(-b[i + 1] + rec(mask1)));
        }
      } else {
        if (id == 1) {
          ans = max(ans, rec(mask1));
        } else
          ans = max(ans, -rec(mask1));
      }
    }
  }
  if (id == 1) {
    dp[mask] = ans;
  } else
    dp[mask] = -ans;
  bdp[mask] = 1;
  return dp[mask];
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  cin >> m;
  for (int i = 1, j = n; i <= m; i++, j--) {
    b[i] = a[j];
  }
  char x;
  int y;
  int m1 = m;
  while (m1--) {
    cin >> x >> y;
    v.push_back(make_pair(x, y));
  }
  memset(bdp, 0, sizeof bdp);
  int ans = rec(0);
  printf("%d\n", ans);
  return 0;
}
