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>
using namespace std;

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

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

using namespace std;

#define MAX 128

int main(void) {
	while(1) {
		string str;
		bool balance = true;
		stack<char> sbracket;

		getline(cin, str);
		if(str == ".") break;
		for(int i = 0; str[i] != '.'; i++) {
			if(str[i] == '(' || str[i] == '[') {
				sbracket.push(str[i]);
			}
			if(str[i] == ')') {
				if(sbracket.size() == 0 || sbracket.top() != '(') {
					balance = false;
					break;
				}
				sbracket.pop();
			}
			if(str[i] == ']') {
				if(sbracket.size() == 0 || sbracket.top() != '[') {
					balance = false;
					break;
				}
				sbracket.pop();
			}
		}
		if(sbracket.size() != 0) balance = false;
		printf(balance ? "Yes\n" : "No\n");
	}
	return 0;
}

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


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//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 EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#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)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	string str;
	bool ok;

	while (true) {
		stack<char>st;
		ok = true;
		
		getline(cin, str);

		if (str == ".")break;

		for (char c :str) {
			if (c == '(')st.push('(');
			if (c == '[')st.push('[');

			if (c == ')') {
				if (st.empty() || st.top() != '(') {
					ok = false;
					break;
				}

				st.pop();
			}

			if (c == ']') {
				if (st.empty() || st.top() != '[') {
					ok = false;
					break;
				}

				st.pop();
			}
		}

		if (ok&&st.empty()) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}

	}
}

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

using namespace std;

string hantei(string line);

int main(void){
  string line;
  vector<string> result;
  while (getline(cin, line)){
    if (line == "."){
      return 0;
    }
    //cout << hantei(line) << endl;
	result.push_back(hantei(line));
  }
  vector<string>::iterator it = result.begin();
  while( it != result.end()){
	cout << *it << endl;
	++it;
  }
  return 0;
}

string hantei(string line){
  stack<char> left;

  for (int i=0; i<line.size(); ++i){
    if ((line[i] == '(') || (line[i] == '[')){
      left.push(line[i]);
    }
    if (!left.empty()){
      if ((left.top() == '(') && (line[i] == ')')){
	left.pop();
     }
      else if ((left.top() == '[') && (line[i] == ']')){
	left.pop();	
      } 
    }
  }
  if (left.empty()){
    return "yes";
  }
  else{
    return "no";
  }
}

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

using namespace std;

int main(){
	int rk=0, sk=0, len=0;
	char in;
	bool check=false;
	vector<char> st;
	st.push_back(' ');
	while(true){
		scanf("%c", &in);
		if( in == '\n' ) continue;
		if( in == '.' && len == 0 ) break;
		len++;
		if( in == '(' ){ rk++; st.push_back('('); }
		if( in == '[' ){ sk++; st.push_back('['); }
		if( in == ')' ){
			if( --rk < 0 || st.empty() || st.back() != '(' ){
				check=true;
				st.push_back(' ');
			}
			st.pop_back();
		}
		if( in == ']' ){
			if( --sk < 0 || st.empty() || st.back() != '[' ){
				check=true;
				st.push_back(' ');
			}
			st.pop_back();
		}
		if( in == '.' ){
			if( rk != 0 || sk != 0 )
				check = true;
			cout << (check?"no":"yes") << endl;
			rk = 0;
			sk = 0;
			len = 0;
			check = false;
			st.clear();
			st.push_back(' ');
		//	while(st.empty()) st.pop();
		//	st.push(' ');
		}
	}
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<string>
#include<stack>
using namespace std;
int brkat(string s){
  stack<int> st;
  int i;
  st.push(111);
  for(i=0;s[i]!=0;i++){
    if(s[i]=='[')       st.push(s[i]);	  
    if(s[i]=='(')       st.push(s[i]);
    if(s[i]==']')      {
      if('['!=st.top() )	  return 2;
      st.pop();}	
  
    if(s[i]==')')      {
      if('('!=st.top() )
	return 2;
      st.pop();}
    //    cout <<i<<"ggg\n";
 }
  if(st.top()!=111) return 2;
  return 0; 
}
int main(){
  stack<int> st;
  string s,ouput;
  int i,j=0;

  while(1){
    i=0;
    getline(cin,s);
        if (s==".") break;
    ouput[j]=brkat(s);
    j++;
  }
  for(i=0;i<j;i++){
    if (ouput[i]==2) cout <<"no\n";
    if (ouput[i]==0) cout <<"yes\n";
  }
  return 0;
}