#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000,100000000000")
using namespace std;
const long long inf = 1e18 + 7;
const long long mod = 1e9 + 7;
const double eps = 1e-12;
const double PI = 2 * acos(0.0);
const double E = 2.71828;
int n, m;
int a[100005];
int res[1 << 20];
bool was[1 << 20];
char t[25];
int team[25];
int go(int cur) {
  if (was[cur]) {
    return res[cur];
  }
  was[cur] = true;
  int v = 0;
  for (long long(i) = 0; (i) < (long long)(m); (i)++) {
    if (cur & (1 << i)) {
      ++v;
    }
  }
  if (v == m) {
    return 0;
  }
  int best;
  if (team[v] == 1) {
    best = -mod;
  } else {
    best = mod;
  }
  for (long long(i) = 0; (i) < (long long)(m); (i)++) {
    if (!(cur & (1 << i))) {
      cur ^= (1 << i);
      if (team[v] == 1) {
        best = max(best, go(cur) + (t[v] == 'p' ? a[i] : 0));
      } else {
        best = min(best, go(cur) - (t[v] == 'p' ? a[i] : 0));
      }
      cur ^= (1 << i);
    }
  }
  return res[cur] = best;
}
int main(void) {
  cin >> n;
  for (long long(i) = 0; (i) < (long long)(n); (i)++) {
    scanf("%d", a + i);
  }
  sort(a, a + n);
  reverse(a, a + n);
  cin >> m;
  for (long long(i) = 0; (i) < (long long)(m); (i)++) {
    cin >> t[i] >> team[i];
  }
  printf("%d\n", go(0));
  return 0;
}
