#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T BM(T p, T e, T M) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T MDINV(T a, T M) {
  return BM(a, M - 2, M);
}
template <class T>
inline T PW(T p, T e) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p);
    p = (p * p);
  }
  return (T)ret;
}
template <class T>
string NTS(T Number) {
  stringstream ss;
  ss << Number;
  return ss.str();
}
template <class T>
T stringtonumber(const string &Text) {
  istringstream ss(Text);
  T result;
  return ss >> result ? result : 0;
}
long long int n;
long long int a[100 + 3];
pair<char, long long int> b[23];
long long int DP[23][1048579];
long long int dp(long long int i, long long int musk) {
  if (i == n) {
    return 0;
  }
  long long int &ret = DP[i][musk];
  if (ret != -1) return ret;
  ret = -1000000007ll;
  if (b[i].first == 'p') {
    for (long long int j = 0; j < n; j++) {
      if ((musk & (1ll << j)) == 0) {
        long long int y = musk;
        y = y | (1ll << j);
        ret = (b[i].second == 1 ? 1 : -1) * a[j] + dp(i + 1, y);
        break;
      }
    }
  } else {
    bool fl = 0;
    for (long long int j = 0; j < n; j++) {
      if ((musk & (1ll << j)) == 0) {
        long long int y = musk;
        y = y | (1ll << j);
        if (fl == 0) {
          fl = 1;
          ret = dp(i + 1, y);
        } else {
          ret = (b[i].second == 1 ? max(ret, dp(i + 1, y))
                                  : min(ret, dp(i + 1, y)));
        }
      }
    }
  }
  return ret;
}
int main() {
  scanf("%lld", &n);
  for (long long int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  sort(a, a + n);
  reverse(a, a + n);
  long long int m;
  scanf("%lld", &m);
  n = m;
  for (long long int i = 0; i < m; i++) {
    cin >> b[i].first >> b[i].second;
  }
  memset(DP, -1, sizeof DP);
  cout << dp(0, 0) << endl;
  return 0;
}
