#include using namespace std; #define ll long long #define rep(i,n) for(int i = 0; i skips; vector options; bool ischar(char c){ return c>='a'&&c<='z'; } int total(int i, int j, bool skipped){ if(j==-1) return 0; if(i==-1&&(ischar(r[j])||r[j]=='?'))return -1; else if(i==-1) return total(i, j-1, false); if(dp[i][j][skipped]!=-1) return dp[i][j][skipped]; dp[i][j][skipped] = 0; int res = total(i-1, j, false); if(ischar(r[j])){ if(r[j]==s[i]) res = max(res, total(i-1, j-1, false)+1); if(j>n; cin>>s; cin>>m; skips.assign(m, -1); cin>>r; options.assign(m, {}); vector pbuffer; vector bbuffer; rep(i,m){ if(r[i] == '(') pbuffer.push_back(i); if(r[i]==')') { skips[i] = pbuffer.back(); skips[pbuffer.back()] = i; pbuffer.pop_back(); } if(r[i] == '[') bbuffer.push_back(i); if(r[i]==']') { skips[i] = bbuffer.back(); skips[bbuffer.back()] = i; for(int j = bbuffer.back()+1; j