#include <bits/stdc++.h>
using namespace std;
const int inf = 1000100100;
int n, m;
string s[105];
int team[105];
int dp[21][(1 << 21)];
int a[104];
int solve(int cur, int mask) {
  if (cur == m) return 0;
  int &ret = dp[cur][mask];
  if (ret == inf) {
    if (s[cur] == "p") {
      int j = 0;
      while (j < m && ((mask >> j) & 1)) ++j;
      if (team[cur] == 1)
        ret = solve(cur + 1, mask | (1 << j)) + a[j];
      else
        ret = solve(cur + 1, mask | (1 << j)) - a[j];
    } else {
      ret = solve(cur + 1, mask);
      for (int j = 0; j < m; ++j) {
        if ((mask >> j) & 1) continue;
        if (team[cur] == 1)
          ret = max(ret, solve(cur + 1, mask | (1 << j)));
        else
          ret = min(ret, solve(cur + 1, mask | (1 << j)));
      }
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a, a + n, greater<int>());
  cin >> m;
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> team[i];
  }
  fill(&dp[0][0], &dp[0][0] + (21 * (1 << 21)), inf);
  cout << solve(0, 0);
}
