#include <bits/stdc++.h>
using namespace std;
int abs(int x) {
  if (x < 0) return -x;
  return x;
}
int a[101], n, m;
pair<char, int> p[30];
int dp[21][1 << 20];
int solve(int pos, int mask) {
  if (pos == m) return 0;
  if (mask == 0) return 0;
  if (dp[pos][mask] != -1) return dp[pos][mask];
  int ans;
  if (p[pos].second == 1) {
    ans = -999999999;
    for (int i = 0; i < m; i++) {
      if (!((1 << i) & mask)) continue;
      if (p[pos].first == 'p')
        ans = max(ans, a[i] + solve(pos + 1, mask ^ (1 << i)));
      else {
        ans = max(ans, solve(pos + 1, mask ^ (1 << i)));
      }
    }
  } else {
    ans = 999999999;
    for (int i = 0; i < m; i++) {
      if (!((1 << i) & mask)) continue;
      if (p[pos].first == 'p')
        ans = min(ans, solve(pos + 1, mask ^ (1 << i)) - a[i]);
      else
        ans = min(ans, solve(pos + 1, mask ^ (1 << i)));
    }
  }
  return dp[pos][mask] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> p[i].first >> p[i].second;
  }
  sort(a, a + n);
  reverse(a, a + n);
  cout << solve(0, (1 << m) - 1) << endl;
  return 0;
}
