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;

namespace Solver {

    string s;
    inline bool Read() {
        getline(cin, s);
        return s != ".";
    }

    inline void Work() {
        stack<char> stk;
        for (int i = 0; i < s.length(); i++) {
            if (s[i] == '[' || s[i] == '(') {
                stk.push(s[i]);
            } else if (s[i] == ']') {
                if (!stk.empty() && stk.top() == '[') stk.pop();
            } else if (s[i] == ')') {
                if (!stk.empty() && stk.top() == '(') stk.pop();
            }
        }

        if (stk.empty()) cout << "yes" << endl;
        else cout << "no" << endl;
    }

    inline void Solve() {
         while(Read()) Work();
    }
}

int main() {
    Solver::Solve();
}

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

bool solve(){
  stack<char> st;
  for(int i=0;i<(int)str.size();i++){
    if(str[i]=='(')st.push(str[i]);
    else if(str[i]=='[')st.push(str[i]);
    else if(str[i]==')'){
      if(st.empty())return false;
      if(st.top()!='(')return false;
      st.pop();
    }else if(str[i]==']'){
      if(st.empty())return false;
      if(st.top()!='[')return false;
      st.pop();
    }
  }
  return st.empty();
}

int main(){
  while(1){
    getline(cin,str);
    if(str==".")break;
    if(solve())cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}

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

int main(){

	bool F=true;bool R=true;
while(1){char str[250]={},ch;
	for(int i=0;i<245;i++)
	{scanf("%c",&ch);if(ch=='.'&&R==false&&i==1){F=false;break;}
	if(ch=='.'){break;}
	str[i]=ch;}
	if(F==false){break;}
	int ks=0,kl=0,ms=0,ml=0;
	bool f=true;int p[200]={};int y=0;bool G=true;
	if(str[1]=='.'&&str[0]=='\n')F=false;
	for(int i=0;i<200;i++)
	{

		//cout<<i<<"#"<<y<<"#"<<p[y]<<endl;
		if(str[i]=='('){ms++;y++;p[y]=1;}
	else if(str[i]=='['){ks++;y++;p[y]=5;}
	else if(str[i]==')'){ml++;if(p[y]==5||p[y]==0){f=false;}if(ms<ml){f=false;}y--;}//cout<<i<<" ";}
	else if(str[i]==']'){kl++;if(p[y]==1||p[y]==0){f=false;}if(ks<kl){f=false;}y--;}
	}
	if(F==true){
	if(f!=false&&ms==ml&&ks==kl)cout<<"yes"<<endl;
	else{cout<<"no"<<endl;//<<ms<<ml<<ks<<kl<<endl;
	}
	}
R=false;
}


return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
const int limit=200;
char st[limit];
int a[limit];
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int aa;
	gets(st);
	int n=strlen(st);
	while (!((st[0]=='.')&&(n==1)))
	{
		for(int i=0;i<=n;i++)
		{
			if(st[i]=='[') a[++aa]=1;
			else if(st[i]==']') a[++aa]=2;
			else if(st[i]=='(') a[++aa]=3;
			else if(st[i]==')') a[++aa]=4;	
		}	
		bool ok=true;
		while ((ok)&&(aa>0))
		{
			ok=false;
			for (int i=1;i<=aa-1;i++) if(((a[i]==1)&&(a[i+1]==2))||((a[i]==3)&&(a[i+1]==4)))
			{
				for(int j=i;j<=aa-2;j++) a[j]=a[j+2];
				a[aa]=0; a[aa-1]=0;
				aa=aa-2;
				ok=true;
				break;
			}
		}
		if(aa==0) cout<<"yes";
		else cout<<"no";
		cout<<endl;
		for(int i=1;i<=aa;i++) a[i]=0;
		aa=0;
		gets(st);
		n=strlen(st);
	}		
}

C++: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

bool solve(string &s){
    stack<char> S;
    for (auto &&i : s) {
        if(i == '(' || i == '[') S.emplace(i);
        else if(i == ')' || i == ']'){
            if(S.empty()) return false;
            char c = S.top(); S.pop();
            if(i == ')' && c == '[') return false;
            if(i == ']' && c == '(') return false;
        }
    }
    return S.empty();
}

int main() {
    string s;
    while(getline(cin, s), s != "."){
        puts(solve(s) ? "yes" : "no");
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define rep(i,e) for(int i=0;i<(e);++i)

int main() {
  string s;
  while(getline(cin, s)){
    if(s[0]=='.') return 0;
    stack<char> st;
    bool good = true;
    for(auto e: s){
      if(e=='(' || e=='[') st.push(e);
      else if(e==')' || e==']'){
        if(st.size()==0){
          good = false;
          break;
        }
        else if((e==')' && st.top()=='(') || (e==']' && st.top()=='[')) st.pop();
        else{
          good = false;
          break;
        }
      }
    }
    if(good==true && st.size()==0) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

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.size() || (st.size() && st.top() != '(')) f = false;
        if(st.size())st.pop();
      }
      if(s[i] == '['){
        st.push('[');
      }
      if(s[i] == ']'){
        if(!st.size() || (st.size() && st.top() != '[')) f = false;
        if(st.size())st.pop();
      }
    }
    if(f && !st.size()){
      cout << "yes"<<endl;
    }
    else{
      cout << "no"<<endl;
    }
  }
  return 0;
}