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++: //#define _GRIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
    string s;
    while(getline(cin,s), s!=".") {
        queue<int> que1, que2;
        rep(i,s.size()) {
            if(s[i]=='(') que1.push(1);
            else if(s[i]==')') {
                if(que1.empty()) {
                    cout << "no" << endl;
                    break;
                } else {
                    que1.pop();
                }
            }
            else if(s[i]=='[') que2.push(1);
            else if(s[i]==']') {
                if(que2.empty()) {
                    cout << "no" << endl;
                    break;
                } else {
                    que2.pop();
                }
            }
        }
        if(que1.empty()&&que2.empty()) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define dump(a) cout << (#a) << "=" << (a) << endl
using namespace std;

/*
	expr:
		| ''
		| term expr
	term: 
		| '(' expr ')' 
		| '[' expr ']'
*/

bool isCheck=true;

void term(string &line, int &i);
void expr(string &line, int &i);

void term(string &line, int &i)
{
	switch(line[i])
	{
		case '(':
			i++;
			expr(line, i);
			//dump(i);
			//dump(line[i]);
			if (line[i] != ')') { isCheck=false; }
			i++;
			break;
		case '[':
			i++;
			expr(line, i); //i????????¢??????????????????
			if (line[i] != ']') { isCheck=false; }
			i++;
			break;
		default:
			
			break;
	}
	return;
}


/*
	expr:
		| ''
		| term expr
	term: 
		| '(' expr ')' 
		| '[' expr ']'
*/


void expr(string &line, int &i)
{
	if (line[i] == '(' || line[i] == '[') {
		term(line,i);
		expr(line,i);
	}
	return; //?????????
}

string pass(string &line)
{
	string new_line;
	for(int i=0; i<line.size(); i++) {
		if ((line[i] == '[') || (line[i] == '(') ||
			(line[i] == ']') || (line[i] == ')') ) {
			new_line+=line[i];
		}
	}
	return new_line;
}

int main()
{
	string line;
	while(getline(cin, line)) {
		isCheck=true;
		if (line[0] == '.') { break; }
		//cout << line << endl;
		int i=0;
		string new_line=pass(line);
		if (new_line[0]==')' || new_line[0]==']') {
			isCheck=false;
		}
		else {
			expr(new_line,i);
		}

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

	return EXIT_SUCCESS;
}

C++: #include <stdio.h>

int main(void){
  char c;
  bool ok;

  while(1){
    char s[101] = {0};
    ok = true;
    std::stack<char> st;
    for(int i=0; i<101; i++){
      scanf("%c", &c);
      if(c == '\n'){
	s[i] = '\0';
	break;
      }else{
	s[i] = c;
      }
    }

    if(s[0] == '.'){
      break;
    }

    for(int i=0; i<101; i++){
      if(s[i] == '.'){
	break;
      }
      if(s[i] == '(' || s[i] == '['){
	st.push(s[i]);
      }else if(str[i] == ')'){
	if(st.empty() || st.top()!='('){
	  ok = false;
	  break;
	}else{
	  st.pop();
	}
      }else if(str[i] == ']'){
	if(st.empty() || st.top() != '['){
	  ok = false;
	  break;
	}else{
	  st.pop();
	}
      }
    }

    if(!st.empty()){
      ok = false;
    }

    if(ok){
      printf("yes\n");
    }else{
      printf("no\n");
    }
    
  }
  return 0;
}

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

using namespace std;
int main(){
	string str;
	while(getline(cin,str)&& str!="."){
		string ss;

		for(int i=0;i<str.size();i++)
			if(str[i]=='(' || str[i]==')' || str[i]=='[' || str[i]==']')
				ss+=str[i];
	
		stack<char> s;
		bool f=true;

		for(int i=0;i<ss.length();i++){

			if(ss.empty() || ss[i]=='(' || ss[i]=='[')
				s.push(ss[i]);

			else if( (s.top()=='(' && ss[i]==')') || (s.top()=='[' && ss[i]==']') )
					s.pop();
			else{
				f=false;
				break;
			}
		}
		cout << (f && s.empty()?"yes":"no") << endl;
	}
}

C++: #include<iostream>

using namespace std;

int main(void) {
	string in;
	char tmp;
	int pos, count, dir, tmppos;

	while(true) {
		getline(cin, in);
		if(in == ".") { break; }
		pos = 0;
		count = 0;
		dir = 1;
		while(true) {
			if(dir == 1 && (in[pos] == '(' || in[pos] == '[')) {
				count++;
			} else if(dir == 1 && (in[pos] == ')' || in[pos] == ']')) {
				tmp = in[pos];
				tmppos = pos;
				dir = -1;
			} else if(dir == -1 && ((in[pos] == '(' && tmp == ')') || (in[pos] == '[' && tmp == ']'))) {
				count--;
				in[pos] = '*';
				in[tmppos] = '*';
				dir = 1;
			} else if(dir == -1 && ((in[pos] == '(' && tmp == ']') || (in[pos] == '[' && tmp == ')'))) {
				break;
			}
			pos += 1*dir;
			if(pos < 0) { count++; break; }
			if((int)in.length() < pos) { break; }
		}
		if(count == 0) { cout << "yes" << endl; }
		else { cout << "no" << endl; }
	}

	return 0;
}