#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed;
  cout.precision(12);
  solve();
  return 0;
}
template <typename T>
void sc(T& x) {
  cin >> x;
}
template <typename Head, typename... Tail>
void sc(Head& head, Tail&... tail) {
  cin >> head;
  sc(tail...);
}
template <typename T>
void pr(const T& x) {
  cout << x << '\n';
}
template <typename Head, typename... Tail>
void pr(const Head& head, const Tail&... tail) {
  cout << head << ' ';
  pr(tail...);
}
const int inf = 2e9;
int n, m;
vector<int> a;
vector<pair<char, int>> act;
int dp[22][1 << 20];
int calc(int pos, int mask) {
  if (pos == m) {
    return 0;
  }
  if (dp[pos][mask] != -1) {
    return dp[pos][mask];
  }
  int ans = (act[pos].second == 1 ? -inf : inf);
  for (int i = 0; i < m; i++) {
    if (act[pos].second == 1) {
      if ((mask >> i) % 2 == 0) {
        ans = max(ans, calc(pos + 1, mask | (1 << i)) +
                           a[i] * (act[pos].first == 'p'));
      }
    } else {
      if ((mask >> i) % 2 == 0) {
        ans = min(ans, calc(pos + 1, mask | (1 << i)) -
                           a[i] * (act[pos].first == 'p'));
      }
    }
  }
  return dp[pos][mask] = ans;
}
void solve() {
  sc(n);
  for (int i = 0; i < n; i++) {
    int x;
    sc(x);
    a.push_back(x);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  sc(m);
  for (int i = 0; i < m; i++) {
    string t;
    sc(t);
    int x;
    sc(x);
    act.push_back(make_pair(t[0], x));
  }
  memset(dp, -1, sizeof dp);
  pr(calc(0, 0));
}
