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(){
	string s;
	while(getline(cin,s)){
		if(s.size()==1 && s[0]=='.')break;
		stack<int>st;
		bool suc=true;
		for(int i=0;i<s.size();i++){
			if(s[i]=='[')st.push(0);
			if(s[i]=='(')st.push(1);
			
			if(s[i]==']'){
				if(st.empty())suc=false;
				else if(st.top()==1)suc=false; 
				else if(st.top()==0)st.pop();
			}
			if(s[i]==')'){
				if(st.empty())suc=false;
				else if(st.top()==0)suc=false;
				else if(st.top()==1)st.pop();
			}
			
		}
		
		if(!st.empty())suc=false;
		if(suc)cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
}

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

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

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

int main(){
  string s;
  while(1){
    getline(cin,s);
    if(s.size()==1&&s[0]=='.')break;
    string tmp;
    bool ok=true;
    for(int i=0;i<s.size();i++){
      if(s[i]=='(')tmp.push_back('(');
      if(s[i]=='[')tmp.push_back('[');

      if(s[i]==')'&&tmp[tmp.size()-1]=='('){
	tmp.pop_back();
      }else if(s[i]==')'&&tmp[tmp.size()-1]=='['){
	ok=false;
	break;
      }

      if(s[i]==']'&&tmp[tmp.size()-1]=='['){
	tmp.pop_back();
      }else if(s[i]==']'&&tmp[tmp.size()-1]=='('){
	ok=false;
	break;
      }
    }
    if(ok&&tmp.size()==0)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    
  }
  return 0;
}

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

string s;
int c = 0;

void k( int i ){

   c = 0;
  
  for( int j = i + 1 ; s[j] != '.' ; j++ ){
    
    if( s[i] == '(' && s[j] == ')' ){
      if( c == 0 ){
      s[i] = s[j] = ' ';
      return ;
      }
    }
    if( s[i] == '[' && s[j] == ']' ){
      if( c == 0 ){
      s[i] = s[j] = ' ';
      return ;
      }
    }
    if( s[i] == '(' && ( s[j] == '(' || s[j] == '[' ) ){
      k(j);
    }
    if( s[i] == '[' && ( s[j] == '(' || s[j] == '[' ) ){
      k(j);
    }
    if( s[i] == '(' && s[j] == ']' ){
      c++;
      return ;
    }
    if( s[i] == '[' && s[j] == ')' ){
      c++;
      return ;
    }
  }
}

int main(void){
  
  int cnt;

  while(1){
    
    cnt = 0;

    /* for( int i = 0 ; s[i] != '.' ; i++ ){
     cin >> s[i];*/  

      getline( cin , s );
      /*if( s[ s.size() ] == '.'){*/
      if( s[0] == '.')break;
	s[ s.size()] = '\0';
	/*break;*/
    /* }*/
      /* }*/
    if( s[0] == '\0' )break;
    
    for( int i = 0 ; s[i] != '.' ; i++ ){
      if( s[i] == '(' || s[i] == '[' ){
	k(i);
      }
      /*      else if( s[i] == ')' || s[i] == ']' ){
	cout << "no" << endl;
	break;
	}*/
    }    
    for( int i = 0 ; s[i] != '\0' ; i++ ){
      if( s[i] == '(' ||  s[i] == ')' ||  s[i] == '[' ||  s[i] == ']' ){
	cnt++;
	break;
      }
    }
    if( cnt == 0 )cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

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

using namespace std;

int main(void){
  string s;
  stack<char> str;

  while(getline(cin,s) && s!="."){

    string ch;
    for(int i=0;i<s.length;i++)
      if(s[i]=='{' || s[i]=='(' || s[i]=='}' || s[i]==')')ch+=s[i];

    for(int i=0;i<ch.length();i++){
      
      if(ch[i]=='(' || ch[i]=='{')str.push(s[i]);
      
      if(ch[i]==')' && str.top()=='(')str.pop();
      if(ch[i]=='}' && str.top()=='}')str.pop();
    }

    cout << str.empty()?"YES":"NO" << endl;

  }

  return 0;
}

C++: /* vim:set foldmethod=marker: */
#include <bits/stdc++.h>
using namespace std;

//{{{
#define all(x) (x).begin(),(x).end()
#define REP(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define RREP(i,a,b) for(int i=(int)(a); i>=b; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,n,0)
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;

#define dump(x) (cerr << #x << "=" << x << endl)
template<class T> ostream& osContainer(ostream& os,T c) { os<<'[';for(decltype(c.begin()) it=c.begin();it!=c.end();it++)os<<*it<<',';os<<']';return os; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { return osContainer(os,v); }
template<class T> ostream& operator<<(ostream& os,const set<T>& s) { return osContainer(os,s); }
template<class T> ostream& operator<<(ostream& os,const multiset<T>& s) { return osContainer(os,s); }
template<class T,class S> ostream& operator<<(ostream& os,const map<T,S>& m) { return osContainer(os,m); }
template<class T,class S> ostream& operator<<(ostream& os,const multimap<T,S>& m) { return osContainer(os,m); }
template<class T1,class T2>
ostream& operator<<(ostream& os, const pair<T1,T2>& p){ os << '(' << p.first << ',' << p.second << ')'; return os; }

const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};
//}}}

bool edge();
bool round();
int idx;

string str;

bool check()
{
    idx = 0;
    bool res = true;

    while(idx < str.length()) {
        if (str[idx] == '(') {
            idx++;
            res = res && round();
        }
        else if (str[idx] == '['){
            idx++;
            res = res && edge();
        }
        idx++;
    }

    return res;
}

bool round()
{
    bool res = true;
    while(idx < str.length()) {
        if (str[idx] == ')') {
            return true;
        }
        else if (str[idx] == ']') {
            return false;
        }
        else if (str[idx] == '(') {
            idx++;
            round();
        }
        else if (str[idx] == '['){
            idx++;
            edge();
        }
        idx++;
    }

    return false;
}

bool edge()
{
    bool res = true;
    while(idx < str.length()) {
        if (str[idx] == ']'){
            return true;
        }
        else if (str[idx] == ')') {
            return false;
        }
        else if (str[idx] == '(') {
            idx++;
            round();
        }
        else if (str[idx] == '['){
            idx++;
            edge();
        }
        idx++;
    }

    return false;
}

void solve()
{
    while(getline(cin, str), !(str[0] == '.' && str.length() == 1)) {
        cout << (check() ? "yes" : "no") << endl;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(12);
    solve();
}