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>

char c[3] = ")]";

bool search(char* s,int* i){
	int b = 0;
	if(s[(*i)] == '[')
		b = 1;
	for((*i)++; s[(*i)] != '.'; (*i)++){
		if(s[(*i)] == c[b])
			return true;
		else if(s[(*i)] == c[1-b])
			return false;
		else if(s[(*i)] == '(' || s[(*i)] == '[')
			if(!search(s, i))
				return false;
	}
	return false;
}

int main(){
	using std::cout;
	char input[128];
	int i;
	for(;;){
		std::cin.getline(input, sizeof(input));
		if(input[0] == '.')
			return 0;
		for(i=0; input[i] != '.'; i++){
			if(input[i] == '(' || input[i] == '['){
				if(!search(input, &i))
					goto NO;
			}else if(input[i] == ']' || input[i] == ')')
				goto NO;
		}
		std::cout << "yes\n";
		continue;
NO:;
		std::cout << "no\n";
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

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

    string s;
    while (getline(cin, s), s[0] != '.') {
        stack<char> stk;
        stk.push('#');
        for (auto c : s) {
            if (c == '(' || c == '[') {
                stk.push(c);
            } else if ((stk.top() == '(' && c == ')') || (stk.top() == '[' && c == ']')) {
                stk.pop();
            }
        }
        cout << (stk.size() == 1 ? "yes" : "no") << endl;
    }
}

C++: #include<stdio.h>
char s[110],a[110],b,i,t;main(){while(fgets(s,110,stdin)){if(s[1]=='\n'&&s[0]==46)break;for(t=1,b=0,i=0;s[i]&&t;++i){if(s[i]==40||s[i]==91) a[b++]=s[i];else if(s[i]==41||s[i]==93) {if(!b){t=0;break;}if((s[i]==41&&a[b-1]==40)||(s[i]==93&&a[b-1]==91)) --b;else t=0;}}puts(((t&&!b)?1:0)?"yes":"no");}}

C++: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define FORR(i,a,b) for (int i=a; i>=b; i--)

typedef long long ll;

int main(void){
	string str;

	while(getline(cin,str)){
		if (str.size()==1 && str[0]=='.') break;
		bool f=1;
		stack<int> st;
		REP(i,str.length()){
			switch(str[i]){
				case '(' :
					st.push(0);
					break;
				case '[' :
					st.push(1);
					break;
				case ')' :
					if (st.empty()){
						f=0;
						break;
					}
					if (st.top()==0)
						st.pop();
					else
						f=0;
					break;
				case ']' :
					if (st.empty()){
						f=0;
						break;
					}
					if (st.top()==1)
						st.pop();
					else
						f=0;
					break;
			}
		}
		if (!st.empty())
			f=0;

		if (f)
			cout << "yes" << endl;
		else 
			cout << "no" << endl;
	}
	

	return 0;
}

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

using namespace std;

int main(){
		while(1){
				char a[110];
				fgets(a,110,stdin);
				if(strcmp(a,".")==0)break;
				int n=strlen(a);
				int i;
				stack<int> st;
				for(i=0;i<n;i++){
						if(a[i]=='['){
								st.push(1);
						}else if(a[i]==']'){
								if(st.empty()==1){
										cout<<"no"<<endl;
										break;
								}
								if(st.top()==1){
										st.pop();
								}else{
										cout<<"no"<<endl;
										break;
								}
						}else if(a[i]=='('){
								st.push(2);
						}else if(a[i]==')'){
								if(st.empty()==1){
										cout<<"no"<<endl;
										break;
								}
								if(st.top()==2){
										st.pop();
								}else{
										cout<<"no"<<endl;
										break;
								}
						}
				}
				if(i==n)cout<<"yes"<<endl;
		}
		return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
int main() {
    string s;
    while (getline(cin, s) && s != ".") {
        string t;
        rep(i, s.size()) {
            if (s[i] == '[' || s[i] == ']' || s[i] == '(' || s[i] == ')') t += s[i];
        }
        if (t == "") {
            cout << "yes" << endl;
            continue;
        }
        //cout << t << endl;
        int table[t.size()];
        rep(i, t.size()) table[i] = 0;
        rep(i, t.size()) {
            //cout << t[i] << endl;
            if (t[i] == '[') table[i] = 1;
            else if (t[i] == ']') table[i] = 2;
            else if (t[i] == '(') table[i] = 3;
            else table[i] = 4;
        }
        /*
        rep(i, t.size()) cout << table[i] << " ";
        cout << endl;
        */
        int flg = 0;
        rep(i, t.size()) {
            if (t[i] == ')') {
                for (int j = i - 1; j >= 0; --j) {
                    if (table[j] == 3) {
                        table[j] = 0;
                        table[i] = 0;
                        break;
                    } else if (table[j] == 1){
                        cout << "no" << endl;
                        flg = 1;
                        break;
                    }
                    if (j == 0) {
                        cout << "no" << endl;
                        flg = 1;
                        break;
                    }
                }
            } else if (t[i] == ']') {
                for (int j = i - 1; j >= 0; --j) {
                    if (table[j] == 1) {
                        table[j] = 0;
                        table[i] = 0;
                        break;
                    } else if (table[j] == 3) {
                        cout << "no" << endl;
                        flg = 1;
                        break;
                    }
                    if (j == 0) {
                        cout << "no" << endl;
                        flg = 1;
                        break;
                    }
                }
                
            }
            if (flg) break;
            /*
            rep(i, t.size()) cout << table[i] << " ";
            cout << endl;
             */
        }
        if (flg == 0) {
            rep(i, t.size()) {
                if (table[i] > 0) {
                    cout << "no" << endl;
                    break;
                }
                if (i == t.size() - 1) cout << "yes" << endl;
            }
        }
    }
    
    
}