Problem:
The Balance of the World
The world should be finely balanced.  Positive vs. negative,
light vs. shadow, and left vs. right brackets.
Your mission is to write a program that judges whether a string is balanced
with respect to brackets so that we can observe the balance of the
world.
A string that will be given to the program may have two kinds of brackets,
round (“( )”) and square (“[ ]”).
A string is balanced if and only if the following conditions hold.
For every left round bracket (“(”), there is a corresponding
    right round bracket (“)”) in the following part of the string.
For every left square bracket (“[”), there is a corresponding
    right square bracket (“]”) in the following part of the string.
For every right bracket, there is a left bracket corresponding to it.
Correspondences of brackets have to be one to one, that is, a
    single bracket never corresponds to two or more brackets.
For every pair of corresponding left and right brackets,
    the substring between them is balanced.
Input
The input consists of one or more lines, each of which being a dataset.
A dataset is a string that consists of English alphabets,
space characters, and two kinds of brackets, round (“( )”) and square (“[ ]”),
terminated by a period.  You can assume that every line has 100
characters or less.
The line formed by a single period indicates the end of the input,
which is not a dataset.
Output
For each dataset, output “yes” if the
string is balanced, or “no” otherwise, in a line.
There may not be any extra characters in the output.
Sample Input
So when I die (the [first] I will see in (heaven) is a score list).
[ first in ] ( first out ).
Half Moon tonight (At least it is better than no Moon at all].
A rope may form )( a trail in a maze.
Help( I[m being held prisoner in a fortune cookie factory)].
([ (([( [ ] ) ( ) (( ))] )) ]).
 .
.
Output for the Sample Input
yes
yes
no
no
no
yes
yes

Submitted solutions:

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

int main()
{
	while(true)
	{
		string s;
		getline(cin,s);
		if(s==".")
			break;
		vector <int> v;
		bool ans=true;
		for(int i=0; i<s.size(); i++)
		{
			if(s[i]=='(')
				v.push_back(1);
			if(s[i]=='[')
				v.push_back(2);
			if(s[i]==')')
			{
				if(v.size()>0 and v.back()==1)
					v.pop_back();
				else
				{
					ans=false;
					break;
				}
			}
			if(s[i]==']')
			{
				if(v.size()>0 and v.back()==2)
					v.pop_back();
				else
				{
					ans=false;
					break;
				}
			}
		}
		if(ans and v.size()==0)
			cout<<"yes";
		else
			cout<<"no";
		cout<<endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3176
final_rank: 6

code_snippet: #include <iostream>
#include <string>
#include <utility>
#include <limits.h>
#include <cstdlib>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <map>
using namespace std;
using llint = long long;
using vec = vector<llint>;
using vvec = vector<vec>;

void a(vector<int>& data, int len){
    for(int i = 0; i < len; i++){
        if(data[i] == 0){
            int j = 0;
            for(j = i; j < len-1; j++){
                data[j] = data[j+1];
            }
            data[len - 1] = 0;
            i--;
            len--;
        }
    }
}

int main(){
    while(1){
        int j = 0;
        int ans = 1;
        string s;
        getline(cin,s);
        if(s == ".")return 0;
        vector<int> num(101,0);
        for(int i = 0; s[i] != '\0'; i++){
            if(s[i] == '('){
                num[j] = 1;
                j++;
            }
            if(s[i] == '['){
                num[j] = 2;
                j++;
            }
            if(s[i] == ')'){
                num[j] = -1;
                j++;
            }
            if(s[i] == ']'){
                num[j] = -2;
                j++;
            }
        }
        for(int i = 0; i < j; i++){
            int count = 0;
            for(int q = 0; q < j; q++){
                if(num[q] == 0){
                    count++;
                }
            }
            if(count == j){
                ans = 0;
                break;
            }
            if(i == 0 && num[i] < 0)break;
            if(num[i-1] + num[i] == 0 && num[i-1] > 0){
                num[i-1] = 0;
                num[i] = 0;
                /*for(int q = 0; q < j; q++){
                    cout << num[q] << ",";
                }
                cout << endl;*/
                a(num,j);
                /*for(int q = 0; q < j; q++){
                    cout << num[q] << ",";
                }
                cout << endl;*/

                j-=2;
                i=0;
            }
        }

        if(num[0] == 0 && num[1] == 0){
            ans = 0;
        }

        if(ans == 1){
            cout << "no\n";
        }else if(ans == 0){
            cout << "yes\n";
        }
    }

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

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


int main() {
    while(1) {
        string s;
        getline(cin, s);
        if (s == ".") break;
        bool flag = true;
        stack<int> st;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == '(') {
                st.push(0);
            } else if (s[i] == ')') {
                if (st.empty()) {
                    flag = false;
                    break;
                }
                if (st.top() != 0) {
                    flag = false;
                    break;
                }
                st.pop();
            } else if (s[i] == '[') {
                st.push(1);
            } else if (s[i] == ']') {
                if (st.empty()) {
                    flag = false;
                    break;
                }
                if (st.top() != 1) {
                    flag = false;
                    break;
                }
                st.pop();
            }
            
        }
        if (!st.empty()) flag = false;
        if (flag) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3192
final_rank: 7

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

#define MAX 1000000

set<int> prime;

void main_(){
    string s;
    getline(cin,s);
    if(s == ".") exit(0);

    string k;
    rep(i,s.size()){
        set<char> st = {'(',')','[',']'};
        if(st.find(s.at(i)) != st.end()){
            k.push_back(s.at(i));
        }
    }

    int flag = true;
    while(flag){
        flag = false;
        string nxt;
        
        int num = k.size();
        int i = 0;
        for(i = 0;i < num - 1;i++){
            if( (k.at(i) == '(' && k.at(i + 1) == ')' ) ||
             (k.at(i) == '[' && k.at(i + 1) == ']' )){
                i += 1;;
                flag = true;
            } else {
                nxt.push_back(k.at(i));
            }
        }
        if(i == num - 1) nxt.push_back(k.at(i));

        k = nxt;
    }

    if(k == ""){
        cout << "yes" << endl;
    } else {
        cout << "no" << endl;
    }
}
signed main(){
    while(1) main_();
}
accuracy: 1
time_ms: 20
memory_kb: 3348
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main() {
  while (true) {
    string S;
    getline(cin, S);
    if (S == ".") {
      break;
    }
    stack<char> Q;
    bool ok = true;
    int L = S.length();
    for (int i = 0; i < L; i++) {
      if (S[i] == '(' || S[i] == '[') {
        Q.push(S[i]);
      }
      if (S[i] == ')' || S[i] == ']') {
        if (Q.empty()) {
          ok = false;
        }
        if (ok) {
          char c = Q.top();
          if ((S[i] == ')' && c == '(') || (S[i] == ']' && c == '[')) {
            Q.pop();
          } else {
            ok = false;
          }
        }
      }
    }
    if (ok && Q.empty()) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3136
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
    string str, ans;
    stack<char> st;
    while(getline(cin, str), str != "."){
        while(!st.empty()) st.pop();
        ans = "yes";
        for(int i=0;i<str.size();i++){
            if(ans == "no") continue;
            if(str[i] == '('){
                st.push('(');
            }else if(str[i] == ')'){
                if(st.empty() || st.top() != '(') ans = "no";
                else st.pop();
            }else if(str[i] == '['){
                st.push('[');
            }else if(str[i] == ']'){
                if(st.empty() || st.top() != '[') ans = "no";
                else st.pop();
            }
        }
        if(!st.empty()) ans = "no";
        cout << ans << endl;
    }
    return(0);
}
accuracy: 1
time_ms: 10
memory_kb: 3172
final_rank: 5

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

int main()
{    
    while(1){
        int flg = 1;
        string s;
        stack<char> S;
        getline(cin, s);

        if(s == "."){
            flg = 2;
            break;
        }
        for(int i=0; i < s.length(); i++){
            char c = s[i];
            if(c == '('){
                S.push(c);
            }
            else if(c == ')'){
                if(S.size() > 0 && S.top() == '(') S.pop();
                else{
                    flg = 0;
                    break;
                }
            }
            else if(c == '['){
                S.push(c);
            }
            else if(c == ']'){
                if(S.size() > 0 && S.top() == '[') S.pop();
                else{
                    flg = 0;
                    break;
                }
            }
            else continue;
        }
        if(flg == 1 && S.size() == 0) cout << "yes" << endl;
        else if(flg == 0 || S.size() != 0) cout << "no" << endl;
        else if(flg == 2) break;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3160
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int, int>
#define us unordered_set
#define ud unordered_dict
#define Lower_bound(vec, n) distance((vec).begin(), lower_bound((vec).begin(), (vec).end(), (n)))
#define Upper_bound(vec, n) distance((vec).begin(), upper_bound((vec).begin(), (vec).end(), (n)))
#define Erase(vec) (vec).erase(unique((vec).begin(), (vec).end()), (vec).end())
#define Print(vec) copy((vec).begin(), (vec).end(), ostream_iterator<int>(cout, ": ")); cout << endl
//template <class T = int> in()(T x; cin >> x; return (x);)
//template <class T> print(T& x) (cout << x << endl;)
//using template <class T> vec = vector<T>;
using Graph = vector<vector<int>>;
const int INF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

signed main() {

    string intmp;
    while (true) {

        /*
        vector<string> vec{};
        while (true) {
            cin >> intmp;
            vec.push_back(intmp);
            if (intmp[intmp.size() - 1] == '.') break;
        }
        */
        string s;
        getline(cin, s);

        /*
        vector<string> stop{"."};
        if (vec == stop) break;
        */
        if (s == ".") break;

        vector <char> str{};
        us<char> chars{'(', ')', '[', ']'};
        //int num_maru=0, num_sikaku=0;
        //bool flag = false;
        char c;
        /*
        for (string e: vec) {
            REP(i, e.size()) {
                c = e[i];
                if (chars.count(c)) str.push_back(c);
            }
        }
        */

        REP(i, s.size()) {
            c = s[i];
            if (chars.count(c)) str.push_back(c);
        }

        bool flag = true;
        if (str.size() % 2 != 0) flag = false;
        int iter = str.size() / 2;
        REP(i, iter) {
            REP(j, str.size()-1) {
                if ((str[j] == '(' && str[j+1] == ')') || (str[j] == '[' && str[j+1] == ']')) {
                    str.erase(str.begin()+j);
                    str.erase(str.begin()+j);
                    break;
                }
            }
        }
        if (str.size() != 0) flag = false;
        if (flag) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3272
final_rank: 9

code_snippet: #include<bits/stdc++.h>
#pragma GCC target("avx2")

#pragma GCC optimize("Ofast")

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define lp(i,n) for(int i=0;i<(int)(n);i++)
#define lps(i,j,n) for(int i=j;i<n;i++)

#define fordebug int hoge;cin>>hoge;

#define DEKAI 1000000007
#define floot10 cout<<fixed<<setprecision(15)1
#define all(v) v.begin(),v.end()
double PI = acos(-1);

namespace {
#define __DECLARE__(C)						\
  template <typename T>						\
  std::ostream &operator<<(std::ostream &, const C<T> &);

#define __DECLAREM__(C)						\
  template <typename T, typename U>				\
  std::ostream &operator<<(std::ostream &, const C<T, U> &);

  __DECLARE__(std::vector)
  __DECLARE__(std::deque)
  __DECLARE__(std::set)
  __DECLARE__(std::stack)
  __DECLARE__(std::queue)
  __DECLARE__(std::priority_queue)
  __DECLARE__(std::unordered_set)
  __DECLAREM__(std::map)
  __DECLAREM__(std::unordered_map)

  template <typename T, typename U>
  std::ostream &operator<<(std::ostream &, const std::pair<T, U> &);
  template <typename... T>
  std::ostream &operator<<(std::ostream &, const std::tuple<T...> &);
  template <typename T, std::size_t N>
  std::ostream &operator<<(std::ostream &, const std::array<T, N> &);

  template <typename Tuple, std::size_t N>
  struct __TuplePrinter__ {
    static void print(std::ostream &os, const Tuple &t) {
      __TuplePrinter__<Tuple, N - 1>::print(os, t);
      os << ", " << std::get<N - 1>(t);
    }
  };

  template <typename Tuple>
  struct __TuplePrinter__<Tuple, 1> {
    static void print(std::ostream &os, const Tuple &t) { os << std::get<0>(t); }
  };

  template <typename... T>
  std::ostream &operator<<(std::ostream &os, const std::tuple<T...> &t) {
    os << '(';
    __TuplePrinter__<decltype(t), sizeof...(T)>::print(os, t);
    os << ')';
    return os;
  }

  template <typename T, typename U>
  std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &v) {
    return os << '(' << v.first << ", " << v.second << ')';
  }

#define __INNER__                               \
  os << '[';                                    \
  for (auto it = begin(c); it != end(c);) {     \
    os << *it;                                  \
    os << (++it != end(c) ? ", " : "");         \
  }                                             \
  return os << ']';

  template <typename T, std::size_t N>
  std::ostream &operator<<(std::ostream &os, const std::array<T, N> &c) {
    __INNER__
      }

#define __DEFINE__(C)						\
  template <typename T>						\
  std::ostream &operator<<(std::ostream &os, const C<T> &c) {	\
    __INNER__							\
      }

#define __DEFINEM__(C)							\
  template <typename T, typename U>					\
  std::ostream &operator<<(std::ostream &os, const C<T, U> &c) {	\
    __INNER__								\
      }

#define __DEFINEW__(C, M1, M2)					\
  template <typename T>						\
  std::ostream &operator<<(std::ostream &os, const C<T> &c) {	\
    std::deque<T> v;						\
    for (auto d = c; !d.empty(); d.pop()) v.M1(d.M2());		\
    return os << v;						\
  }

  __DEFINE__(std::vector)
  __DEFINE__(std::deque)
  __DEFINE__(std::set)
  __DEFINEW__(std::stack, push_front, top)
  __DEFINEW__(std::queue, push_back, front)
  __DEFINEW__(std::priority_queue, push_front, top)
  __DEFINE__(std::unordered_set)
  __DEFINEM__(std::map)
  __DEFINEM__(std::unordered_map)
}


template <signed M, unsigned T>
struct mod_int {
  constexpr static signed MODULO = M;
  constexpr static unsigned TABLE_SIZE = T;

  signed x;

  mod_int() : x(0) {}

  mod_int(long long y) : x(static_cast<signed>(y >= 0 ? y % MODULO : MODULO - (-y) % MODULO)) {}

  mod_int(int y) : x(y >= 0 ? y % MODULO : MODULO - (-y) % MODULO) {}

  mod_int &operator+=(const mod_int &rhs) {
    if ((x += rhs.x) >= MODULO) x -= MODULO;
    return *this;
  }

  mod_int &operator-=(const mod_int &rhs) {
    if ((x += MODULO - rhs.x) >= MODULO) x -= MODULO;
    return *this;
  }

  mod_int &operator*=(const mod_int &rhs) {
    x = static_cast<signed>(1LL * x * rhs.x % MODULO);
    return *this;
  }

  mod_int &operator/=(const mod_int &rhs) {
    x = static_cast<signed>((1LL * x * rhs.inv().x) % MODULO);
    return *this;
  }

  mod_int operator-() const { return mod_int(-x); }

  mod_int operator+(const mod_int &rhs) const { return mod_int(*this) += rhs; }

  mod_int operator-(const mod_int &rhs) const { return mod_int(*this) -= rhs; }

  mod_int operator*(const mod_int &rhs) const { return mod_int(*this) *= rhs; }

  mod_int operator/(const mod_int &rhs) const { return mod_int(*this) /= rhs; }

  bool operator<(const mod_int &rhs) const { return x < rhs.x; }

  mod_int inv() const {
    assert(x != 0);
    if (x <= static_cast<signed>(TABLE_SIZE)) {
      if (_inv[1].x == 0) prepare();
      return _inv[x];
    } else {
      signed a = x, b = MODULO, u = 1, v = 0, t;
      while (b) {
        t = a / b;
        a -= t * b;
        std::swap(a, b);
        u -= t * v;
        std::swap(u, v);
      }
      return mod_int(u);
    }
  }

  mod_int pow(long long t) const {
    assert(!(x == 0 && t == 0));
    mod_int e = *this, res = mod_int(1);
    for (; t; e *= e, t >>= 1)
      if (t & 1) res *= e;
    return res;
  }

  mod_int fact() {
    if (_fact[0].x == 0) prepare();
    return _fact[x];
  }

  mod_int inv_fact() {
    if (_fact[0].x == 0) prepare();
    return _inv_fact[x];
  }

  mod_int choose(mod_int y) {
    assert(y.x <= x);
    return this->fact() * y.inv_fact() * mod_int(x - y.x).inv_fact();
  }

  static mod_int _inv[TABLE_SIZE + 1];

  static mod_int _fact[TABLE_SIZE + 1];

  static mod_int _inv_fact[TABLE_SIZE + 1];

  static void prepare() {
    _inv[1] = 1;
    for (int i = 2; i <= (int)TABLE_SIZE; ++i) {
      _inv[i] = 1LL * _inv[MODULO % i].x * (MODULO - MODULO / i) % MODULO;
    }
    _fact[0] = 1;
    for (unsigned i = 1; i <= TABLE_SIZE; ++i) {
      _fact[i] = _fact[i - 1] * int(i);
    }
    _inv_fact[TABLE_SIZE] = _fact[TABLE_SIZE].inv();
    for (int i = (int)TABLE_SIZE - 1; i >= 0; --i) {
      _inv_fact[i] = _inv_fact[i + 1] * (i + 1);
    }
  }
};

template <int M, unsigned F>
std::ostream &operator<<(std::ostream &os, const mod_int<M, F> &rhs) {
  return os << rhs.x;
}

template <int M, unsigned F>
std::istream &operator>>(std::istream &is, mod_int<M, F> &rhs) {
  long long s;
  is >> s;
  rhs = mod_int<M, F>(s);
  return is;
}

template <int M, unsigned F>
mod_int<M, F> mod_int<M, F>::_inv[TABLE_SIZE + 1];

template <int M, unsigned F>
mod_int<M, F> mod_int<M, F>::_fact[TABLE_SIZE + 1];

template <int M, unsigned F>
mod_int<M, F> mod_int<M, F>::_inv_fact[TABLE_SIZE + 1];

template <int M, unsigned F>
bool operator==(const mod_int<M, F> &lhs, const mod_int<M, F> &rhs) {
  return lhs.x == rhs.x;
}

template <int M, unsigned F>
bool operator!=(const mod_int<M, F> &lhs, const mod_int<M, F> &rhs) {
  return !(lhs == rhs);
}

const int MF = 1000010;
const int MOD = 1000000007;

using mint = mod_int<MOD, MF>;

mint binom(int n, int r) { return (r < 0 || r > n || n < 0) ? 0 : mint(n).choose(r); }

mint fact(int n) { return mint(n).fact(); }

mint inv_fact(int n) { return mint(n).inv_fact(); }

#define int long long
#define INF 100000000000000000

struct sg {
  int n;
  vector<int> table;
  vector<int> node;
  vector<bool> need;
  sg(vector<int> v){
    table.resize(1000010, 0);
    int cnt = 1;
    for(int i=1;i<1000010;i++){
      for(int j =i;j<1000010;j+=i)table[j]++;
    }
    int sz = v.size();
    n=1;
    while(n<sz)n*=2;
    node.resize(n*2-1,0);
    need.resize(n*2-1,false);

    for(int i=0;i<sz;i++)node[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--)node[i]=node[2*i+1]+node[2*i+2];
  }

  int get(int a, int b, int k=0, int l=0, int r=-1) {
    if(r < 0) r = n;
    if(r <= a || b <= l) return 0;
    if(a <= l && r <= b) return node[k];
    int vl = get(a, b, 2*k+1, l, (l+r)/2);
    int vr = get(a, b, 2*k+2, (l+r)/2, r);
    return vl+vr;
  }
  int calc(int a){
    return table[a];
  }
  bool q(int a, int b, int k=0, int l=0, int r=-1) {
    if(need[k])return need[k];
    if(r < 0) r = n;
    if(r <= a || b <= l) return need[k];
    if(k>=n-1){
      node[k]=calc(node[k]);
      int val = node[k];
      int x = k;
      while(x>0){
	x=(x-1)/2;
	node[x]=node[2*x+1]+node[2*x+2];
      }
      if(val<=2)need[k]=true;
      return need[k];
    }
    bool vl = q(a, b, 2*k+1, l, (l+r)/2);
    bool vr = q(a, b, 2*k+2, (l+r)/2, r);
    if(vl&&vr)need[k]=true;
    return need[k];
  }

  void out(){
    cout<<node<<endl;
    cout<<need<<endl;
  }
};

signed main(){
  while(1){
    string s;
    getline(cin, s);
    if(s==".")break;
    vector<int> v;
    lp(i,s.size()){
      if(s[i]=='(')v.push_back(1);
      if(s[i]==')')v.push_back(-1);
      if(s[i]=='[')v.push_back(2);
      if(s[i]==']')v.push_back(-2);
    }
    
    while(1){
      //cout<<v<<endl;
      vector<int> res;
      lp(i,v.size()){
	if(i!=v.size()-1&&v[i]+v[i+1]==0&&v[i]>0){
	  i++;
	  continue;
	}
	res.push_back(v[i]);
      }
      if(v==res)break;
      v=res;
    }
    if(v.empty())cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 15108
final_rank: 12

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

using namespace std;

int main()
{
	string s;

	while (getline(cin, s)) {

		if (s == ".") break;

		stack<char> j;
		bool f = true;

		for (auto c : s) {
			if (c == '(') { f = false; j.push('('); }
			if (c == '[') { f = false; j.push('['); }

			if (c == ')' && j.size() == 0) {
				f = false;
				break;
			}
			else if (c == ')' && j.top() != '(') {
				f = false;
				break;
			}
			else if (c == ')') { f = true; j.pop(); }

			if (c == ']' && j.size() == 0) {
				f = false;
				break;
			}
			else if (c == ']' && j.top() != '[') {
				f = false;
				break;
			}
			else if (c == ']') { f = true; j.pop(); }
		}

		if (f&&!j.size()) cout << "yes" << endl;
		else cout << "no" << endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3216
final_rank: 8

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

int dp[105][105];

bool ok(string &s,int l,int na){
  if(~dp[l][na])return dp[l][na];
  if(na&1)return false;
  if(na==0)return true;
  for(int i=2;i<na;i+=2)if(ok(s,l,i)&&ok(s,l+i,na-i))return dp[l][na]=true;
  if(s[l]=='('&&s[l+na-1]==')'&&ok(s,l+1,na-2))return dp[l][na]=true;
  if(s[l]=='['&&s[l+na-1]==']'&&ok(s,l+1,na-2))return dp[l][na]=true;
  return dp[l][na]=false;
}

signed main(){
  string s;
  while(getline(cin,s),s!="."){
    memset(dp,-1,sizeof(dp));
    string u;
    for(char p:s)if(p=='('||p==')'||p=='['||p==']')u+=p;
    if(ok(u,0,u.size()))cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
}
accuracy: 1
time_ms: 30
memory_kb: 3184
final_rank: 13

code_snippet: #include<iostream>
#include<stack>
#include<string>
using namespace std;
int main(){
  while(1){
    string s;
    getline(cin,s);
    if(s=="."){
      break;
    }
    bool flg=true;

    int n=(int)s.size();
    stack<char> st;
    for(int i=0;i<n;i++){
      if(s[i]=='['){
        st.push(s[i]);
        continue;
      }
      if(s[i]=='('){
        st.push(s[i]);
        continue;
      }
      if(s[i]==']'){
        if(st.empty()){
          flg=false;
          break;
        }
        if(st.top()=='['){
          st.pop();
          continue;
        }
        flg=false;
        break;
      }
      if(s[i]==')'){
        if(st.empty()){
          flg=false;
          break;
        }
        if(st.top()=='('){
          st.pop();
          continue;
        }
        flg=false;
        break;
      }
    }
    if(!st.empty()){
      flg=false;
    }

    cout<<(flg?"yes":"no")<<'\n';
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3156
final_rank: 3

code_snippet: #include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=a;i>=n;i--)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
char kako[4]={'(',')','[',']'};
int main(){
    string s;
    while(true){

        getline(cin,s);

        if(s.size()==1&&s[0]=='.'){
            break;
        }
        vector<int> v;

//        rep(i,0,s.size()){
//            rep(p,0,4){
//                if(kako[p]==s[i]){
//                    v.push_back(p);
//                }
//            }
//        }
//        while(true){
//            cin>>s;

            rep(i,0,s.size()){
                rep(p,0,4){
                    if(kako[p]==s[i]){
                        v.push_back(p);
                    }
                }
            }
       //     if(s[s.size()-1]=='.')break;
      //  }


        stack<int> s;



        rep(i,0,v.size()){
            if(s.empty()){
                s.push(v[i]);
            }else{
                int tp=s.top();
                if(tp==0&&v[i]==1){
                    s.pop();
                }else if(tp==2&&v[i]==3){
                    s.pop();
                }else{
                    s.push(v[i]);
                }
            }

        }
        if(s.size()==0){
            cout<<"yes"<<endl;
        }else{
            cout<<"no"<<endl;
        }


    }


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