#include <bits/stdc++.h>
using namespace std;
int n, i, j, p, m, s[110], a[110], b[110], dp[22][1 << 20];
bool ok(int x) { return -20000000 <= x && x <= 20000000; }
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &s[i]);
  sort(s + 1, s + n + 1);
  scanf("%d", &m);
  for (i = 0; i < m; i++) s[i] = s[n - m + 1 + i];
  for (i = 1; i <= m; i++) {
    for (a[i] = getchar(); a[i] <= 32; a[i] = getchar())
      ;
    scanf("%d", &b[i]);
  }
  for (i = 0; i < (1 << m); i++) dp[m + 1][i] = 2000000000;
  dp[m + 1][0] = 0;
  for (i = m; i; i--) {
    if (b[i] == 1) {
      for (j = 0; j < (1 << m); j++) dp[i][j] = -2000000000;
      if (a[i] == 'p') {
        for (j = 0; j < (1 << m); j++)
          for (p = 0; p < m; p++)
            if (ok(dp[i + 1][j]) && !((1 << p) & j))
              dp[i][j + (1 << p)] =
                  max(dp[i][j + (1 << p)], dp[i + 1][j] + s[p]);
      } else {
        for (j = 0; j < (1 << m); j++)
          for (p = 0; p < m; p++)
            if (ok(dp[i + 1][j]) && !((1 << p) & j))
              dp[i][j + (1 << p)] = max(dp[i][j + (1 << p)], dp[i + 1][j]);
      }
    } else {
      for (j = 0; j < (1 << m); j++) dp[i][j] = 2000000000;
      if (a[i] == 'p') {
        for (j = 0; j < (1 << m); j++)
          for (p = 0; p < m; p++)
            if (ok(dp[i + 1][j]) && !((1 << p) & j))
              dp[i][j + (1 << p)] =
                  min(dp[i][j + (1 << p)], dp[i + 1][j] - s[p]);
      } else {
        for (j = 0; j < (1 << m); j++)
          for (p = 0; p < m; p++)
            if (ok(dp[i + 1][j]) && !((1 << p) & j))
              dp[i][j + (1 << p)] = min(dp[i][j + (1 << p)], dp[i + 1][j]);
      }
    }
  }
  printf("%d\n", dp[1][(1 << m) - 1]);
}
