#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
  return x * x;
}
const int maxn = 101;
const int lim = 21;
int n, m;
int a[maxn], who[maxn];
char p[maxn];
int f[21][1 << lim];
int mymin(int x, int y) { return min(x, y); }
int mymax(int x, int y) { return max(x, y); }
int main() {
  srand(time(NULL));
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a, a + n);
  reverse(a, a + n);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> p[i] >> who[i];
  f[0][0] = 0;
  for (int i = 1; i <= n; ++i)
    for (int mask = 0; mask < (1 << n); ++mask) {
      if (__builtin_popcount(mask) < i - 1) continue;
      int sign = (who[n - i] == 1) ? 1 : -1;
      if (sign == 1)
        f[i][mask] = -1000000000;
      else
        f[i][mask] = 1000000000;
      if (p[n - i] == 'p') {
        for (int j = 0; j < n; ++j) {
          if (mask & (1 << j))
            f[i][mask] = ((sign == 1) ? mymax : mymin)(
                f[i][mask], sign * a[j] + f[i - 1][mask ^ (1 << j)]);
        }
      } else {
        f[i][mask] = f[i - 1][mask];
        for (int j = 0; j < n; ++j) {
          if (mask & (1 << j))
            f[i][mask] = ((sign == 1) ? mymax : mymin)(
                f[i][mask], f[i - 1][mask ^ (1 << j)]);
        }
      }
    }
  cout << f[n][(1 << n) - 1];
  return 0;
}
