#include <bits/stdc++.h>
using namespace std;
inline bool iseq(double x, double y) {
  if (fabs(x - y) < 1e-8) return true;
  return false;
}
template <typename T>
inline T hpt(T x1, T y1, T x2, T y2) {
  return hypot(x1 - x2, y1 - y2);
}
template <typename T>
inline T gcd(T a, T b) {
  if (!b)
    return a;
  else
    return gcd(b, a % b);
}
template <typename T>
inline void extended_euclid(T a, T b, T &x, T &y) {
  if (a % b == 0)
    x = 0, y = 1;
  else {
    extended_euclid(b, a % b, x, y);
    T temp = x;
    x = y;
    y = -y * (a / b) + temp;
  }
}
template <typename T>
inline T bigmod(T b, T p, T m) {
  if (!p)
    return 1;
  else if (!(p % 2)) {
    T x = bigmod(b, p / 2, m);
    return (x * x) % m;
  } else
    return ((b % m) * bigmod(b, p - 1, m)) % m;
}
int prime[5 / 32 + 1];
void setbit(int i) {
  int p = i >> 5, q = i & 31;
  prime[p] |= (1 << q);
}
bool checkbit(int i) {
  int p = i >> 5, q = i & 31;
  return prime[p] & (1 << q) ? true : false;
}
void buildprime(int n) {
  int i, j, k = sqrt(double(n));
  prime[0] = 3;
  for (i = 4; i < n; i += 2) setbit(i);
  for (i = 3; i <= k; i += 2) {
    if (!checkbit(i)) {
      int ii = i + i;
      for (j = i * i; j < n; j += ii) setbit(j);
    }
  }
}
int sum, r, n, N, R, C, m;
int power[105], player[25], dp[20][1 << 20];
bool nisi[20][1 << 20];
string cmd[25];
int doit(int p, int bit) {
  if (m <= p) return 0;
  int &ret = dp[p][bit];
  if (nisi[p][bit]) return ret;
  nisi[p][bit] = true;
  if (cmd[p] == "p") {
    for (int i = 0; i < m; ++i)
      if ((bit & (1 << i)) == 0) {
        ret = doit(p + 1, bit | (1 << i));
        if (player[p] == 1)
          ret += power[i];
        else
          ret -= power[i];
        break;
      }
    return ret;
  }
  if (player[p] == 1)
    ret = -(1 << 30);
  else
    ret = (1 << 30);
  for (int i = 0; i < m; ++i)
    if ((bit & (1 << i)) == 0) {
      int tem = doit(p + 1, bit | (1 << i));
      if (player[p] == 1)
        ret = max(ret, tem);
      else
        ret = min(ret, tem);
    }
  return ret;
}
int main() {
  int i, j, k;
  while (scanf("%d", &n) == 1) {
    for ((i) = (0); (i) < (n); (i)++) scanf("%d", &power[i]);
    sort(power, power + n);
    reverse(power, power + n);
    scanf("%d", &m);
    for ((i) = (0); (i) < (m); (i)++) cin >> cmd[i] >> player[i];
    memset(nisi, 0, sizeof(nisi));
    int ans = doit(0, 0);
    cout << ans << endl;
  }
  return 0;
}
