Go: package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Buffer(make([]byte, 0), 1000000009)

	for {
		var s string
		s = nextString()
		if s == "." {
			break
		}
		var st []byte
		is_valid := true

		for _, value := range s {
			if value == '(' {
				st = append(st, byte(value))
			}
			if value == '[' {
				st = append(st, byte(value))
			}
			if value == ')' {
				if len(st) == 0 || st[len(st)-1] != '(' {
					is_valid = false
					break
				} else {
					st = st[:len(st)-1]
				}
			}
			if value == ']' {
				if len(st) == 0 || st[len(st)-1] != '[' {
					is_valid = false
					break
				} else {
					st = st[:len(st)-1]
				}
			}
		}
		if len(st) != 0 {
			is_valid = false
		}
		if is_valid {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

C++: #include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

string s;

int main(){
	while(getline(cin,s),s!="."){
		stack<int> S;
		int ok=1;
		rep(i,s.sz){
			if(s[i]=='(')S.push(0);
			if(s[i]=='[')S.push(1);
			if(s[i]==')'){
				if(!S.sz||S.top()==1){ok=0;break;}
				S.pop();
			}
			if(s[i]==']'){
				if(!S.sz||S.top()==0){ok=0;break;}
				S.pop();
			}
		}
		cout<<(ok&&!S.sz?"yes":"no")<<endl;
	}
}

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

int main() {
  string s;
  while (getline(cin, s), !(s.length() == 1 && s[0] == '.')) {
    int n = s.length();
    vector<int> imos_m(105, 0), imos_k(105, 0);
    REP(i, n) {
      if (s[i] == '(') imos_m[i + 1]++;
      if (s[i] == ')') imos_m[i + 1]--;
      if (s[i] == '[') imos_k[i + 1]++;
      if (s[i] == ']') imos_k[i + 1]--;
    }
    REP(i, 104) {
      imos_m[i + 1] += imos_m[i];
      imos_k[i + 1] += imos_k[i];
    }
    bool ans = true;
    REP(i, 105) {
      if (imos_m[i] < 0) ans = false;
      if (imos_k[i] < 0) ans = false;
    }
    if (imos_m[104] != 0) ans = false;
    if (imos_k[104] != 0) ans = false;
    REP(l, 105) REP(r, 105) {
      if (l >= r) continue;
      if (l - 1 < 0) continue;
      if (105 <= r) continue;
      if (imos_m[l - 1] < imos_m[l] && imos_m[r - 1] > imos_m[r] && imos_m[l] == imos_m[r - 1] && imos_k[l] != imos_k[r - 1]) ans = false;
      if (imos_m[l] > imos_m[r]) break;
    }
    REP(l, 105) REP(r, 105) {
      if (l >= r) continue;
      if (l - 1 < 0) continue;
      if (105 <= r) continue;
      if (imos_k[l - 1] < imos_k[l] && imos_k[r - 1] > imos_k[r] && imos_k[l] == imos_k[r - 1] && imos_m[l] != imos_m[r - 1]) ans = false;
      if (imos_k[l] > imos_k[r]) break;
    }
    cout << ((ans) ? "yes" : "no") << endl;
  }
}

C++: #include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>

#define TEST 1

using namespace std;
int parse(string str){
    if(str.length()==0)return 0;
    switch(str[0]){
        case '(':{
            
            int sub=parse(str.substr(1));
            if(sub==-1)return -1;
            int p1=1+sub;
            if(str[p1]==')'){
                int sub2=parse(str.substr(p1+1));
                return p1+sub2+1;
            }
            return -1;
        }
        case '[':{
            int sub=parse(str.substr(1));
            if(sub==-1)return -1;
            int p1=1+sub;
            if(str[p1]==']'){
                int sub2=parse(str.substr(p1+1));
                return p1+sub2+1;
            }
            return -1;
        }
        case ')':
        case ']':
            return 0;
        default:
            int res=parse(str.substr(1));
            return res==-1?-1:res+1;
    }
}

int main(){
    string line;
    while (getline(cin,line)&&line!=".") {
        int len=parse(line);
        cout<<(len==line.length()?"yes":"no")<<endl;
    }
}

C++: #include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i, n) for(int i=0; i<(n); ++i)

int main(void){
    string s;
    while(getline(cin, s) && s!=".") {
        int rb=0, sb=0;
        bool ok = true;
        int l, r=s.size()-1;
        for(int l=0; l<=r; l++) {
            if(s[l] == '(') {
                for(; r>=0 && s[r]!=')'; r--) ;
                if(r < l) {
                    ok=false;
                    break;
                }
            }
            if(s[l] == '[') {
                for(; r>=0 && s[r]!=']'; r--) ;
                if(r < l) {
                    ok=false;
                    break;
                }
            }
        }
        if(ok) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}

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

int main(){
	string s;
	while(getline(cin,s) and s!="."){
		string ans="yes";
		int n=s.size();
		stack<bool> last;
		rep(i,n){
			if(s[i]=='(') last.push(0);
			if(s[i]=='[') last.push(1);
			if(s[i]==')'){
				if(last.empty()) ans="no";
				else if(!last.top()) last.pop();
				else ans="no";
			}
			if(s[i]==']'){
				if(last.empty()) ans="no";
				else if(last.top()) last.pop();
				else ans="no";
			}
		}
		if(!last.empty()) ans="no";
		cout<<ans<<endl;
	}
    return 0;
}

C++: #include <cstdio>
#include<iostream>
#include<stack>
#include <cstring>

using namespace std;

stack<char> stk;

char s[101];

int main(void){
	int i;
	
	while(1) {
		fgets(s,100,stdin);
		if(s[0] == '.' && s[1] == '\0') break;

		while(!stk.empty())
			stk.pop();
		int flag = 0;
		int l = strlen(s);
		int m = 0, k = 0;
		char past = '\0';

		for(i = 0; i < l && flag == 0; i++) {
			if( s[i] == '(' ) {
				stk.push('(');
			}
			if( s[i] == ')' ) {
				if(stk.empty()){
					flag=1;
					break;
				}
				if(stk.top() == '(') stk.pop();
				else flag = 1;
			}
			if( s[i] == '[' ) {
				stk.push('[');
			}
			if( s[i] == ']' ) {
				if(stk.empty()){
					flag=1;
					break;
				}
				if(stk.top() == '[') stk.pop();
				else flag = 1;
			}

		}

		if( !stk.empty() ) flag = 1;

		if( flag == 0 ) printf("yes\n");
		else printf("no\n");

	}

	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<stack>
#include<string>

#define loop(lp) for(int i = 0;i < lp;i++)

using namespace std;       
int main(){
  string s;
  stack<char> a;
  int i=0,j=0;
  while(true){
    getline(cin,s);
    while(s[i] != '.'){
      
      if(s[i] == '('){
	a.push('(');  
      }else if(s[i] == ')'){
	if(a.size() == 0){
	  j = 1;
	  break;
	}
	if(a.top() == '('){
	  a.pop();  
	}else{
	  j = 1;
	  break;
	}
      }else if(s[i] == '[' ){
	a.push('[');  
      }else if(s[i] == ']'){
	if(a.size() == 0){
	  j = 1;
	  break;
	}
	if(a.top() == '['){
	  a.pop();  
	}else{
	  j = 1;
	  break;
	}
      }
      i++;
    }
    if(i == 0){
      break;
    }
    if(a.size() == 0 && j != 1){
	cout <<"yes"<<endl;
      }else{
	cout <<"no"<<endl;   
      }
    i = 0;
    while(a.size() != 0){
      a.pop();
    }
    j = 0;
  }
    
    
    return 0;
}