1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <string> 6 #include <map> 7 #include <cmath> 8 #include <vector> 9 10 #define Faster ios::sync_with_stdio(false),cin.tie(0) 11 #define Read freopen("in.txt","r",stdin),freopen("out.txt","w",stdout) 12 #define Close fclose(stdin),fclose(stdout) 13 const int maxn = 150; 14 using namespace std; 15 const int MOD = 1e9+7; 16 typedef long long ll; 17 18 ll dp[maxn][maxn]; 19 string s; 20 21 void solve(){ 22 int len = s.size(); 23 memset(dp, 0, sizeof(dp)); 24 25 for(int i = 1;i < len;i++){ 26 for(int j = 0;j + i < len;j++){ 27 int k = i+j; 28 if((s[j] == '(' && s[k] == ')') || (s[j] == '[' && s[k] == ']')) 29 dp[j][k] = dp[j+1][k-1] + 2; 30 for(int l = j;l < k;l++){ 31 dp[j][k] = max(dp[j][l] + dp[l+1][k],dp[j][k]); 32 } 33 } 34 } 35 cout << dp[0][len-1] << endl; 36 } 37 38 int main(){ 39 Faster; 40 // string s; 41 while(cin >> s){ 42 if(s == "end"){ 43 break; 44 } 45 solve(); 46 } 47 return 0; 48 }