#include <bits/stdc++.h>
using namespace std;
int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }
int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }
const int MAXN = 105;
const int INF = 1e9;
int a[MAXN];
int n, m;
int dp[20][1 << 20];
bool visit[20][1 << 20];
pair<int, int> query[MAXN];
bool bit(int n, int b) { return (n >> b) & 1; }
int rec(int idx, int mask) {
  int &ans = dp[idx][mask];
  if (visit[idx][mask]) return ans;
  visit[idx][mask] = true;
  ans = -INF;
  if (idx == m - 1) {
    ans = 0;
    if (query[idx].first) {
      int j = __builtin_ctz(mask);
      ans = a[j];
    }
    return ans;
  }
  int sign = (query[idx].second == query[idx + 1].second) ? 1 : -1;
  if (query[idx].first) {
    int j = __builtin_ctz(mask);
    ans = a[j] + sign * rec(idx + 1, mask ^ (1 << j));
  } else {
    for (int j = (0); j <= (m - 1); ++j) {
      if (bit(mask, j)) {
        ans = max(ans, sign * rec(idx + 1, mask ^ (1 << j)));
      }
    }
  }
  return ans;
}
void solve() {
  cin >> n;
  for (int i = (0); i <= (n - 1); ++i) cin >> a[i];
  sort(a, a + n);
  reverse(a, a + n);
  cin >> m;
  for (int i = (0); i <= (m - 1); ++i) {
    char c;
    cin >> c;
    query[i].first = (c == 'p');
    cin >> query[i].second;
  }
  int ans = rec(0, (1 << m) - 1);
  if (query[0].second == 2) ans = -ans;
  cout << ans << '\n';
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  for (int i = (1); i <= (t); ++i) {
    solve();
  }
}
