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 rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double eps = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1};

int main() {
	string S;
	while (getline(cin, S), S != ".") {
		vector<char> tmp;
		rep(i, S.size()) {
			if (S[i] == '(' || S[i] == ')' || S[i] == '[' || S[i] == ']') tmp.push_back(S[i]);
		}
		stack<char> st;
		bool ans = true;
		rep(i, tmp.size()) {
			if (st.empty() || tmp[i] == '(' || tmp[i] == '[') st.push(tmp[i]);
			else if ((st.top() == '(' && tmp[i] == ')') || (st.top() == '[' && tmp[i] == ']')) st.pop();
			else {
				ans = false;
				break;
			}
		}
		cout << (ans && st.empty() ? "yes" : "no") << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


int main(){
	for (string s; getline(cin,s), s != "."; ) {
		stack<char> st;
		bool ok = true;
		rep (i, s.size()) {
			if (s[i] == ')') {
				if (st.size() == 0 || st.top() == '[') {
					ok = false;
					break;
				}
				st.pop();
			}
			else if (s[i] == ']') {
				if (st.size() == 0 || st.top() == '(') {
					ok = false;
					break;
				}
				st.pop();
			}
			else if(s[i] == '(' || s[i] == '[') {
				st.push(s[i]);
			}
		}
		if (ok && st.size() == 0) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int q,p;
	q=p=0;
	char a;
	while(a = getchar())
	{if(a=='\n')
		if(q==p&&q==0){
			cout<<"yes"<<endl; q=p=0;
		}
		else{
			cout<<"no"<<endl; q=p=0;
		}
		
	else if(a=='(') q++;
	else if(a==')')q--;
	else if(a=='[')p++;
	else if(a==']')p--;
	}
}

C++: #include "bits/stdc++.h"

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define mod 1000000007
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes printf("yes\n")
#define no printf("no\n")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

const int INF=1LL<<55;

string s;

void solve(){

    stack<int> st;
    rep(i, s.size()){
        if(s[i]=='('){
            st.push(0);
        }
        if(s[i]=='['){
            st.push(1);
        }
        if(s[i]==')'){
            if(st.empty() || st.top()!=0){
                no;
                return;
            }else{
                st.pop();
            }
        }
        if(s[i]==']'){
            if(st.empty() || st.top()!=1){
                no;
                return;
            }else{
                st.pop();
            }
        }
    }
    if(st.empty()) yes;
    else no;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    while(getline(cin,s),s!="."){
        solve();
    }

    return 0;
}

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

using std::cin;
using std::cout;
using std::endl;

int main(void) {
	std::string str;
	getline(cin, str);

	while (str[0] != '.' && str.length() != 0) {
		std::stack<int> check;
		bool much = true;
		for (int i = 0; i < str.length(); i++) {
			if (much) {
				if (str[i] == '(') {
					check.push(1);
				}
				if (str[i] == ')') {
					if (check.empty()) {
						much = false;
					} else {
						if (check.top()!=1) {
							much = false;
						}
						check.pop();
					}
				}
				if (str[i] == '[') {
					check.push(2);
				}
				if (str[i] == ']') {
					if (check.empty()) {
						much = false;
					} else {
						if (check.top()!=2) {
							much = false;
						}
						check.pop();
					}
				}
			}
		}
		if (much) {
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
		getline(cin, str);
	}

	return 0;
}

C++: #include<stack>
#include<vector>
#include<iostream>

using namespace std;
int main(){
	string str;
	while(getline(cin,str)&& str!="."){
		string ss;

		for(int i=0;i<str.size();i++)
			if(str[i]=='(' || str[i]==')' || str[i]=='[' || str[i]==']')
				ss+=str[i];
	
		stack<char> s;
		bool f=true;

		for(int i=0;i<ss.size();i++){

			if(ss.empty() || ss[i]=='(' || ss[i]=='[')
				s.push(ss[i]);

			else if( (s.top()=='(' && ss[i]==')') || (s.top()=='[' && ss[i]==']') )
					s.pop();
			else{
				f=false;
				break;
			}
		}
		cout << (f && s.empty()?"yes":"no") << endl;
	}
}

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

int main() {
	string s;
	while(1){
		getline(cin, s);
		if(s == ".")
			break;
		stack<char> k;
		bool ok = true;
		for(int i = 0; i < s.size(); ++i){
			if(s[i] == '('){
				k.push('(');
			}
			else if(s[i] == ')'){
				if(k.empty()){
					ok = false;
					break;
				}
				char c = k.top();
				k.pop();
				if(c != '('){
					ok = false;
					break;
				}
			}
			else if(s[i] == '['){
				k.push('[');
			}
			else if(s[i] == ']'){
				if(k.empty()){
					ok = false;
					break;
				}
				char c = k.top();
				k.pop();
				if(c != '['){
					ok = false;
					break;
				}
			}
		}
		if(k.empty() && ok){
			cout << "yes" << endl;
		}
		else{
			cout << "no" << endl;
		}
	}
	return 0;
}