#include <bits/stdc++.h>
using namespace std;
const int Inf = 1e8 + 1, N = 101, M = 21;
int n, m, a[N], dp[1 << M];
char c[M], t[M];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  reverse(a, a + n);
  cin >> m;
  for (int i = 0; i < m; i++) cin >> c[i] >> t[i];
  for (int i = 1; i < (1 << m); i++) {
    int turn = m - __builtin_popcount(i);
    dp[i] = t[turn] == '1' ? -Inf : Inf;
    for (int j = 0; j < m; j++)
      if ((i >> j) & 1)
        if (t[turn] == '1')
          dp[i] = max(dp[i], (c[turn] == 'p' ? a[j] : 0) + dp[i - (1 << j)]);
        else
          dp[i] = min(dp[i], (c[turn] == 'p' ? -a[j] : 0) + dp[i - (1 << j)]);
  }
  cout << dp[(1 << m) - 1];
}
