#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  char f = 1, ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(long long x) {
  write(x);
  puts("");
}
const int N = 12344;
int a[N], n, num[N], m, f[21][1 << 21];
char op[N][5];
bool vis[21][1 << 21];
bool cmp(int x, int y) { return x > y; }
int dfs(int cur, int st) {
  if (vis[cur][st]) return f[cur][st];
  vis[cur][st] = 1;
  int &res = f[cur][st] = -1e9;
  if (op[cur][0] == 'p') {
    for (int i = 0; i < m; ++i)
      if (!(st & 1 << i)) {
        if (cur == m)
          res = max(res, a[i + 1]);
        else if (num[cur] == num[cur + 1])
          res = max(res, a[i + 1] + dfs(cur + 1, st | 1 << i));
        else
          res = max(res, a[i + 1] - dfs(cur + 1, st | 1 << i));
      }
  } else {
    for (int i = 0; i < m; ++i)
      if (!(st & 1 << i)) {
        if (cur == m)
          res = 0;
        else if (num[cur] == num[cur + 1])
          res = max(res, dfs(cur + 1, st | 1 << i));
        else
          res = max(res, -dfs(cur + 1, st | 1 << i));
      }
  }
  return res;
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  m = read();
  for (int i = 1; i <= m; ++i) cin >> op[i] >> num[i];
  sort(a + 1, a + 1 + n, cmp);
  int ans = dfs(1, 0);
  if (num[1] == 2) ans = -ans;
  writeln(ans);
  return 0;
}
