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<cstdio>
#include<deque>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

bool check(string &s,int sp,int ep) {
  int a = 0, b = 0;
  REP(i,sp+1,ep) {
    if( s[i] == '(' ) ++a;
    if( s[i] == '[' ) ++b;
    if( s[i] == ')' ) --a;
    if( s[i] == ']' ) --b;
    if( a < 0 || b < 0 ) return false;
  }
  return a == 0 && b == 0;
}

int main() {
  string s;
  while( getline(cin,s), s != "." ) {
    bool ok = true;
    deque<int> a,b;
    rep(i,(int)s.size()) {
      if( s[i] == '(' ) a.push_back(i);
      if( s[i] == '[' ) b.push_back(i);
      if( s[i] == ')' ) {
	if( a.empty() ) { ok = false; break; }
	int sp = a.back(); a.pop_back();
	if( !check(s,sp,i) ) { ok = false; break; }
      }
      if( s[i] == ']' ) {
	if( b.empty() ) { ok = false; break; }
	int sp = b.back(); b.pop_back();
	if( !check(s,sp,i) ) { ok = false; break; }
      }
    }
    if( a.size() || b.size() ) ok = false;
    puts(ok?"yes":"no");
  }
  return 0;
}

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

int main() 
{
	string s;
	while(true)
	{
		getline(cin,s);
		if(s==".")return 0;
		string t;
		//t=reverse(s.begin(),s.end());
		int len=s.size();
		for(int i=0;i<len;i++)
		{
			if(s[i]=='(')
			{
				for(int j=s.size()-1;i<j;j--)
				{
					if(s[j]==')')
					{
						s.erase(i);
						s.erase(j);
					}
				}
			}
			if(s[i]=='[')
			{
				for(int j=s.size()-1;i<j;j--)
				{
					if(s[j]==']')
					{
						s.erase(i);
						s.erase(j);
					}
				}
			}
		}
		for(int i=0;i<s.size();i++)
		{
			if(s[i]=='('||s[i]==')'||s[i]=='['||s[i]==']')
			{
				cout<<"no"<<endl;
				goto A;
			}
		}
		cout<<"yes"<<endl;
		A:;
	}
	return 0;
}

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

const string C = "[]()";

int main() {
  for(string s; getline(cin, s) && s != ".";) {
    try {
      stack<int> stk;
      for(int i = 0; i < s.size(); ++i) {
        int p = C.find(s[i]);
        if(p == string::npos) continue;
        if(p % 2 == 0) {
          stk.push(p);
        } else {
          if(stk.empty() || stk.top() != p-1) {
            throw "no";
          }
          stk.pop();
        }
      }
      throw "yes";
    } catch(const char *res) {
      cout << res << endl;
    }
  }
  return 0;
}

C++: //
//  main.cpp
//  The Balance of the World
//
//  Created by x15071xx on 2017/06/16.
//  Copyright ?? 2017??´ AIT. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
int main(int argc, const char * argv[]) {
    
    
    while(1){
        string yn = "yes";
        string str;
        vector<char> st;
        getline(cin, str);
        
        
        if (str == ".") {
            break;
        }
        
        for (int i = 0;  i < str.size(); i++) {
            
            if (str[i] == '(' || str[i] == '[') {
                st.push_back(str[i]);
            }
            
            if (str[i] == ')') {
                
                
                if ('(' != st.back()) {
                    yn = "no";
                    break;
                }
                
                st.pop_back();
                
            }

            if (str[i] == ']') {
                
                if ('[' != st.back()) {
                    yn = "no";
                    break;
                }
                
                st.pop_back();
                
            }

        }
        
        if (!st.empty()) {
            yn = "no";
        }
        
        cout << yn << endl;
    }
    return 0;
}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  string line;
  while(getline(cin,line)){
	if(line == ".") break;
	int p1 = 0, p2 = 0, i;

	bool ans = true;
	stack<int> st;
	for(i=0;i<SZ(line);++i){
	  switch(line[i]){
	  case '(':
		st.push(0); break;
	  case '[':
		st.push(1); break;
	  case ')':
		if(st.empty())
		  ans = false;		
		else{
		  if(st.top() != 0)
			ans = false;			
		  st.pop();
		}
		break;
	  case ']':
		if(st.empty())
		  ans = false;		
		else{
		  if(st.top() != 1)
			ans = false;			
		  st.pop();
		}
		break;
	  }
	}
	ans = ans && st.empty();
	cout << (ans? "yes": "no") << endl;
  }

  return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)

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

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

int main(){
  string str;
			
  while(getline(cin, str)){
	if(str == ".") break;
	//cout << str << endl;
	bool flag  = false;
	stack<char> s;
	
	for(int i = 0; i < str.size(); i++){
	  if(str[i] == '(') s.push(str[i]);
	  else if(str[i] == '[') s.push(str[i]);
	  else if(str[i] == ')'){
		if(s.empty()){
		  flag = true;
		  break;
		}
		
		char tmp = s.top(); s.pop();
		//cout << "if ')' then tmp = " << tmp << endl;
		if(tmp != '('){
		  flag = true;
		  break;
		}
	  }
	  else if(str[i] == ']'){
		if(s.empty()){
		  flag = true;
		  break;

		}
		char tmp = s.top(); s.pop();
		//cout << "if ']' then tmp  = " << tmp << endl;
		if(tmp  != '['){
		  flag = true;
		  break;
		}
	  }
	}
	
	if(flag || !s.empty()) cout << "no" << endl;
	else cout << "yes" << endl;
  }
  return 0;
}