Problem:
問題 C : [[iwi]]
そうだ，僕のハンドルネームは (iwi) だ．
僕は確かに昔にプログラミングコンテストに参加していた．
そして，多くの仲間と楽しい時間を過ごした．
確か，仲間たちは全員，美少女だったような気がする．
プログラミングコンテストの世界は，僕のハーレムだったような気がする．
G○○gle は，僕のハーレムを奪ったのだ，そうに違いない．
昔の仲間の手がかりをつかむためにも，やはりプログラミングコンテストに出なければならない．
G○○gle Code Jam に参加登録することにしよう．
今度の ID には，丸括弧以外の括弧も検討に入れてみよう．
問題
'i', 'w', '(', ')', '{', '}', '[', ']' からなる文字列が与えられた時，
その部分列をとって，線対称な文字列を作りたい．
最大で何文字の文字列を作ることができるかを計算するプログラムを作成せよ．
与えられる文字列は，
"iwi" という文字列を一度含み，それ以外の部分には 'i' と 'w' を含まない．
より形式的には，与えられる文字列は
s
"iwi"
t
（
s
と "iwi" と
t
を連結したもの）という形で表すことができ，
s
と
t
は '(', ')', '{', '}', '[', ']' からなる文字列である．
s
や
t
が 0 文字である可能性もある．
作る文字列は，与えられる文字列の部分列をとって作る．
部分列とは，元の文字列からいくつかの文字を取り出し，それらを，
元の文字列に含まれる順番で繋げたものである．
取り出す文字たちは必ずしも元の文字列で連続していなくても良い．
また，作る文字列も，与えられる文字列と同様に，"iwi" という文字列を一度含み，
それ以外の部分には 'i' と 'w' は含まないようにしたい．
ここで用いる左右に線対称の定義は，以下とする．
以下の文字列は左右に線対称．
空文字列
"i"
"w"
文字列
x
が左右に線対称のとき，以下の文字列も左右に線対称．
"i"
x
"i"
"w"
x
"w"
"("
x
")"
")"
x
"("
"{"
x
"}"
"}"
x
"{"
"["
x
"]"
"]"
x
"["
以上のもののみが左右に線対称．
入力
入力は 'i', 'w', '(', ')', '{', '}', '[', ']' からなり上記の条件を満たす文字列である．
出力
上記の条件を満たし作ることのできる文字列の長さの最大値を出力せよ．
制約
入力の文字列の長さは 15 以下である．
入出力例
入出力例 1
入力例 1:
[[[iwi[[[
入力例 1 に対する出力例:
3
"iwi" という文字列しか作ることができない．
入出力例 2
入力例 2:
[{)iwi(]}
入力例 2 に対する出力例:
7
"[)iwi(]" や "{)iwi(}" など 7 文字の文字列を作ることができる．

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
 
bool check(string s){
    int n = s.size();
    bool ok = true;
    for(int i=0;i<n/2;i++){
        if(s[i] == '('){
            ok &= s[n-1-i] == ')';
        }
        else if(s[i] == ')'){
            ok &= s[n-1-i] == '(';
        }
        else if(s[i] == '['){
            ok &= s[n-1-i] == ']';
        }
        else if(s[i] == ']'){
            ok &= s[n-1-i] == '[';
        }
        else if(s[i] == '}'){
            ok &= s[n-1-i] == '{';
        }
        else if(s[i] == '{'){
            ok &= s[n-1-i] == '}';
        }
        else{
            ok &= s[i] == s[n-1-i];
        }
    }
    int cnt = 0, pos = 0;
    while((pos = s.find("iwi",pos)) != s.npos){
        cnt++;
        pos++;
    }
    ok &= cnt == 1;
    return ok;
}

int main(){
    int n, ans = 0;
    string s;
    cin >> s;
    n = s.size();
    for(int S=1;S<1<<n;S++){
        string t;
        for(int i=0;i<n;i++){
            if((S>>i)&1){
                t.push_back(s[i]);
            }
            if(check(t)){
                ans = max(ans, int(t.size()));
            }
        }
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3212
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;

bool check(string s){
    int n = s.size();
    bool ok = true;
    for(int i=0;i<n/2;i++){
        if(s[i] == '('){
            ok &= s[n-1-i] == ')';
        }
        else if(s[i] == ')'){
            ok &= s[n-1-i] == '(';
        }
        else if(s[i] == '['){
            ok &= s[n-1-i] == ']';
        }
        else if(s[i] == ']'){
            ok &= s[n-1-i] == '[';
        }
        else if(s[i] == '}'){
            ok &= s[n-1-i] == '{';
        }
        else if(s[i] == '{'){
            ok &= s[n-1-i] == '}';
        }
        else{
            ok &= s[i] == s[n-1-i];
        }
    }
    return ok;
}

int main(){
    int n, ans = 0;
    string s;
    cin >> s;
    n = s.size();
    for(int S=1;S<1<<n;S++){
        string t;
        for(int i=0;i<n;i++){
            if((S>>i)&1){
                t.push_back(s[i]);
            }
            if(check(t)){
                ans = max(ans, int(t.size()));
            }
        }
    }
    cout << ans << endl;
    return 0;
}
accuracy: 0.13513513513513514
time_ms: 20
memory_kb: 3216
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const long long INF = 2e18;
const long long MOD = 1e9+7;

#define sx(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a),end(a)

int main(void) {
    string S;
    cin >> S;
    int N = S.size();

    int ans = 0;

    for (int i=0; i<(1<<N); i++) {
        vector<bool> use(N, false);
        int t = i;
        REP(j, N) {
            use[j] = t%2;
            t /= 2;
        }
        string ss;
        REP(j, N) {
            if (use[j]) ss.pb(S[j]);
        }
        int n = ss.size();
        if (n%2 == 0) continue;
        bool flag = true;
        if (!(ss[n/2-1]=='i' && ss[n/2+1]=='i' && ss[n/2] == 'w')) flag = false;
        REP(j, n/2) {
            if (ss[j] == 'i') {
                if (ss[n-j-1] != 'i') flag = false;
                // cout << "a";
            }
            else if (ss[j] == 'w') {
                if (ss[n-j-1] != 'w') flag = false;
                //cout << "b";
            }
            else if (ss[j] == '(') {
                if (ss[n-j-1] != ')') flag = false;
                //cout << "c";
            }
            else if (ss[j] == ')') {
                if (ss[n-j-1] != '(') flag = false;
                //cout << "d";
            }
            else if (ss[j] == '[') {
                if (ss[n-j-1] != ']') flag = false;
                //cout << "e";
            }
            else if (ss[j] == ']') {
                if (ss[n-j-1] != '[') flag = false;
                //cout << "f";
            }
            else if (ss[j] == '{') {
                if (ss[n-j-1] != '}') flag = false;
                //cout << "g";
            }
            else if (ss[j] == '}') {
                if (ss[n-j-1] != '{') flag = false;
                //cout << "h";
            }
        }
        if (flag) ans = max(ans, n);

    }

    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3196
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const long long INF = 2e18;
const long long MOD = 1e9+7;

#define sx(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a),end(a)

int main(void) {
    string S;
    cin >> S;
    int N = S.size();

    int ans = 0;

    for (int i=0; i<(1<<N); i++) {
        vector<bool> use(N, false);
        int t = i;
        REP(j, N) {
            use[j] = t%2;
            t /= 2;
        }
        string ss;
        REP(j, N) {
            if (use[j]) ss.pb(S[j]);
        }
        int n = ss.size();
        bool flag = true;
        REP(j, n/2) {
            if (ss[j] == 'i') {
                if (ss[n-j-1] != 'i') flag = false;
                // cout << "a";
            }
            else if (ss[j] == 'w') {
                if (ss[n-j-1] != 'w') flag = false;
                //cout << "b";
            }
            else if (ss[j] == '(') {
                if (ss[n-j-1] != ')') flag = false;
                //cout << "c";
            }
            else if (ss[j] == ')') {
                if (ss[n-j-1] != '(') flag = false;
                //cout << "d";
            }
            else if (ss[j] == '[') {
                if (ss[n-j-1] != ']') flag = false;
                //cout << "e";
            }
            else if (ss[j] == ']') {
                if (ss[n-j-1] != '[') flag = false;
                //cout << "f";
            }
            else if (ss[j] == '{') {
                if (ss[n-j-1] != '}') flag = false;
                //cout << "g";
            }
            else if (ss[j] == '}') {
                if (ss[n-j-1] != '{') flag = false;
                //cout << "h";
            }
        }
        if (flag) ans = max(ans, n);

    }
    cout << ans << endl;
    return 0;
}
accuracy: 0.13513513513513514
time_ms: 10
memory_kb: 3152
final_rank: 18

code_snippet: #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < int(n); ++ (i))
using namespace std;
template <class T> inline void chmax(T & a, T const & b) { a = max(a, b); }

bool pred(string const & t) {
    int n = t.length();
    if (n % 2 == 0) return false;
    if (n < 3) return false;
    if (t[n / 2 - 1] != 'i') return false;
    if (t[n / 2    ] != 'w') return false;
    if (t[n / 2 + 1] != 'i') return false;
    REP (i, n / 2 - 1) {
        char c;
        switch (t[i]) {
            case '(': c = ')'; break;
            case ')': c = '('; break;
            case '[': c = ']'; break;
            case ']': c = '['; break;
            case '{': c = '}'; break;
            case '}': c = '{'; break;
            default: return false;
        }
        if (c != t[n - i - 1]) return false;
    }
    return true;
}

int main() {
    string s; cin >> s;
    int result = 0;
    REP (x, 1 << s.length()) {
        string t;
        REP (i, s.length()) if (x & (1 << i)) {
            t += s[i];
        }
        if (pred(t)) {
            chmax<int>(result, t.length());
        }
    }
    cout << result << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3200
final_rank: 9

code_snippet: #include <iostream>
#include <cstring>
using namespace std;

char dat[16];

int hantei(char a,char b){
  char lc[]="({[";
  char rc[]=")}]";

  for (int i=0;i<3;i++){
    if (a==lc[i]&&b==rc[i])return 1;
    
    if (b==lc[i]&&a==rc[i])return 1;
    
  }
  return 0;
}

int search(int a,int b,int c,int islfix){
  int lm,rm;
  if (islfix){
    for (int i=b;i>c;i--){
      if (hantei(dat[i],dat[a])){
	lm=search(a+1,i-1,c,1);
	rm=search(a+1,i-1,c,0);
	return max(lm,rm)+2;
      }
    }
  }else{
    for (int i=a;i<c;i++){
      if (hantei(dat[i],dat[b])){
	lm=search(i+1,b-1,c,1);
	rm=search(i+1,b-1,c,0);
	return max(lm,rm)+2;
      }
    }
  }
  int reta=0,retb=0,flg=0;
  if (a<c-1){
    rm= search( a+1, b, c, 0);
    lm= search( a+1, b, c, 1);
    //cout << a << " " << b ;

    //cout << rm << " " << lm << endl;
    reta=max(rm,lm);
    flg=1;
  }
  if (b>c+1){
    rm= search( a, b-1, c, 0);
    lm= search( a, b-1, c, 1);
    //cout << a << " " << b ;
    // cout << rm << " " << lm << endl;
    retb=max(rm,lm);
    flg=1;
  }
  //cout << flg << " "<< reta << " " << retb << endl;
  if (flg)return max(reta,retb);
  else return 3;
}

int main(){
  int c,ret;
  cin >> dat;
  for (c=0;dat[c]!='w';c++);
  ret = max(search(0,strlen(dat)-1,c,0),search(0,strlen(dat)-1,c,1));
  cout << ret << endl;
  return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 3080
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  string s;
  cin>>s;
  int n=s.size();
  int ans=0;
  map<char,char> r;
  r['[']=']';
  r[']']='[';
  r['(']=')';
  r[')']='(';
  r['{']='}';
  r['}']='{';
  r['i']='i';
  r['w']='w';
  for(int b=0;b<(1<<n);b++){
    string t;
    for(int i=0;i<n;i++) if((b>>i)&1) t+=s[i];
    if(t.find("iwi")==string::npos) continue;
    int k=t.size();
    if(k%2==0) continue;
    if(t[k/2-1]!='i'||t[k/2]!='w'||t[k/2+1]!='i') continue;
    bool f=1;
    for(int i=0;i<k/2;i++) f&=t[i]==r[t[k-1-i]];
    if(f) ans=max(ans,k);
  }
  cout<<ans<<endl;
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3188
final_rank: 7

code_snippet: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;

map<char, char>mp{ {'[',']'},{'{','}'},{'(',')'},{']','['},{'}','{'},{')','('} };
int main() {
	string s; cin >> s;
	int Max = 0;
	rep(i, 1 << s.size()) {
		string t;
		rep(j, s.size()) {
			if (i >> j & 1)t += s[j];
		}
		if ((int)t.find("iwi") == -1)continue;
		string k = t; reverse(k.begin(), k.end());
		for (char&c : k) {
			if (!isalpha(c))c = mp[c];
		}
		if (k == t)Max = max(Max, (int)t.size());
	}
	printf("%d\n", Max);
}
accuracy: 1
time_ms: 10
memory_kb: 3352
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  string r;
  R r;
  int n=r.size();
  int ans=0;
  REP(t,1,1<<n) {
    if(__builtin_popcount(t)<=2) continue;
    string s="";
    rep(i,n) if(t&(1<<i)) s+=r[i];
    bool f=1;
    int m=s.size();
    rep(i,m) {
      char c=s[i],c2=s[s.size()-i-1];
      if(c=='i'&&c2!='i') f=0;
      if(c=='w'&&c2!='w') f=0;
      if(c=='('&&c2!=')') f=0;
      if(c==')'&&c2!='(') f=0;
      if(c=='['&&c2!=']') f=0;
      if(c==']'&&c2!='[') f=0;
      if(c=='{'&&c2!='}') f=0;
      if(c=='}'&&c2!='{') f=0;
    }
    if(f&&m%2) {
      if(s[m/2-1]!='i'||s[m/2]!='w'||s[m/2+1]!='i') continue;
      bool ff=1;
      rep(i,m/2-1) {
        if(isalpha(s[i])) ff=0;
        if(isalpha(s[m-i-1])) ff=0;
      }
      if(ff) ans=max(ans,(int)s.size());
    }
  }
  pr(ans);
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1204
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  string r;
  R r;
  int n=r.size();
  int ans=0;
  REP(t,1,1<<n) {
    string s="";
    rep(i,n) if(t&(1<<i)) s+=r[i];
    bool f=1;
    rep(i,s.size()) {
      char c=s[i],c2=s[s.size()-i-1];
      if(isalpha(c)&&c!=c2) f=0;
      if(c=='('&&c2!=')') f=0;
      if(c==')'&&c2!='(') f=0;
      if(c=='['&&c2!=']') f=0;
      if(c==']'&&c2!='[') f=0;
      if(c=='{'&&c2!='}') f=0;
      if(c=='}'&&c2!='{') f=0;
    }
    if(f) ans=max(ans,(int)s.size());
  }
  pr(ans);
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}
accuracy: 0.13513513513513514
time_ms: 10
memory_kb: 1200
final_rank: 17

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	bool m[300][300]={0};
	m['i']['i']=true;
	m['w']['w']=true;
	m[')']['(']=true;
	m['('][')']=true;
	m[']']['[']=true;
	m['['][']']=true;
	m['}']['{']=true;
	m['{']['}']=true;
	string s;
	cin>>s;
	int n=s.size();
	int out=0;
	loop(i,1,1<<n){
		string t="";
		rep(j,n)if(i&(1<<j))t+=s[j];
		if(t.size()%2==0)continue;
		bool h=true;
		rep(j,t.size()/2)if(m[t[j]][t[t.size()-1-j]]==0)h=false;
		if(t[t.size()/2]!='w')h=false;
		if(h&&out<t.size())out=t.size();
	}
	cout<<out<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 1292
final_rank: 5

code_snippet: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string S,T;
bool sym(string U){
	for(int i=0;i<U.size();i++){
		int K=U.size()-1-i;
		if(U[i]=='i' && U[K]=='i'){
			goto E;
		}
		if(U[i]=='w' && U[K]=='w'){
			goto E;
		}
		if(U[i]=='(' && U[K]==')'){
			goto E;
		}
		if(U[i]==')' && U[K]=='('){
			goto E;
		}
		if(U[i]=='[' && U[K]==']'){
			goto E;
		}
		if(U[i]==']' && U[K]=='['){
			goto E;
		}
		if(U[i]=='{' && U[K]=='}'){
			goto E;
		}
		if(U[i]=='}' && U[K]=='{'){
			goto E;
		}
		return false;
		E:;
	}
	int cnt=0;
	char x[200];
	int size2=U.size();
	for(int i=0;i<size2;i++){
		x[i]=U[i];
	}
	for(int i=0;i<size2-2;i++){
		if(x[i]==105 && x[i+1]==119 && x[i+2]==105){
			cnt++;
		}
	}
	if(cnt==1){
		return true;
	}
	return false;
}
int main(){
	int res=0;
	cin>>S;
	for(int i=0;i<(1<<(S.size()));i++){
		T="";
		for(int j=0;j<S.size();j++){
			if((i/(1<<j))%2==0){
				T+=S[j];
			}
		}
		bool ok=sym(T);
		if(ok==true){
			res=max(res,(int)(T.size()));
		}
	}
	if(res<=2){
		res=0;
	}
	cout<<res<<endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1192
final_rank: 1

code_snippet: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string S,T;
bool sym(string U){
	for(int i=0;i<U.size();i++){
		int K=U.size()-1-i;
		if(U[i]=='i' && U[K]=='i'){
			goto E;
		}
		if(U[i]=='w' && U[K]=='w'){
			goto E;
		}
		if(U[i]=='(' && U[K]==')'){
			goto E;
		}
		if(U[i]==')' && U[K]=='('){
			goto E;
		}
		if(U[i]=='[' && U[K]==']'){
			goto E;
		}
		if(U[i]==']' && U[K]=='['){
			goto E;
		}
		if(U[i]=='{' && U[K]=='}'){
			goto E;
		}
		if(U[i]=='}' && U[K]=='{'){
			goto E;
		}
		return false;
		E:;
	}
	return true;
}
int main(){
	int res=0;
	cin>>S;
	for(int i=0;i<(1<<(S.size()));i++){
		T="";
		for(int j=0;j<S.size();j++){
			if((i/(1<<j))%2==0){
				T+=S[j];
			}
		}
		bool ok=sym(T);
		if(ok==true){
			res=max(res,(int)(T.size()));
		}
	}
	if(res<=2){
		res=0;
	}
	cout<<res<<endl;
	return 0;
}
accuracy: 0.13513513513513514
time_ms: 10
memory_kb: 1192
final_rank: 16

code_snippet: #include <string>
#include <iostream>
#include <algorithm>

using namespace std;

string S;

const string R1 = "iw(){}[]";
const string R2 = "iw)(}{][";

inline bool solve(string T)
{
	int is = 0, ws = 0;

	for (int i = 0; i < T.size(); i++)
	{
		if (T[i] == 'i') is++;
		if (T[i] == 'w') ws++;
	}

	if (!(is == 2 && ws == 1)) return false;

	bool flag = false;

	for (int i = 0; i < (int)(T.size()) - 2; i++)
	{
		if (T.substr(i, 3) == "iwi")
		{
			flag = true;
		}
	}

	if (!flag) return false;

	if (T.size() % 2 == 1)
	{
		char middle = T[T.size() / 2];

		if (!(middle == 'i' || middle == 'w')) return false;
	}

	for (int i = 0; i < T.size(); i++)
	{
		char c1 = T[i];
		char c2 = T[T.size() - i - 1];

		for (int j = 0; j < 8; j++)
		{
			if (R1[j] == c1)
			{
				if (R2[j] != c2)
				{
					return false;
				}
			}
		}
	}

	return true;
}

int main()
{
	cin >> S;

	int ret = 0;

	for (int i = 0; i < (1 << S.size()); i++)
	{
		string T;

		for (int j = 0; j < S.size(); j++)
		{
			if (i & (1 << j))
			{
				T += S[j];
			}
		}

		if (solve(T))
		{
			ret = max(ret, (int)(T.size()));
		}
	}

	printf("%d\n", ret);

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3328
final_rank: 10

code_snippet: #include <string>
#include <iostream>
#include <algorithm>

using namespace std;

string S;

const string R1 = "iw(){}[]";
const string R2 = "iw)(}{][";

bool solve(string T)
{
	int is = 0, ws = 0;

	for (int i = 0; i < T.size(); i++)
	{
		if (T[i] == 'i') is++;
		if (T[i] == 'w') ws++;
	}

	if (!(is == 2 && ws == 1)) return false;

	bool flag = false;

	for (int i = 0; i < (int)(T.size()) - 2; i++)
	{
		if (T.substr(i, 3) == "iwi")
		{
			flag = true;
		}
	}

	if (!flag) return false;

	if (T.size() % 2 == 1)
	{
		char middle = T[T.size() / 2];

		if (!(middle == 'i' || middle == 'w')) return false;
	}

	for (int i = 0; i < T.size(); i++)
	{
		char c1 = T[i];
		char c2 = T[T.size() - i - 1];

		for (int j = 0; j < 8; j++)
		{
			if (R1[j] == c1)
			{
				if (R2[j] != c2)
				{
					return false;
				}
			}
		}
	}

	return true;
}

int main()
{
	cin >> S;

	int ret = 0;

	for (int i = 0; i < (1 << S.size()); i++)
	{
		string T;

		for (int j = 0; j < S.size(); j++)
		{
			if (i & (1 << j))
			{
				T += S[j];
			}
		}

		if (solve(T))
		{
			ret = max(ret, (int)(T.size()));
		}
	}

	printf("%d\n", ret);

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3328
final_rank: 10

code_snippet: #include <string>
#include <iostream>
#include <algorithm>

using namespace std;

string S;

const string R1 = "iw(){}[]";
const string R2 = "iw)(}{][";

bool solve(string T)
{
	int is = 0, ws = 0;

	for (int i = 0; i < T.size(); i++)
	{
		if (T[i] == 'i') is++;
		if (T[i] == 'w') ws++;
	}

	if (!(is == 2 && ws == 1)) return false;

	bool flag = false;

	for (int i = 0; i < (int)(T.size()) - 2; i++)
	{
		if (T.substr(i, 3) == "iwi")
		{
			flag = true;

			T.erase(T.begin() + i, T.begin() + i + 3);
		}
	}

	if (!flag) return false;

	if (T.size() % 2 == 1)
	{
		char middle = T[T.size() / 2];

		if (!(middle == 'i' || middle == 'w')) return false;
	}

	for (int i = 0; i < T.size(); i++)
	{
		char c1 = T[i];
		char c2 = T[T.size() - i - 1];

		for (int j = 0; j < 8; j++)
		{
			if (R1[j] == c1)
			{
				if (R2[j] != c2)
				{
					return false;
				}
			}
		}
	}

	return true;
}

int main()
{
	cin >> S;

	int ret = 0;

	for (int i = 0; i < (1 << S.size()); i++)
	{
		string T;

		for (int j = 0; j < S.size(); j++)
		{
			if (i & (1 << j))
			{
				T += S[j];
			}
		}

		if (solve(T))
		{
			ret = max(ret, (int)(T.size()));
		}
	}

	printf("%d\n", ret);

	return 0;
}
accuracy: 0.13513513513513514
time_ms: 10
memory_kb: 3328
final_rank: 19

code_snippet: #include<bits/stdc++.h>
using namespace std;

typedef pair<int,int>pint;
typedef vector<int>vint;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}


string S;
int N;

bool check(string s){
    if((s.size()&1)==0||s.size()<3||s.substr(s.size()/2-1,3)!="iwi")return false;
    rep(i,s.size()/2){
        char l=s[i],r=s[s.size()-i-1];
        if(isalpha(l)){
            if(l!=r)return false;
        }
        else{
            if(l=='['&&r==']')continue;
            if(l==']'&&r=='[')continue;
            if(l=='('&&r==')')continue;
            if(l==')'&&r=='(')continue;
            if(l=='{'&&r=='}')continue;
            if(l=='}'&&r=='{')continue;
            return false;
        }
    }
    return true;
}

int main(){
    cin>>S;
    N=S.size();

    int ma=0;

    rep(i,1<<N){
        string sub;
        rep(j,N)if(i>>j&1)sub+=S[j];
        if(check(sub))chmax(ma,sub.size());
    }

    cout<<ma<<endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1200
final_rank: 3

code_snippet: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;


char L[] = {'i', 'w', '(', ')', '{', '}', '[', ']'};
char R[] = {'i', 'w', ')', '(', '}', '{', ']', '['};

bool check(string s){
  int sl = s.length();
  if(s[sl / 2] != 'w' || s[sl / 2 - 1] != 'i' || s[sl / 2 + 1] != 'i') return 0;
  int l = sl / 2 - 2, r = sl / 2 + 2;
  while(l >= 0 && r < sl){
    bool f = 0;
    REP(i, 8) if(s[l] == L[i] && s[r] == R[i]) f = 1;
    if(!f) return 0;
    --l; ++r;
  }
  return 1;
}

int main() {
  string s; cin >>s;
  int sl = s.length(), ans = 3;
  REP(b, (1 << sl)){
    stringstream ss;
    REP(i, sl) if(1 & (b >> i)) ss << s[i];
    if(ss.str().length() < 3 || ss.str().length() % 2 == 0) continue;
    if(check(ss.str())) ans = max(ans, (int)ss.str().length());
  }
  cout <<ans <<endl;
  return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 1212
final_rank: 6

code_snippet: #include<iostream>
#include<algorithm>
#include<string>
using namespace std;


inline int popcount(unsigned int x){
	x = (x>>1 & 0x55555555)+(x & 0x55555555);
	x = (x>>2 & 0x33333333)+(x & 0x33333333);
	x = (x>>4 & 0x0f0f0f0f)+(x & 0x0f0f0f0f);
	x = (x>>8 & 0x00ff00ff)+(x & 0x00ff00ff);
	return (x>>16)+(x & 0x0000ffff);
}

int main(){
	char rev[256];
	for(int i=0;i<256;i++)rev[i]=i;
	rev['(']=')';
	rev['{']='}';
	rev['[']=']';
	rev[')']='(';
	rev['}']='{';
	rev[']']='[';
		
	string s;
	int ans=0;
	cin>>s;
	int n=s.size();
	for(int i=1;i<(1<<n);i++){
		string t;
		for(int j=0;j<n;j++){
			if(i>>j&1)t+=s[j];
		}
		if(t.find("iwi",0)==string::npos)continue;
		int len=popcount(i);
		if(len<=ans)continue;
		bool ok=true;
		for(int j=0;j<len/2;j++){
			if(rev[t[j]]!=t[len-1-j])ok=false;
		}
		if(len%2&&t[len/2]!=rev[t[len/2]])ok=false;
		if(ok)ans=len;
	}
	cout<<ans<<endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1196
final_rank: 2

code_snippet: #include<iostream>
#include<algorithm>
#include<string>
using namespace std;


inline int popcount(unsigned int x){
	x = (x>>1 & 0x55555555)+(x & 0x55555555);
	x = (x>>2 & 0x33333333)+(x & 0x33333333);
	x = (x>>4 & 0x0f0f0f0f)+(x & 0x0f0f0f0f);
	x = (x>>8 & 0x00ff00ff)+(x & 0x00ff00ff);
	return (x>>16)+(x & 0x0000ffff);
}

int main(){
	char rev[256];
	for(int i=0;i<256;i++)rev[i]=i;
	rev['(']=')';
	rev['{']='}';
	rev['[']=']';
	rev[')']='(';
	rev['}']='{';
	rev[']']='[';
		
	string s;
	int ans=0;
	cin>>s;
	int n=s.size();
	for(int i=1;i<(1<<n);i++){
		string t;
		for(int j=0;j<n;j++){
			if(i>>j&1)t+=s[j];
		}
		int len=popcount(i);
		if(len<=ans)continue;
		bool ok=true;
		for(int i=0;i<len/2;i++){
			if(rev[t[i]]!=t[len-1-i])ok=false;
		}
		if(len%2&&t[len/2]!=rev[t[len/2]])ok=false;
		if(ok)ans=len;
	}
	cout<<ans<<endl;
	return 0;
}
accuracy: 0.13513513513513514
time_ms: 10
memory_kb: 1184
final_rank: 15