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 <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;

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

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

	return 0;
}

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

using namespace std;

int check(char c){
  if(c == '[' || c == '(') return 2;
  if(c == ']' || c == ')') return 1;
  return 0;
}

int isOK(char c, char in){
  if(in == ']' && c == '[') return 1;
  if(in == ')' && c == '(') return 1;
  // cout << " " << c << " " << in << endl;
  return 0;
}

int main(){

  string in;
  while(getline(cin,in)){
    if(in == ".") break;
    stack<char> S;
    int status = 1;
    for(int i = 0; i < in.length(); i++){
      int j = check(in[i]);
      if(j == 2){
	S.push(in[i]);
	//	cout << " " << in[i] << endl;
      }
      if(j == 1) {
	if(S.size() == 0){
	  status = 0;
	  break;
	}
	if(!isOK(S.top(),in[i])){
	  status = 0;
	  break;
	}
	S.pop();
      }
    }
    if(status) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
 

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

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

int main() {

  string seq;

  while ( getline(cin, seq) ) {

    if ( seq.size() == 1 && seq[0] == '.' ) return 0;

    stack<int> V;
    int sw = 0;
    for ( int i = 0; i < seq.length(); i++ ) {
      if ( seq[i] == '(' ) V.push(0);
      if ( seq[i] == '[' ) V.push(1);
      if ( seq[i] == ')' ) {
        if ( !V.empty() && V.top() == 0 ) V.pop();
        else sw = 1;
      }
      if ( seq[i] == ']' ) {
        if ( !V.empty() && V.top() == 1 ) V.pop();
        else sw = 1;
      }
      continue;
    }
    if ( sw == 0 && V.empty() ) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}

C++: #include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	string s;
	while(getline(cin, s), s!="."){
		bool ok = true;
		int a = 0, b = 0;
		int state = 0;
		stack<char> st;
		rep(i,s.size()){
			if(s[i] == '('){
				st.push(s[i]);
			}
			else if(s[i] == ')'){
				if(st.empty() || st.top() != '('){
					ok=false;
				}
				else{
					st.pop();
				}
			}
			if(s[i] == '['){
				st.push(s[i]);
			}
			else if(s[i] == ']'){
				if(st.empty() || st.top() != '['){
					ok=false;
				}
				else{
					st.pop();
				}
			}
		}
		if(st.size()) ok=false;
		cout << (ok?"yes":"no") << endl;
	}
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}