#include <bits/stdc++.h>
using namespace std;
int arr[110];
int n, m, team[25];
char type[25];
int sign[3] = {0, 1, -1};
int memo[20][(1 << 20)];
int solve(int aidx, int mask) {
  if (aidx == m) return 0;
  int &ret = memo[aidx][mask];
  if (ret != 1e9) return ret;
  if (team[aidx] == 1) ret = -1e9;
  int s = sign[team[aidx]];
  if (type[aidx] == 'p') {
    for (int i = 0; i < m; ++i) {
      if (mask & (1 << i)) {
        ret = s * arr[i] + solve(aidx + 1, mask ^ (1 << i));
        break;
      }
    }
  } else {
    if (team[aidx] == 1) {
      ret = solve(aidx + 1, mask);
      for (int i = 0; i < m; ++i)
        if (mask & (1 << i)) ret = max(ret, solve(aidx + 1, mask ^ (1 << i)));
    } else {
      ret = solve(aidx + 1, mask);
      for (int i = 0; i < m; ++i)
        if (mask & (1 << i)) ret = min(ret, solve(aidx + 1, mask ^ (1 << i)));
    }
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &arr[i]);
  sort(arr, arr + n, greater<int>());
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    cin >> type[i] >> team[i];
  }
  for (int i = 0; i < (1 << 20); ++i)
    for (int j = 0; j < 20; ++j) memo[j][i] = 1e9;
  cout << solve(0, (1 << m) - 1);
}
