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 <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 
 
 int main(){
   
  

   while(1){
   std::string s;
   (std::getline(std::cin, s)) ;
  
  if(s==".") break ;
  
  bool ok=1 ; 
  bool ko=1 ;
  bool p=1 ;
  int w= 0;
  int sa = 0 ;
  int as = 0 ;
   ll k= s.size() ;
   stack<int>  A; 
    rep(i,k-1){
    if(s[i]=='(') {
      sa++ ;
      A.push(1) ;
    }
    if(s[i]==')') {
      sa-- ;
      if(!A.empty()){
       int x= A.top() ;
       if(x!=1) p=0 ;
       A.pop() ;
      }
    }
    if(s[i]=='[') {
      as++ ;
      A.push(-1) ;
    }
    if(s[i]==']') {
      as-- ;
      if(!A.empty()){
        int x= A.top() ;
        if(x!=-1) p=0 ;
        A.pop() ;
      }
    }
    if(sa<0) ok=0 ;
    if(as<0) ko=0 ;
    
    
    }

      if(ok==1&&ko==1&&sa==0&&as==0&&p==1){
       
      cout<<"yes"<<endl;
         
      }
      else cout<< "no"<<endl ;
      
    
  
      
      
   }
   return 0 ;
 }

C++: // Undone
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
string calc(string s) {
  stack<int> v;
  for (int i = 0; i < s.length()-1; i++) {
    if (s[i] == '[' || s[i] == '(') {
      v.push(s[i]);
    } else if (s[i] == ']') {
      if (v.size() > 0 && v.top() == '[') {
        v.pop();
      } else {
        return "no";
      }
    } else if (s[i] == ')') {
      if (v.size() > 0 && v.top() == '(') {
        v.pop();
      } else {
        return "no";
      }
    }
  }
  if (v.size() > 0) {
    return "no";
  } else {
    return "yes";
  }
}

signed main() {
  string s;
  while (getline(cin, s), s!=".") {
    cout << calc(s) << endl;
  }
  return 0;
}

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

char s[3] = "([";
char e[3] = ")]";

int main(int argc, const char * argv[]) {
    while(1){
        string line; getline(cin, line);
        if(line == ".") break;
        cin.ignore();
        
        bool ok = true;
        stack<char> brackets;
        for(int i = 0; i < line.size(); i++){
            for(int j = 0; j < 2; j++){
                if (line[i] == s[j]) {
                    brackets.push(line[i]);
                } else if (line[i] == e[j]){
                    if(brackets.empty()){
                        ok = false;
                    } else {
                        ok = (brackets.top() == s[j]);
                        brackets.pop();
                    }
                }
            }
            if(!ok) break;
        }
        cout << (ok ? "Yes" : "No") << endl;
        
    }
}

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

int N;

bool balance(string s, int b, int e)
{
  N = 1;
  for(int i = b; i < e; i++){
    if(s.at(i) == '('){
      for(int j = i + 1; j < e; j++){
	if(s.at(j) == ')'){
	  string sub = s.substr(i + 1, j - i - 1);
	  cout << sub << endl;
	  if(balance(sub, 0, sub.size())){
	    N = 0;
	    continue;
	  }
	}
      }
      if(N)
	return false;
      else
	return true;
    }else if(s.at(i) == '['){
      for(int j = i + 1; j < e; j++){
	if(s.at(j) == ']'){
	  string sub = s.substr(i + 1, j - i - 1);
	  cout << sub << endl;
      	  if(balance(sub, 0, sub.size())){
	    N = 0;
	    continue;
	  }
	}
      }
      if(N)
	return false;
      else
	return true;
    }else if(s.at(i) == ')'){
      for(int j = 0; j < i; j++){
	if(s.at(j) == '('){
	  string sub = s.substr(j + 1, i - j - 1);
	  cout << sub << endl;
	  if(balance(sub, 0, sub.size())){
	    N = 0;
	    continue;
	  }
	}
      }
      if(N)
	return false;
      else
	return true;
    }else if(s.at(i) == ']'){
      for(int j = 0; j < i; j++){
	if(s.at(j) == '['){
	  string sub = s.substr(j + 1, i - j - 1);
	  cout << sub << endl;
	  if(balance(sub, 0, sub.size())){
	    N = 0;
	    continue;
	  }
	}
      }
      if(N)
	return false;
      else
	return true;
    }
  }
  return true;
}
       
int main()
{
  string s;
  while(1){
    getline(cin, s);
    if(s == "."){
      break;
    }else{
      if(balance(s, 0, s.size()))
	cout << "yes" << endl;
      else
	cout << "no" << endl;
    }
  }
}

C++: /* 解答時間→ : */

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(){
	string n;
	vector<int> kakko;
	bool flg;
	while(1){
		getline(cin, n);
		if(n == ".")
			break;
		kakko.clear();
		int kakko1 = 0, kakko2 = 1;
		flg = true;
		cout << n.size() << "\n";
		for(int i = 0; i < n.size(); i++){
			/*for(int j = 0; j < kakko.size(); j++)
				cout << "[" << kakko[j] << "]";
			cout << kakko1 "\n";*/
			if(n[i] == '('){
				kakko.push_back(kakko1);
				kakko1 += 2;
			//	cout << "(\n";
			}
			if(n[i] == '['){
				kakko.push_back(kakko2);
				kakko2 += 2;
			//	cout << "[\n";
			}
			if(n[i] == ')'){
				if(kakko[kakko.size() - 1] + 2 == kakko1){
					kakko.pop_back();
					kakko1 -= 2;
				//	cout << ")\n";
				}else{
					flg = false;
					break;
				}
			}
			if(n[i] == ']'){
				if(kakko[kakko.size() - 1] + 2 == kakko2){
					kakko.pop_back();
					kakko2 -= 2;
					//cout << "]\n";
				}else{
					flg = false;
					break;
				}
			}
		}
		if(kakko.size() != 0)
			flg = false;
		if(flg == true)
			cout << "yes" << "\n";
		else
			cout << "no" << "\n";
	}
	cout << flush;
	return 0;
}

/*#include <algorithm>	//sort, binary_search等々
#include <functional>	//greaterなど
#include <iomanip>		//各種マニピュレータ
#include <iostream>		//基本入出力
#include <string>		//文字列処理
#include <vector>		//STLの花形vector
using namespace std;

int main(){
	int n, tmp, *nums_n;
	vector<int> nums_v;

	cin >> n;
	nums_n = new int[n];
	for(int i = 0; i < n; i++){
		cin >> tmp;
		nums_n[i] = tmp;
		nums_v.push_back(tmp);
	}
	cout << nums_n[0] << nums_n[n - 1] << "\n";
	cout << *nums_v.begin() << *nums_v.end() << "\n";
	cout << flush;

	while(1){
		cin >> n;
		if(n == 0)
			break;
		
	}

	delete [] nums_n;

	return 0;
}
*/