#include <bits/stdc++.h>
using namespace std;
int dp[21][1100000];
int n, m;
int a[105];
char ord1[25];
int ord2[25];
void DP(int i, int j) {
  if (i == m) {
    dp[i][j] = 0;
    return;
  }
  if (ord1[i] == 'p') {
    int cal;
    if (ord2[i] == 1)
      cal = 1;
    else
      cal = -1;
    for (int k = m - 1; k >= 0; k--)
      if (((1 << k) & j) == 0) {
        if (dp[i + 1][j | (1 << k)] == 500000000) DP(i + 1, j | (1 << k));
        dp[i][j] = dp[i + 1][j | (1 << k)] + cal * a[n - m + k];
        break;
      }
    return;
  }
  if (dp[i + 1][j] == 500000000) DP(i + 1, j);
  dp[i][j] = dp[i + 1][j];
  for (int k = m - 1; k >= 0; k--)
    if (((1 << k) & j) == 0) {
      if (dp[i + 1][j | (1 << k)] == 500000000) DP(i + 1, j | (1 << k));
      if (ord2[i] == 1)
        dp[i][j] = max(dp[i][j], dp[i + 1][j | (1 << k)]);
      else
        dp[i][j] = min(dp[i][j], dp[i + 1][j | (1 << k)]);
    }
  return;
}
int main() {
  while (scanf("%d", &n) != EOF) {
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    sort(a, a + n);
    scanf("%d", &m);
    for (int i = 0; i < m; i++) scanf(" %c %d", &ord1[i], &ord2[i]);
    for (int i = 0; i < m; i++)
      for (int j = 0; j < (1 << m); j++) dp[i][j] = 500000000;
    DP(0, 0);
    printf("%d\n", dp[0][0]);
  }
  return 0;
}
