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>
#include<vector>

using namespace std;

int main(void){
  string s;

  while(getline(cin,s) && s!="."){

    string ch;
    for(int i=0;i<s.size();i++)
      if(s[i]=='{' || s[i]=='(' || s[i]=='}' || s[i]==')')ch+=s[i];

    stack<char> str;
    bool flag = true;
    for(int i=0;i<ch.length();i++){
      
      if(str.empty() || ch[i]=='(' || ch[i]=='{')str.push(ch[i]);
      else if((ch[i]==')' && str.top()=='(')||(ch[i]=='}' && str.top()=='}'))str.pop();
      else {
	flag = false;
	break;
      }
    }

    cout << (flag && str.empty()?"YES":"NO") << endl;

  }

  return 0;
}

C++: #include <stdio.h>
#include <string.h>
int kakko(char *c,char tmp,int count){
	int flag = 0;
	char wtmp;
	*c = getchar();
	count++;
	if(tmp == ')')
		wtmp = ']';
	else
		wtmp = ')';
	while(*c != '.' && *c != tmp && *c != wtmp){
		if(*c == '(' || *c == '['){
			if(*c == '(')
				tmp = ')';
			else
				tmp = ']';
			flag = kakko(c,tmp,count);
		}
		if(*c != '.' && *c != tmp){
			*c = getchar();
			count++;
		}
	}
	if(*c == '.' || *c == wtmp)
		flag = 1;
	return flag;
}

int main(void){
	int count = 0, flag = 0;
	char c, tmp;
	c = getchar();
	while(c != '.' || count != 0){
		if(c == '(' || c == '['){
			if(c == '(')
				tmp = ')';
			else
				tmp = ']';
			flag = kakko(&c,tmp,count);
		}
		if(c == '.'){
			if(flag == 0)
				printf("yes\n");
			else
				printf("no\n");
			flag = 0;
			count = 0;
			getchar(); //改行読取ばs
			c = getchar();
		}
		else{
			c = getchar();
			count++;
		}
	}
	return 0;
}

C++: // AOJ 1173

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

int main(void)
{
	while (1){
		string str;
		getline(cin, str);
		if (str == "."){
			break;
		}
		
		stack <char> st;
		bool flag = true;
		for (int i = 0; i < str.length(); i++){
			if (str[i] == '(' || str[i] == '['){
				st.push(str[i]);
			}
			if (str[i] == ')'){
				if (st.size() == 0){
					flag = false;
				}
				else if (st.top() == '('){
					st.pop();
				}
			}
			if (str[i] == ']'){
				if (st.size() == 0){
					flag = false;
				}
				else if (st.top() == '['){
					st.pop();
				}
			}
		}
		if (st.size() == 0 && flag){
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
	
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;

const int INF = INT_MAX / 4;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); i++ )
#define UREP( i, m, n ) for ( ui i = (ui)( m ); i < (ui)( n ); i++ )
#define EACH( v, c ) for ( __typeof( c.front() ) &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define RALL( c ) (c).rbegin(), (c).rend()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

int main()
{
	while ( true )
	{
		string line;
		getline( cin, line );

		if ( line == "." )
		{
			break;
		}

		bool yes = true;
		char c;
		stack<char> st;
		istringstream iss( line );

		while ( iss >> c )
		{
			if ( c == '(' )
			{
				st.push( '(' );
			}
			else if ( c == '[' )
			{
				st.push( '[' );
			}
			else if ( c == ')' )
			{
				if ( !st.empty() && st.top() == '(' )
				{
					st.pop();
				}
				else
				{
					yes = false;
					break;
				}
			}
			else if ( c == ']' )
			{
				if ( !st.empty() && st.top() == '[' )
				{
					st.pop();
				}
				else
				{
					yes = false;
					break;
				}
			}
		}

		if ( yes )
		{
			cout << "yes" << endl;
		}
		else
		{
			cout << "no" << endl;
		}
	}				

	return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cctype>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)

bool dfs(string str){
    //cout <<str <<endl;
    bool ret = true;
    REP(i, str.length()){
        if(str[i] == '('){
            int cnt = 0;
            bool findflg = false;
            for(int j = i + 1; j < str.length(); j++){
                if(str[j] == '(') cnt++;
                else if(cnt == 0 && str[j] == ')'){
                    ret = min(ret, dfs(str.substr(i + 1, j - i - 1)));
                    findflg = true;
                    break;
                }
                else if(str[j] == ')') cnt--;
            }
            if(!findflg) return false;
        }
        //////
        if(str[i] == '['){
            int cnt = 0;
            bool findflg = false;
            for(int j = i + 1; j < str.length(); j++){
                if(str[j] == '[') cnt++;
                else if(cnt == 0 && str[j] == ']'){
                    ret = min(ret, dfs(str.substr(i + 1, j - i - 1)));
                    findflg = true;
                    break;
                }
                else if(str[j] == ']') cnt--;
            }
            if(!findflg) return false;
        }
    }
    return ret;
}

int main(){
    string str;
    while(getline(cin, str)){
        if(str == ".") break;
        cout <<((dfs(str))? "yes" : "no") <<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
bool solve(string str){
	stack<char> stk;
	for(int i=0; i<str.length(); ++i){
		if(str[i]==')' || str[i]==']'){
			if(stk.empty() || str[i]!=stk.top())	return false;
			stk.pop();
		}else if(str[i]=='(')	stk.push(')');
		else if(str[i]=='[')	stk.push(']');
	}
	return stk.empty();
}
int main(){
	string str;
	while(getline(cin,str)){
		if(str==".")	break;
		cout << (solve(str)? "yes": "no") << endl;
	}
}

C++: #include <stdio.h>



int main(void){
  char c, moji[101];
  int maru, kaku;
  bool end = true;
  while(1){ 
    if(end){
      maru = 0;
      kaku = 0;
    }
    end = false;
    for(int i=0; i<101; i++){
      scanf("%c", &c);
      if(c == '\n'){
	moji[i] = '\0';
	break;
      }else{
	moji[i] = c;
      }
    }
    if(moji[0] == '.'){
      break;
    }
    for(int i=0; i<101; i++){
      if(moji[i] == '.'){
	end = true;
	break;
      }else if(moji[i] == '('){
	maru++;
      }else if(moji[i] == ')'){
	maru--;
	if(maru<0){
	  break;
	}
      }else if(moji[i] == '['){
	kaku++;
      }else if(moji[i] == ']'){
	kaku--;
	if(kaku<0){
	  break;
	}
      }else if(moji[i] == '\0'){
	break;
      }
    }
    if(end){
      if(maru == 0 && kaku == 0){
	printf("yes\n");
      }else{
	printf("no\n");
      }
    }
  }
  return 0;
}