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<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL sum = a;
    LL res = 1;
    while(b){
        if(b&1){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}

vector<int> makesosu(int n){
    vector<char> line(n*2+1, 1);
    vector<int> res;
    for(int i=2;i<=n*2;++i){
        if(line[i]){
            res.push_back(i);
            for(int j=i*2;j<=n*2;j+=i)line[j]=0;
        }
    }
    return res;
}

int main(){
    string str;
    while(true){
        getline(cin, str);
        if(str==".")break;
        bool flag=true;
        stack<char> st;
        foreach(i, str){
            if(i=='('){
                st.push(i);
            }else if(i=='['){
                st.push(i);
            }else if(i==')'){
                if(st.empty()){
                    flag=false;
                    break;
                }
                if(st.top()=='['){
                    flag=false;
                    break;
                }
                st.pop();
            }else if(i==']'){
                if(st.empty()){
                    flag=false;
                    break;
                }
                if(st.top()=='('){
                    flag=false;
                    break;
                }
                st.pop();
            }
        }
        if(st.size())flag=false;
        cout << (flag?"yes":"no") << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    string s;
    while(getline(cin, s)) {
        if(s == ".") break;
        bool ok = true;
        stack<char> st;
        rep(i,0,s.length()) {
            if(s[i] == '(') st.push('(');
            else if(s[i] == '[') st.push('[');
            else if(s[i] == ')') {
                // printf("1: top = %c\n", st.top());
                if(!st.empty() && st.top() == '(') st.pop();
                else ok = false;
            }
            else if(s[i] == ']') {
                // printf("2: top = %c\n", st.top());
                if(!st.empty() && st.top() == '[') st.pop();
                else ok = false;
            }
        }
        if(!ok) cout << "no" << endl;
        else cout << "yes" << endl;
    }
    return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<string>
using namespace std;

int main(){

	bool F=true;
while(F){char str[250]={},ch;
	for(int i=0;i<245;i++)
	{scanf("%c",&ch);if(ch=='.'&&i==0){F=false;break;}
	if(ch=='.'){break;}
	str[i]=ch;}
	if(F=='.'){break;}
	int ks=0,kl=0,ms=0,ml=0;
	bool f=true;int p[200]={};int y=0;
	for(int i=0;i<200;i++)
	{if(str[0]=='.')F=false;
		//cout<<i<<"#"<<y<<"#"<<p[y]<<endl;
		if(str[i]=='('){ms++;y++;p[y]=1;}
	else if(str[i]=='['){ks++;y++;p[y]=5;}
	else if(str[i]==')'){ml++;if(p[y]==5||p[y]==0){f=false;}if(ms<ml){f=false;}y--;}//cout<<i<<" ";}
	else if(str[i]==']'){kl++;if(p[y]==1||p[y]==0){f=false;}if(ks<kl){f=false;}y--;}
	}
	if(F==true){
	if(f!=false&&ms==ml&&ks==kl)cout<<"yes"<<endl;
	else{cout<<"no"<<endl;//<<ms<<ml<<ks<<kl<<endl;
	}
	}
}


return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define N_PRIME 1000000007
#define ll int64_t

void solve(){
    string s;
    getline(cin,s);
    if( s==".")exit(0);
    stack<int> t;
    
    
    for(int i = 0 ; i < s.size() ; i++ ){
        if( s[i] == '(' ){
            t.push(0);
        }else if( s[i] == '[' ){
            t.push(1);
        }else if( s[i] == ')' ){
            if( t.size() == 0 || t.top() != 0 ){
                cout << "no" << endl;
                return ;
            }else{
                t.pop();
            }
        }else if( s[i] == ']' ){
            if( t.size() == 0 || t.top() != 1 ){
                cout << "no" << endl;
                return ;
            }else{
                t.pop();
            }
        }
    }
    
    cout << "yes"<<endl;
    return ;
}
int main(void){
    while(true)solve();
    return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
	string s;
	while(getline(cin,s)){
		if(s==".") break;
		int a[100][100]={0},k1=0,k2=0,b=0,c1=0,c2=0,c3=0,c4=0;
		a[50][50]=1;
		for(int i=0;i<s.size();i++){
			if(s[i]=='('){
				k1++;
				a[50+k1][50+k2]++;
				c1++;
			}
			else if(s[i]==')'){
				a[50+k1][50+k2]=0;
				k1--;
				if(a[50+k1][50+k2]==0){
					b++;
				}
				c2++;
			}
			else if(s[i]=='['){
				k2++;
				a[50+k1][50+k2]++;
				c3++;
			}
			else if(s[i]==']'){
				a[50+k1][50+k2]=0;
				k2--;
				if(a[50+k1][50+k2]==0){
					b++;
				}
				c4++;
			}
		}
		if(b==0&&c1==c2&&c3==c4){
			cout<<"yes"<<endl;
		}
		else{
			cout<<"no"<<endl;
		}
	}
    return 0;
}