#include <bits/stdc++.h>
using namespace std;
int dp[20][1 << 20];
bool isVisit[20][1 << 20];
int data[100], n;
int m, query[20][2];
vector<int> subsets[1 << 20];
int getAns(int ind, int left) {
  int &ret = dp[ind][left];
  if (isVisit[ind][left]) return ret;
  isVisit[ind][left] = true;
  if (ind == m - 1) {
    if (query[ind][0] == 0)
      ret = data[subsets[left][0]];
    else
      ret = 0;
  } else {
    ret = -999999999;
    int flag = 1;
    if (query[ind][1] != query[ind + 1][1]) flag = -1;
    for (int i = 0; i < subsets[left].size(); i++) {
      int bit = subsets[left][i];
      int val = getAns(ind + 1, left ^ (1 << bit)) * flag;
      if (query[ind][0] == 0) val += data[bit];
      ret = max(ret, val);
    }
  }
  return ret;
}
int main(void) {
  for (int i = 0; i < (1 << 20); i++)
    for (int j = 0; j < 20; j++)
      if (i & (1 << j)) subsets[i].push_back(j);
  memset(dp, -1, sizeof(dp));
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", data + i);
  sort(data, data + n);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    char temp[2];
    scanf("%s %d", temp, query[i] + 1);
    if (temp[0] == 'p')
      query[i][0] = 0;
    else
      query[i][0] = 1;
  }
  for (int i = 0; i < m; i++) data[i] = data[n - m + i];
  int val = getAns(0, (1 << m) - 1);
  if (query[0][1] == 2) val *= -1;
  printf("%d\n", val);
  return 0;
}
