#include <bits/stdc++.h>
using namespace std;
int n, m;
int S[111];
char act[20];
int team[20];
int dp[1 << 20];
bool calculated[1 << 20];
int calc_state(int state, int step) {
  if (step >= m) return 0;
  if (calculated[state]) return dp[state];
  vector<int> results;
  for (int i = 0; i < m; ++i) {
    if ((state >> i) & 1) continue;
    int tres = calc_state(state | (1 << i), step + 1);
    if (act[step] == 'p') tres += team[step] == 1 ? S[i] : -S[i];
    results.push_back(tres);
  }
  int res = team[step] == 1 ? *max_element(results.begin(), results.end())
                            : *min_element(results.begin(), results.end());
  calculated[state] = true;
  return dp[state] = res;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> S[i];
  sort(S, S + n);
  reverse(S, S + n);
  cin >> m;
  for (int i = 0; i < m; ++i) cin >> act[i] >> team[i];
  cout << calc_state(0, 0);
  return 0;
}
