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

int main(){
  string str;

  while(getline(cin,str) && str!="."){
    string c;
    for(int i=0;i<str.size();i++)
      if(str[i]==')' ||str[i]=='(' ||str[i]=='[' ||str[i]==']')
	c += str[i];

  stack<char> s;
  bool f=true;
    for(int i=0;i<c.length();i++){
      if(s.empty() || c[i]=='(' || c[i]=='[')
	s.push(c[i]);
      else if((s.top()=='(' && c[i]==')' )||(s.top()=='[' && c[i]==']')){
	s.pop();
      }else{
	f=false;
	break;
      }
      
    }
    cout << (f && s.empty()?"YES":"NO") << endl;
  }
  
}

C++: #include <iostream>
#include <string>
#include <stack>
using namespace std;
int glo;
int input(char& a,string& tmp){
  a=tmp[glo++];
  if(tmp[glo]==0){
    getline(cin,tmp);
    glo=0;
    if(tmp==".")
      glo=1000;
  }
  return 1;
}
void error(char& a,string& tmp,stack<char>& st){
  cout<<"no\n";
  st.empty();
  st.push(0);
  while(a!='.')
    input(a,tmp);
};

int main(){
  string tmp;
  char a;
  stack<char> st;
  st.push(0);
  glo=0;
  getline(cin,tmp);
  if(tmp==".")
    return 0;
  while(input(a,tmp)){
    if(a=='['||a=='(')
      st.push(a);
    if(a==']'){
      if(st.top()=='[')
	st.pop();
      else {
	error(a,tmp,st);
	continue;
      }
    }
    if(a==')'){

     if(st.top()=='(')
	st.pop();
     else {
       error(a,tmp,st);
       continue;
     }
    }
    if(a=='.'){
      if(st.top()){
	st.empty();
	st.push(0);
	cout <<"no!";
      }
      else cout <<"yes\n";
    }
    //   cout <<a<<endl;
    if(glo==1000) break;
  }
  return 0;
}

C++: #include "bits/stdc++.h"
#define REP(i, n, N) for(ll i=(n); i < N; i++)
#define p(s) cout << (s) << endl
#define p2(a, b) cout << (a) << ' ' << (b) << endl
using namespace std;
typedef long long ll;
int main() {
    string s;

    while(1){
        getline(cin,s);
        if(s.size()==1)break;
        stack<char> stk;
        stk.push('?');
        bool flag=true;
        REP(i,0,s.size()){
            if(s[i]=='(') stk.push('(');
            if(s[i]=='[') stk.push('[');
            if(s[i]==')') {
                if (stk.top() == '(') {
                    stk.pop();
                } else {
                    flag=false;
                    break;
                }
            }
            if(s[i]==']') {
                if (stk.top() == '[') {
                    stk.pop();
                } else {
                    flag= false;
                    break;
                }
            }
        }
        if(flag && stk.size()==1){
            p("yes");
        }else{
            p("no");
        }
    }

    return 0;
}

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

string s;

void solve(){
	stack<char> T;
	for(int i=0;i<s.size();i++){
		if(s[i]=='(' || s[i]=='[')
			T.push(s[i]);
		if(s[i]==')'){
			if(T.empty()){cout<<"no"<<endl;return;}
			if(T.top()=='(') T.pop();
			else{cout<<"no"<<endl;return;}
		}
		if(s[i]==']'){
			if(T.empty()){cout<<"no"<<endl;return;}
			if(T.top()=='[') T.pop();
			else{cout<<"no"<<endl;return;}
		}
	}
	if(T.empty())
		cout<<"yes\n";
	else cout<<"no\n";
}


int main(){

	while(getline(cin,s)){
		if(s==".") break;
		solve();
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <bitset>
#include <stack>
#include <cstdlib>
#define REP(i,n) for(int i = 0; n > i; i++)
#define MOD 1000000007
using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;
typedef long long int ll;
char str[101];
map<char, char> kako = { {'(',')'},{'[',']'} };
int is_balanced(int s) {
	for (int i = s+1; strlen(str) > i; i++) {
		if (str[i] == '(' || str[i] == '[') {
			i = is_balanced(i)+1;
			if (i == 0) return -1;
		}
		if (str[i] == ')' || str[i] == ']') {
			if(str[i] != kako[str[s]])
				return -1;
			else {
				return i;
			}
		}
	}
	return -1;
}

int main() {
	while (fgets(str,101, stdin)) {
		if (!strcmp(str, "."))
			return 0;
		bool f = true;
		REP(i, strlen(str)) {
			if (str[i] == '(' || str[i] == '[') {
				i = is_balanced(i)+1;
				if (i == 0) {
					printf("no\n");
					f = false;
					break;
				}
			}
		}
		if (f) printf("yes\n");
	}

	return 0;
}

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

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

C++: #include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init));

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  while(getline(cin,s)){
    if(s == ".") break;
    bool f = true;
    stack<char> st;
    rep(i,s.size()){
      if(s[i] == '('){
        st.push('(');
      }
      if(s[i] == ')'){
        if(st.top() != '(') f = false;
        st.pop();
      }
      if(s[i] == '['){
        st.push('[');
      }
      if(s[i] == ']'){
        if(st.top() != '[') f = false;
        st.pop();
      }
    }
    if(f){
      cout << "yes"<<endl;
    }
    else{
      cout << "no"<<endl;
    }
  }
  return 0;
}