#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
void Open() {}
int dp[1 << 21];
int n, m;
char tmp[3];
int a[21 * 10];
int ty[21];
int who[21];
int main() {
  Open();
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  sort(a, a + n, greater<int>());
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++)
    scanf("%s%d", tmp, who + i), ty[i] = (tmp[0] == 'p');
  int limit = 1 << (n = m);
  for (int i = 1; i < limit; i++) {
    int idx = n - __builtin_popcount(i);
    if (who[idx] == 1)
      dp[i] = -INF;
    else
      dp[i] = INF;
    for (int j = 0; j < n; j++)
      if (i & (1 << j)) {
        if (who[idx] == 1)
          dp[i] = max(dp[i], dp[i ^ (1 << j)] + a[j] * (ty[idx] ? 1 : 0));
        else
          dp[i] = min(dp[i], dp[i ^ (1 << j)] - a[j] * (ty[idx] ? 1 : 0));
      }
  }
  cout << dp[limit - 1] << endl;
  return 0;
}
