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 <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) string((s).rbegin(), (s).rend())
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;

int main(){

	char m[200];

	m[')'] = '(';
	m[']'] = '[';

	while(1){
		string s;
		getline(cin, s);
		if(s.size() == 1 && s[0] == '.')break;
		stack<char> st;
		rep(i, s.size()){
			if(s[i] == '(' || s[i] == '[') st.push(s[i]);
			if(s[i] == ')' || s[i] == ']'){
				if(st.size() < 1){
					st.push('a');
					break;
				}
				if(st.top() == m[s[i]]){
					st.pop();
				}else{
					break;
				}
			}
		}
		cout << (st.size()?"no":"yes") << endl;
	}

	return 0;
}

C++: //#include <bits/stdc++.h>
#include <iostream>
#include <stack>
using namespace std;
#define MAX 300000

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

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

using namespace std;

bool solve(string S)
{
	stack<char> s;

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

		if (s.empty()) { return false; }

		if (S[i] == ')' || S[i] == ']')
		{
			if (s.top() != (S[i] == ')' ? '(' : '['))
			{
				return false;
			}
			
			s.pop();
		}
	}

	return s.empty();
}

int main()
{
	string S;

	while (true)
	{
		cin >> S;

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

		cout << (solve(S) ? "yes" : "no") << endl;
	}
	
	return 0;
}

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

using namespace std;

int main()
{
  int no,size;
  string end(".");
  char a5;

  while(1){
    string v;
    stack<char> sta;
    no = 0;
    getline(cin,v);

    if(v == end){
      break;
    }

    for(char e : v){
      if(e == '[' || e == '('){
        sta.push(e);
      }
      else if(e == ']'){
        a5 = sta.top();
        sta.pop();

        if(a5 != '['){
          no = 1;
        }
      }
      else if(e == ')'){
        a5 = sta.top();
        sta.pop();

        if(a5 != '('){
          no = 1;
        }
      }
      if(no == 1){
        break;
      }
    }

    size = sta.size();

    if(size != 0){
      no = 1;
    }

    if(no == 1){
      cout<<"no"<<endl;
    }
    else{
      cout<<"yes"<<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;
		stack<char> st;

		for ( auto &c : line )
		{
			if ( c == '(' || c == '[' )
			{
				st.push( c );
			}
			else if ( c == ')' || c == ']' )
			{
				int c2 = ( c == ')' ? '(' : '[' );

				if ( !st.empty() && st.top() == c2 )
				{
					st.pop();
				}
				else
				{
					yes = false;
				}
			}
		}

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

	return 0;
}

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

int main(){
  char ch;
  while(1){
    stack<int> S1,S2;
    scanf("%c",&ch);
    if(ch=='.')break;
    int i=0;
    bool flag=0;
    while(1){
      if(i!=0)scanf("%c",&ch);
      if(ch=='.')break;
      
      if(ch=='[') S1.push(i);
      else if(!S2.empty()){
	if(ch==']'&&S1.size()>0&&S1.top()>S2.top()) S1.pop();
	else if(ch==']'&&S1.size()==0)flag=1;
      }else if(ch==']'&&S1.size()>0)S1.pop();
      else if(ch==']')flag=1;
      
      if(ch=='(')S2.push(i);
      else if(!S1.empty()){
	if(ch==')'&&S2.size()>0&&S2.top()>S1.top()) S2.pop();
	else if(ch==')'&&S2.size()==0)flag=1;
      }else if(ch==')'&&S2.size()>0) S2.pop();
      else if(ch==')')flag=1;
      i++;
    }
    if(S1.size()==0&&S2.size()==0&&flag!=1) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    scanf("%c",&ch);
  }
 return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;


main()
{
  string s;
  while( 1 ) {
    getline( cin, s );
    if( s == "." ) break;

    stack<bool> st;
    bool flag = true;
    for(int i=0; i<s.size(); i++) {
      if( s[i] == '(' ) st.push( true );
      if( s[i] == '[' ) st.push( false );
      if( s[i] == ')' ) {
	if( st.size() == 0 ) {flag = false; break;}
	bool tmp = st.top(); st.pop();
	if( !tmp ) {flag = false; break;}  
      }
      if( s[i] == ']' ) {
	if( st.size() == 0 ) {flag = false; break;}
	bool tmp = st.top(); st.pop();
	if( tmp ) {flag = false; break;}  
      }
    }

    if( flag && st.size() == 0 ) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}