#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int INF = 2e9;
const long long INF64 = 7e18;
const long double EPS = 1e-9;
const long double PI = 3.14159265358979310000;
const long long MD = 535355424;
const long long T = 34539;
const int N = 300101;
const int M = (1 << 20) + 1;
int n, m, a[101];
pair<int, int> d[20][M], z[101];
bool mark[20][M];
pair<int, int> rec(int t, int mask) {
  if (t >= m) return make_pair(0, 0);
  if (mark[t][mask]) return d[t][mask];
  pair<int, int> ans = make_pair(0, INF);
  for (int i = 0; i < int(m); i++)
    if (!(mask & (1 << i))) {
      pair<int, int> v = rec(t + 1, mask + (1 << i));
      int s1 = z[t].first ? a[i] : 0, s2 = 0;
      if (t != m - 1) {
        if (z[t + 1].second == z[t].second) {
          s1 += v.first;
          s2 = v.second;
        } else {
          s1 += v.second;
          s2 = v.first;
        }
      }
      if (s1 - s2 > ans.first - ans.second) ans = make_pair(s1, s2);
    }
  mark[t][mask] = 1;
  d[t][mask] = ans;
  return ans;
}
int main() {
  cin >> n;
  for (int i = 0; i < int(n); i++) scanf("%d", &a[i]);
  sort(a, a + n);
  reverse(a, a + n);
  cin >> m;
  for (int u = 0; u < int(m); u++) {
    string s;
    cin >> s >> z[u].second;
    if (s == "p") z[u].first = 1;
  }
  pair<int, int> v = rec(0, 0);
  int ans;
  if (z[0].second == 1)
    ans = v.first - v.second;
  else
    ans = v.second - v.first;
  cout << ans;
  return 0;
}
