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 <stack>

using namespace std;

int
main(int argc, const char *argv[])
{
    string str;    
    while (getline(cin, str)) {
        if (str == ".") break;     
        stack<char> sc;
        bool is_balanced = true;
        for (decltype(str.size()) i = 0; i != str.size(); ++i) {
            if (str[i] == '(' || str[i] == '[') sc.push(str[i]);
            else if (str[i] == ')') {
                if (!sc.empty()) {
                    char c = sc.top();
                    sc.pop();
                    if (c != '(') is_balanced = false;
                } else is_balanced = false;
            } else if (str[i] == ']') {
                if (!sc.empty()) {
                    char c = sc.top();
                    sc.pop();
                    if (c != '[') is_balanced = false;
                } else is_balanced = false;
            }
        }
        if (!sc.empty()) is_balanced = false;
        if (is_balanced) cout << "yes";
        else cout << "no";
        cout << endl;
    }

    return 0;
}

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

using namespace std;

vector<string> ans;

int main(){
	while(1){
		string str;
		getline(cin,str);
		
		if(str == ".")break; 
		
		vector<int> hmk;
		vector<int> hkk;
		bool balance = true;
		
		for(int i = 0;i < str.size();i++){
			if(!balance) break;
			if(str[i] == '(') hmk.push_back(i);
			if(str[i] == '[') hkk.push_back(i);
			if(str[i] == ')'){
				if(hmk.size() == 0) balance = false;
				else{
					for(int j = 0;j < hkk.size();j++){
						if(hmk.back() < hkk[j]){balance = false;break;}
					}
					hmk.pop_back();
				}
			}
			if(str[i] == ']'){
				if(hkk.size() == 0) balance = false;
				else{
					for(int j = 0;j < hmk.size();j++){
						if(hkk.back() < hmk[j]){balance = false;break;}
					}
					hkk.pop_back();
				}
			}
		}
		
		string yn;
		if(hmk.size() == 0 && hkk.size() == 0 && balance) yn = "yes";
		else yn = "no";
		
		ans.push_back(yn);
	}
	for(int i = 0;i < ans.size();i++){
		cout << ans[i] << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
	string S;
	int kakko_1=0;
	int kakko_2=0;
	string T;
	bool hantei=true;

	while(true)
	{
		hantei=true;
		kakko_1=0;
		kakko_2=0;

		getline(cin, S);

		if(S == ".") { break; }

		for(int i=0;i<S.size();i++){
			T=S[i];
			if(T=="("){
				kakko_1 ++;
			}
			if(T==")"){
				kakko_1 --;
			}
			if(T=="["){
				kakko_2 ++;
			}
			if(T=="]"){
				kakko_2 --;
			}
			if(kakko_1<0 || kakko_2<0){
				hantei=false;
			}
		}
		if(kakko_1!=0 || kakko_2!=0){
			hantei=false;
		}

		cout<<(hantei? "yes":"no")<<endl;
	}

	return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
string s;
main()
{
	while(getline(cin,s),s!=".")
	{
		stack<int>a,b;
		int ca=0,cb=0,f=0;
		for(int i=0;i<s.size();i++)
		{
			if(s[i]=='(')
			{
				ca++;
				a.push(cb);
			}
			else if(s[i]=='[')
			{
				cb++;
				b.push(ca);
			}
			else if(s[i]==')')
			{
				ca--;
				if(a.empty()||cb!=a.top())
				{
					cout<<"no"<<endl;
					f=1;
					break;
				}
				a.pop();
			}
			else if(s[i]==']')
			{
				cb--;
				if(b.empty()||ca!=b.top())
				{
					cout<<"no"<<endl;
					f=1;
					break;
				}
				b.pop();
			}
			if(ca<0||cb<0)
			{
				cout<<"no"<<endl;
				f=1;
				break;
			}
		}
		if(!f)
		{
			cout<<(ca||cb?"no":"yes")<<endl;
		}
	}
}

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

int main() {
	string str;
	stack<char>br;
	while (getline(cin, str), str != ".") {
		int flag = false;
		while (br.empty() != true) br.pop();
		for (int i = 0; i < str.size(); i++) {
			if (str[i] == '(' || str[i] == '[') br.push(str[i]), flag = true;
			else if (str[i] == ')') {
				if (br.empty()) {
					br.push('@');
					break;
				}
				else if ('(' == br.top())br.pop();
			}
			else if (str[i] == ']') {
				if (br.empty()) {
					br.push('@');
					break;
				}
				else if ('[' == br.top())br.pop();
			}
		}
		if (br.empty() && flag) cout << "yes" << endl;
		else cout << "no" << endl;
	}
}

C++: #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <stack>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

char str[1000];
int main() {
  while (fgets(str, 999, stdin), str[0] != '.') {
    stack<int> st;
    int len = strlen(str);
    bool ok = true;
    REP(i, len) {
      if (str[i] == '(') { st.push('('); }
      else if (str[i] == '[') { st.push('['); }
      else if (str[i] == ')') {
        if (st.empty() || st.top() != '(') { ok = false; break; }
        st.pop();
      } else if (str[i] == ']') {
        if (st.empty() || st.top() != '[') { ok = false; break; }
        st.pop();
      }
    }
    if (!st.empty()) { ok = false; }
    puts(ok ? "yes" : "no");
  }
}

C++: #include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	while(1){
		string s;
		getline(cin,s);
		if(s==".") break;
		stack<char> st;
		rep(i,s.size()){
			if(s[i]=='(') st.push(')');
			if(s[i]=='[') st.push(']');
			if(s[i]==')' || s[i]==']'){
				if(!st.empty() && st.top()==s[i]) st.pop();
				else{
					st.push('@');
					break;
				}
			}
		}
		if(st.empty()) puts("yes");
		else puts("no");
	}
}