#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> v;
vector<pair<bool, bool> > a;
int dp[1 << 20][20];
bool visit[1 << 20][20];
int f(int b, int k) {
  if (k >= m) return 0;
  if (visit[b][k]) {
    return dp[b][k];
  }
  int res = (a[k].second ? -1 : 1) * 1e9;
  for (int i = 0; i < m; i++) {
    if (((1 << i) & b) != 0) continue;
    if (a[k].second) {
      res = max(res, f(((1 << i) | b), k + 1) + (a[k].first ? v[i] : 0));
    } else {
      res = min(res, f(((1 << i) | b), k + 1) - (a[k].first ? v[i] : 0));
    }
  }
  visit[b][k] = 1;
  return dp[b][k] = res;
}
int main() {
  int e;
  char c;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> e;
    v.push_back(e);
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> c >> e;
    a.push_back(make_pair(c == 'p', e == 1));
  }
  cout << f(0, 0) << endl;
  return 0;
}
