#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
int n, m;
int s[MAXN];
int dp[25][1 << 21];
bool used[25][1 << 21];
char type[MAXN];
int tm[MAXN];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &s[i]);
  sort(s, s + n);
  reverse(s, s + n);
  if (n > 20) {
    n = 20;
  }
  scanf("%d\n", &m);
  for (int i = 1; i <= m; i++) scanf("%c %d\n", &type[i], &tm[i]);
  for (int i = m; i >= 1; i--) {
    for (int j = 0; j < (1 << n); j++) {
      if (tm[i] == 1) {
        if (type[i] == 'p') {
          for (int k = 0; k < n; k++) {
            if ((j & (1 << k)) == 0) {
              if (!used[i][j]) {
                dp[i][j] = dp[i + 1][j | (1 << k)] + s[k];
                used[i][j] = true;
              } else {
                if (dp[i + 1][j | (1 << k)] + s[k] > dp[i][j])
                  dp[i][j] = dp[i + 1][j | (1 << k)] + s[k];
              }
            }
          }
        } else {
          for (int k = 0; k < n; k++) {
            if ((j & (1 << k)) == 0) {
              if (!used[i][j]) {
                dp[i][j] = dp[i + 1][j | (1 << k)];
                used[i][j] = true;
              } else {
                if (dp[i + 1][j | (1 << k)] > dp[i][j])
                  dp[i][j] = dp[i + 1][j | (1 << k)];
              }
            }
          }
          if (!used[i][j]) {
            dp[i][j] = dp[i + 1][j];
            used[i][j] = true;
          } else {
            if (dp[i + 1][j] > dp[i][j]) dp[i][j] = dp[i + 1][j];
          }
        }
      } else {
        if (type[i] == 'p') {
          for (int k = 0; k < n; k++) {
            if ((j & (1 << k)) == 0) {
              if (!used[i][j]) {
                dp[i][j] = dp[i + 1][j | (1 << k)] - s[k];
                used[i][j] = true;
              } else {
                if (dp[i + 1][j | (1 << k)] - s[k] < dp[i][j])
                  dp[i][j] = dp[i + 1][j | (1 << k)] - s[k];
              }
            }
          }
        } else {
          for (int k = 0; k < n; k++) {
            if ((j & (1 << k)) == 0) {
              if (!used[i][j]) {
                dp[i][j] = dp[i + 1][j | (1 << k)];
                used[i][j] = true;
              } else {
                if (dp[i + 1][j | (1 << k)] < dp[i][j])
                  dp[i][j] = dp[i + 1][j | (1 << k)];
              }
            }
          }
          if (!used[i][j]) {
            dp[i][j] = dp[i + 1][j];
            used[i][j] = true;
          } else {
            if (dp[i + 1][j] < dp[i][j]) dp[i][j] = dp[i + 1][j];
          }
        }
      }
    }
  }
  printf("%d\n", dp[1][0]);
  return 0;
}
