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 <algorithm>
#include <string>
#include <stack>
using namespace std;

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for(int i = m; i < (n); ++i)
#define pb push_back

int main()
{
    string str;
    
    while(getline(cin, str) && str != ".")
    {
        int t;
        stack<int> st;
        
        rep(i, str.size()) {
            switch (str[i]) {
                case '(':
                    st.push(1);
                    break;
                case '[':
                    st.push(2);
                    break;
                case ')':
                    if(st.empty()) goto no;
                    t = st.top(); st.pop();
                    if(t != 1) goto no;
                    break; 
                case ']':
                    if(st.empty()) goto no;
                    t = st.top(); st.pop();
                    if(t != 2) goto no;
                    break; 
            }
        }
        if(!st.empty()) goto no;
        cout << "yes" << endl;
        continue;
    no:;
        cout << "no" << endl;
    }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	string a;
	char b[101];
	while(true){
	int count=0;
	getline(cin,a);
	if(a==".")
		break;
	for(int i=0;i<a.size();i++){
		if(a[i]=='('||a[i]==')'||a[i]=='['||a[i]==']'){
			b[count]=a[i];
			count++;
		}
	}
	int check;
	while(true){
		check=count;
		for(int i=0;i<count-1;i++){
			if((b[i]=='('&&b[i+1]==')')||(b[i]=='['&&b[i+1]==']')){
				for(int j=0;j<count;j++){
					if(j<i)
						b[j]=b[j];
					if(j>i+1)
						b[j-2]=b[j];
				}
				count-=2;
			}
		}
		if(count==check)
			break;
	}
	if(count==0)
		cout<<"yes"<<endl;
	else
		cout<<"no"<<endl;
	}
    return 0;
}

C++: #include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int main(){
	string s;
	while(getline(cin, s), s != "."){
		vi v;
		bool ok = 1;
		rep(i, s.size()){
			if(s[i] == '(') v.pb(1);
			if(s[i] == ')'){
				if(!v.size() || v.back() != 1) ok = 0;
				else v.pop_back();
			}
			if(s[i] == '[') v.pb(2);
			if(s[i] == ']'){
				if(!v.size() || v.back() != 2) ok = 0;
				else v.pop_back();
			}
			if(!ok) break;
		}
		cout << (ok && !v.size() ? "yes" : "no") << endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<math.h>
#include<string>
#include<stack>

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

using namespace std;

string str;

void solve() {
	stack<char> sta;
	rep(i,str.size()) {
		if(str[i]=='('||str[i]=='[') sta.push(str[i]);
		if(str[i]==')') {
			if(sta.empty()) {
				cout<<"no"<<endl;
				return;
			}
			if(sta.top()!='(') {
				cout<<"no"<<endl;
				//cout<<i<<endl;
				return;
			}
			else {
				sta.pop();
			}
		}
		if(str[i]==']') {
			if(sta.empty()) {
				cout<<"no"<<endl;
				return;
			}
			if(sta.top()!='[') {
				cout<<"no"<<endl;
				//cout<<i<<endl;
				return;
			}
			else {
				sta.pop();
			}
		}
	}
	if(sta.empty()) {
		cout<<"yes"<<endl;
	}
	else
	{
		cout<<"no"<<endl;
	}

}

int main() {
	while(getline(cin,str)) {
		if(str==".") return 0;
		solve();
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}



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

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

using namespace std;

bool is_balanced(string str) {
    stack<char> nest;
    for (int i=0; i<(int)str.length(); i++) {
        switch (str[i]) {
            case '(':
                nest.push('(');
                break;
            case '[':
                nest.push('[');
                break;
            case ')':
                if (!nest.empty() && nest.top() == '(') {
                    nest.pop();
                }
                else {
                    return false;
                }
                break;
            case ']':
                if (!nest.empty() && nest.top() == '[') {
                    nest.pop();
                }
                else {
                    return false;
                }
                break;
        }
    }
    return nest.empty();
}

int main() {
    string s;
    while (true) {
        getline(cin, s);
        if (s == ".") {
            return 0;
        }
        if (is_balanced(s)) {
            cout << "yes" << endl;
        }
        else {
            cout << "no" << endl;
        }
    }
}