#include <bits/stdc++.h>   using namespace std;   inline int bit(int x, int i) { return (x >> i) & 1; }   inline int two(int x) { return 1 << x; }   int n, s[110], m, team[110], dp[20][1 << 20];   char op[110];   bool vis[20][1 << 20];   int go(int mi, int ban) {     if (mi == m) return 0;     int &ret = dp[mi][ban];     if (vis[mi][ban]) return ret;     vis[mi][ban] = 1;     ret = -514514514;     for (int i = 0; i < (int)(n); i++)       if (!bit(ban, i)) {         int now = go(mi + 1, ban | two(i));         int str = (op[mi] ==  p  ? s[i] : 0);         if (mi + 1 < m && team[mi + 1] != team[mi])           now = str - now;         else           now = str + now;         ret = max(ret, now);       }     return ret;   }   int main() {     scanf( %d , &(n));     for (int i = 0; i < (int)(n); i++) scanf( %d , &(s[i]));     scanf( %d , &(m));     for (int i = 0; i < (int)(m); i++) scanf(  %c %d , op + i, team + i);     sort(s, s + n, greater<int>());     n = m;     int ans = go(0, 0);     if (team[0] == 2) ans *= -1;     printf( %d n , ans);     return 0;   }   