#include <bits/stdc++.h>
using namespace std;
int countbit(int a) {
  int i = 0;
  while (a != 0) {
    if (a & 1) i++;
    a /= 2;
  }
  return i;
}
int dp[1100000] = {0};
int main() {
  int a[150];
  int arr[150], arr1[150] = {0};
  int n, m;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < n / 2; i++) swap(a[i], a[n - 1 - i]);
  cin >> m;
  for (int i = m; i > 0; i--) {
    char s[50];
    int x;
    cin >> s >> x;
    if (s[0] == 'p') {
      arr1[i] = 1;
    }
    if (x == 1)
      arr[i] = 1;
    else
      arr[i] = -1;
  }
  dp[0] = 0;
  for (int i = 1; i < (1 << m); i++) {
    int z = countbit(i);
    if (arr[z] > 0) {
      dp[i] = -1 * 0x3f3f3f3f;
      for (int j = 0; j < m; j++) {
        if (i & (1 << j)) {
          dp[i] = max(dp[i], dp[i ^ (1 << j)] + arr1[z] * a[j]);
        }
      }
    } else {
      dp[i] = 0x3f3f3f3f;
      for (int j = 0; j < m; j++) {
        if (i & (1 << j)) {
          dp[i] = min(dp[i], dp[i ^ (1 << j)] - arr1[z] * a[j]);
        }
      }
    }
  }
  cout << dp[(1 << m) - 1];
  return 0;
}
