#include <bits/stdc++.h>
const double PI = acos(-1);
using namespace std;
int m;
int a[101];
char c[101];
int b[101];
int dp[(1 << 20) + 5];
int f(int x, int i) {
  if (i == m) {
    return 0;
  }
  if (dp[x] != -1) return dp[x];
  int r = -2e9;
  if (b[i] == 2) {
    r = 2e9;
  }
  for (int j = 0; j < m; j++) {
    if (!((1 << j) & x)) {
      if (b[i] == 1) {
        int r1 = f(x | (1 << j), i + 1);
        if (c[i] == 'p') r1 += a[j];
        r = max(r, r1);
      } else {
        int r1 = f(x | (1 << j), i + 1);
        if (c[i] == 'p') r1 -= a[j];
        r = min(r, r1);
      }
    }
  }
  return dp[x] = r;
}
int main() {
  memset(dp, -1, sizeof(dp));
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  reverse(a, a + n);
  cin >> m;
  for (int j = 0; j < m; j++) {
    cin >> c[j] >> b[j];
  }
  cout << f(0, 0);
  return 0;
}
