#include <bits/stdc++.h>
using namespace std;
const int MAX = (1 << 20) + 5, INF = 1e9;
int n, m, y[25], a[105], r[105], dp[25][MAX], mk[25][MAX];
char x[25];
vector<int> v;
int f(int i, int mask) {
  if (i == m + 1) return 0;
  if (mk[i][mask]) return dp[i][mask];
  int ans = y[i] == 1 ? -INF : INF;
  for (int j = 0; j < (int)v.size(); j++) {
    if (mask & 1 << j) continue;
    int nmask = mask | (1 << j);
    if (x[i] == 'p') {
      if (y[i] == 1)
        ans = max(ans, f(i + 1, nmask) + v[j]);
      else
        ans = min(ans, f(i + 1, nmask) - v[j]);
    } else {
      if (y[i] == 1)
        ans = max(ans, f(i + 1, nmask));
      else
        ans = min(ans, f(i + 1, nmask));
    }
  }
  mk[i][mask] = 1;
  return dp[i][mask] = ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1, greater<int>());
  scanf("%d", &m);
  for (int i = 1; i <= min(m, n); i++) v.push_back(a[i]);
  for (int i = 1; i <= m; i++) {
    char op;
    int t;
    scanf("\n%c%d", &op, &t);
    x[i] = op;
    y[i] = t;
  }
  printf("%d\n", f(1, 0));
  return 0;
}
