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

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

int main(){
    string in;
    while( getline(cin, in), !(in.length()==1 && in[0]=='.') ) {
        stack<int> brackets;
        bool judge = true;
        rep( i, in.length() ) {
            if( in[i] == '(' ) {
                brackets.push(0);
            } else if( in[i] == '[' ) {
                brackets.push(1);
            } else if( in[i] == ')' ) {
                if( !(brackets.size()>0 && brackets.top()==0) ) {
                    judge = false;
                } else {
                    brackets.pop();
                }
            } else if( in[i] == ']' ) {
                if( !(brackets.size()>0 && brackets.top()==1) ) {
                    judge = false;
                } else {
                    brackets.pop();
                }
            }
        }
        if( brackets.size() > 0 ) judge = false;
        cout << (judge ? "yes" : "no") << endl;
    }
    return 0;
}

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

using namespace std;

void solve()
{
	string str;
	while(getline(cin, str))
	{
		if(str == ".")
		{
			break;
		}
		int parentheses = 0;
		int box_brackets = 0;
		bool ok_flag = true;
		for(int i = 0; i < str.size(); ++i)
		{
			if(str[i] == '(')
			{
				++parentheses;
			}
			else if(str[i] == '[')
			{
				++box_brackets;
			}
			else if(str[i] == ')')
			{
				--parentheses;
				if(parentheses < 0)
				{
					cout << "no" << endl;
					ok_flag = false;
					break;
				}
			}
			else if(str[i] == ']')
			{
				--box_brackets;
				if(box_brackets < 0)
				{
					cout << "no" << endl;
					ok_flag = false;
					break;
				}
			}
		}
		if(ok_flag && (parentheses != 0 || box_brackets != 0))
		{
			ok_flag = false;
			cout << "no" << endl;
		}
		if(ok_flag)
		{
			cout << "yes" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

C++: //
//  main.cpp
//  AOJ1173
//
//  Created by aki33524 on 2014/07/09.
//  Copyright (c) 2014年 aki33524. All rights reserved.
//

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

string S;
void solve(){
    int a = 0, b = 0;
    char last = '.';
    
    for(int i=0; i<S.size(); i++){
        char c = S[i];
        if(c == '('){
            last = c;
            a++;
        }else if(c == ')'){
            a--;
            if(last == '[' || a < 0){
                cout << "no" << endl;
                return;
            }
            last = c;
        }else if(c == '['){
            last = c;
            b++;
        }else if(c == ']'){
            b--;
            if(last == '(' || b < 0){
                cout << "no" << endl;
                return;
            }
            last = c;
        }
    }
    cout << "yes" << endl;
}

void solve2(){
    stack<char> st;
    for(int i=0; i<S.size(); i++){
        char c = S[i];
        if(c != '(' && c != ')' && c != '[' && c != ']')
            continue;
        
        if(c == '(' || c == '[')
            st.push(c);
        
        if(c == ')' || c == ']'){
            if(st.empty()){
                cout << "no" << endl;
                return;
            }
            if((st.top() == '(' && c == ']') || (st.top() == '[' && c == ')')){
                cout << "no" << endl;
                return;
            }
            st.pop();
        }
    }
    cout << "yes" << endl;
}

int main(int argc, const char * argv[])
{
    while(getline(cin, S), S!="."){
//        cout << S << endl;
        solve2();
    }
    return 0;
}

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;



int main(void) {
	
	while (1) {
		string s;
		int count = 0;
		int now = 0;
		int pos = -1;
		int dp[100] = {};

		getline(cin, s);
		if (s[0] == '.') {
			break;
		}
		FOR(i, 0, s.size() - 1) {
			switch (s[i]) {
			case '(':
				dp[i] = 1;
				count++;
				break;
			case ')':
				dp[i] = -1;
				count++;
				break;
			case '[':
				dp[i] = 2;
				count++;
				break;
			case ']':
				dp[i] = -2;
				count++;
				break;
			}
		}

		while (1) {
			bool check = false;
			int now;
			int i = 0;
			int t = 1;
			while (i<=s.size()-2) {
				if (dp[i] ==1||dp[i]==2) {
					now = dp[i];
					break;
				}
				i++;
			}
			t = i + 1;
			while (t <= s.size() - 1) {
				if (dp[t] + now == 0) {
					dp[i] = dp[t] = 0;
					count -= 2;
					break;
				}
				else if (dp[t] == 1 || dp[t] == 2) {
					now = dp[t];
					i = t;
				}
				else if (dp[t] == -1 || dp[t] == -2) {
					t = s.size() - 1;
				}
				t++;
			}
			if (t == s.size()) {
				break;
			}
			
		}

		if (count == 0) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
		
	}

}

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

int main()
{
	string str;
	while(getline(cin,str), str!=".")
	{
		bool ok=true;
		stack<char> s;
		for(int i=0; i<str.size(); i++)
		{
			if(str[i]=='(' || str[i]=='[')
			{
				s.push(str[i]);
			}
			else if(str[i]==')')
			{
				if(s.empty())    { ok=false; break; }
				if(s.top()!='(') { ok=false; break; }
				s.pop();
			}
			else if(str[i]==']')
			{
				if(s.empty())    { ok=false; break; }
				if(s.top()!='[') { ok=false; break; }
				s.pop();
			}
			else if(str[i]=='.')
			{
				break;
			}
		}

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

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){

  while(1){
	char hoge[200];
	int i = 0;

	//	getline(cin, hoge);

	while(1){
	  hoge[i] = getchar();
	  //	  scanf("%c",&hoge[i]);
	  if(hoge[i]=='\n') continue;
	  if(hoge[i]=='.') break;
	  i++;
	}
	if(hoge[0]=='.') break;

	int mini = 0;
	int big = 0;
	bool now[200] = {};
	int b=0;
 //????????§??????????????????

	REP(a,i){
	  if(hoge[a]=='('){
		mini++;
		b++;
		now[b] = false;
	  }else if(hoge[a]==')'){
		if(now[b] == false) {
		  mini--;
		  b--;
		}else break;
	  }else if(hoge[a]=='['){
		big++;
		b++;
		now[b] = true;
	  }else if(hoge[a]==']'){
		if(now[b] == true){
		  big--;
		  b--;
		}else break;
	  }
	  if(mini < 0||big < 0) break;
	}

	if(mini==0&&big==0) cout << "yes" << endl;
	else cout << "no" << endl;
  }
}