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 <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
 

int main(){
	string s;
	while(getline(cin,s)){
		if(s==".") break;
		stack<char> st;
		bool flag = true;
		for(char c : s){
			if(c == '(' || c == '[') st.push(c);
			else if(c ==')' || c == ']') {
				if(st.empty() || (c != st.top() + (c == '('?1:2))){
					flag =false;
					break;
				}
				st.pop();
			} 
		}
		cout<<(flag?"yes":"no")<<endl;
	}
}

C++: #include <iostream>
#include <stack>
#include <sstream>
using namespace std;

stack<char> st1, st2;
string str;
bool flag;

void parse(string str){
  for(int i = 0; i < str.size(); i++){
    if(str[i] == '(' || str[i] == ')' || str[i] == '[' || str[i] == ']') st2.push(str[i]);
  }
  while(!st2.empty()){
    st1.push(st2.top());
    st2.pop();
  }
}

void init(){
  while(!st1.empty()){
    st1.pop();
  }
  while(!st2.empty()){
    st2.pop();
  }
}

int main(void){
  while(true){
    flag = false;
    getline(cin, str);
    if(str.size() == 1 && str[0] == '.') break;
    init();
    parse(str);
    if(!st1.empty()){
      st2.push(st1.top());
      st1.pop();
    }else{
      flag = true;
    }
    while(!st1.empty()){
      char ch = st1.top();
      st1.pop();
      if(!(ch == ')' && st2.top() == '(') && !(ch == ']' && st2.top() == '[')){
        st2.push(ch);
      }else{
        st2.pop();
      }
    }
    if(st1.empty() && st2.empty()) flag = true;
    if(flag) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <vector>
using namespace std;

int main()
{
	string s;
	while (true)
	{
		getline(cin, s);
		if (s == ".")	break;

		stack<int> data, data2;
		
		for (auto && x : s)
		{
			if (x == '[')
				data.emplace(data2.size());
			else if (x == ']')
			{
				if (data.empty())
				{
					cout << "no" << endl;
					goto END;
				}
				else if (data2.size() != data.top())
				{
					cout << "no" << endl;
					goto END;
				}

				data.pop();
			}
			else if (x == '(')
				data2.emplace(data.size());
			else if (x == ')')
			{
				if (data2.empty())
				{
					cout << "no" << endl;
					goto END;
				}
				else if (data.size() != data2.top())
				{
					cout << "no" << endl;
					goto END;
				}
				data2.pop();
			}
		}

		if (data.empty() && data2.empty())
			cout << "yes" << endl;
		else
			cout << "no" << endl;

	END:;

	}

	return 0;
}

C++: // 2013/09/17 Tazoe

#include <iostream>
#include <string>
#include <stack>
using namespace std;

int main()
{
	while(true){
		string S;
		getline(cin, S);

		if(S==".")
			break;

		stack<char> stk;

		bool err = false;

		for(int i=0; i<S.size(); i++){
			switch(S[i]){
				case '(':
				case '[':
					stk.push(S[i]);
					break;
				case ')':
					if(!stk.empty() && stk.top()=='('){
						stk.pop();
					}
					else{
						err = true;
					}
					break;
				case ']':
					if(!stk.empty() && stk.top()=='['){
						stk.pop();
					}
					else{
						err = true;
					}
					break;
			}

			if(err)
				break;
		}

		if(!err && stk.empty()){
			cout << "yes" << endl;
		}
		else{
			cout << "no" << endl;
		}
	}

	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    string S;
    getline(cin, S);
    while(S.length() - 1){
        stack<char> st;
        bool flag = 0;
        for(char c:S){
            if(c == '[' || c == '(')st.push(c);
            if(c == ']' || c == ')'){
                if(st.size() == 0){
                    flag = 1;
                    break;

                }
                char t = st.top();
                st.pop();
                if(!(t == '[' && c == ']' || t == '(' && c == ')')){
                    flag = 1;
                    break;
                }
            }
        }
        if(!flag)cout << "yes" << endl;
        else    cout << "no" << endl;
        getline(cin, S);
    }
}

C++: #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    string S;
    getline(cin, S);
    while(S.length() - 1){
        stack<char> st;
        bool flag = 0;
        for(char c:S){
            if(c == '[' || c == '(')st.push(c);
            if(c == ']' || c == ')'){
                if(st.size() == 0){
                    flag = 1;
                    break;
                    
                }
                char t = st.top();
                st.pop();
                if(c != t){
                    flag = 1;
                    break;
                }
            }
        }
        if(!flag)cout << "YES" << endl;
        else    cout << "NO" << endl;
        getline(cin, S);
    }
}

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

int main(){
	stack<int>st;
	string s;
	while(1){
		cin>>s;
		for(int i=0;i<s.size();i++){
			if(s[i]=='(') st.push(0);
			if(s[i]=='[') st.push(1);
			if(s[i]=='('){
				int num=st.top();
				if(num==0){
					st.pop();
				}
			}
			if(s[i]==']'){
				int num=st.top();
				if(num==1){
					st.pop();
				}
			}
		}
		if(st.empty()) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES 
#include <iomanip> 
#include <cmath>  
#include<iostream>
#include <fstream>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl


int main() {
	while (1) {
		string input;
		stack<char> st;
		getline(cin, input);
		if (input.length() == 1 && input[0] == '.')break;
		repi(i, 0, input.length()) {
			char ch = input[i];
			if (ch == '(' || ch == '[') st.push(ch);
			if (ch == ')' || ch == ']') {
				if (st.size() == 0 || (st.top()=='(' && ch== ']') || (st.top() == '[' && ch == ')')) {
					wrln("no");
					break;
				}
				else {
					st.pop();
				}
			}
			if (i == input.length() - 1) {
				if (st.size() == 0) wrln("yes");
				else wrln("no");
			}
		}
	}
	return 0;
}