#include <bits/stdc++.h>
using namespace std;
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto vv : V) os << vv << ",";
  return os << "]";
}
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << '\n';
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
const int N = 1e2 + 7;
const int M = 1e7;
int dp[M], n, m, a[N], id[N];
char q[N];
int calc(int mask, int ii) {
  if (mask == 0 || ii == m) return 0;
  int &ret = dp[mask];
  if (ret != -1) return ret;
  ret = id[ii] == 1 ? INT_MIN : INT_MAX;
  for (int bit = 0; bit < m; bit++)
    if ((mask >> bit) & 1) {
      int nmask = mask ^ (1 << bit);
      if (id[ii] == 1) {
        if (q[ii] == 'p')
          ret = max(ret, calc(nmask, ii + 1) + a[bit]);
        else
          ret = max(ret, calc(nmask, ii + 1));
      } else {
        if (q[ii] == 'p')
          ret = min(ret, calc(nmask, ii + 1) - a[bit]);
        else
          ret = min(ret, calc(nmask, ii + 1));
      }
    }
  return ret;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> m;
  for (int i = 0; i < m; i++) cin >> q[i] >> id[i];
  sort(a, a + n, greater<int>());
  memset(dp, -1, sizeof dp);
  cout << calc((1 << m) - 1, 0) << '\n';
  return 0;
}
