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

#define int				long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define FORE( i, m, n ) FOR( i, m , n + 1 )
#define REP( i, n )     FOR( i, 0, n )
#define REPE( i, n )	FOR( i, 0, n + 1 )
#define FORR( i, m )	for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )	FOR( i, 1, n + 1 );
#define ALL( a )        (a).begin(), (a).end()             
#define MP( a, b )		make_pair( (a), (b) )
#define fi				first
#define se				second

template<class T>bool chmax( T& a, const T& b ) { if( a < b ) { a = b; return 1; } return 0; }
template<class T>bool chmin( T& a, const T& b ) { if( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

int dp[101][10001] = {};

signed main() {
	string s;
	while( 1 ) {
		getline( cin, s );  if( s == "." ) break;
		stack<char> st;

		bool flag = true;
		REP( i, s.size()  ) {
			switch( s[i] ) {
				case '(':
					st.push( '(' );
					break;
				case '[':
					st.push( '[' );
					break;
				case ')':
					if( !st.empty() && st.top() == '(' ) st.pop();
					else								 flag = false;
					break;
				case ']':
					if( !st.empty() && st.top() == '[' ) st.pop();
					else								 flag = false;
					break;
				default:
					break;
			}
		}
		if( flag && st.empty() ) cout << "yes" << endl;
		else					 cout << "no" << endl;
	}
}

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

int main(){

	
while(1){char str[250]={},ch;
	for(int i=0;i<245;i++)
	{scanf("%c",&ch);
	if(ch=='.')break;
	str[i]=ch;}
	int ks=0,kl=0,ms=0,ml=0;
	bool f=true;
	for(int i=0;i<200;i++)
	{if(str[i]=='(')ms++;
	else if(str[i]=='[')ks++;
	else if(str[i]==')'){ml++;if(ms==0){f=false;}}//cout<<i<<" ";}
	else if(str[i]==']'){kl++;if(ks==0)f=false;}
	}
	if(f!=false&&ms==ml&&ks==kl)cout<<"yes"<<endl;
	else{cout<<"no"<<endl;//ms<<ml<<ks<<kl<<endl;
	}

}


return 0;
}

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

int main(){
  char ch;

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

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

using namespace std;

int main()
{
  int end;
  stack <char> sta;
  string g;

  while(1){
    string v;
    string t;
    end = 0;

    while(1){
      cin>>v;
      t = t+v;

      for(char s : v){
        if(s == '.'){
          end = 1;
          break;
        }
      }

      if(end == 1){
        break;
      }
    }

    if(t == "."){
      break;
    }
    for(char e : t){
      if(e == '(' || e == '['){
        sta.push(e);
      }
      else if(e == ')'){
        char t = sta.top();
        sta.pop();
        if(t != '('){
          g = "no";
          break;
        }
      }
      else if(e == ']'){
        char t = sta.top();
        sta.pop();
        if(t != '['){
          g = "no";
          break;
        }
      }
    }

    if(g == "no"){
    }
    else{
      g = "yes";
    }

    cout<<g<<endl;
  }
  return 0;
}

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

int main()
{
	string str;
	while (getline(cin, str)){
		int c = 0, s = 0, f = 0;
		bool res = false;
		for (int p = 0; p < str.size(); p++){
			if (str[p] == '('){
				f = 1;
				c++;
			}
			else if (str[p] == ')'){
				if (f == 2) break;
				f = 0;
				c--;
			}
			else if (str[p] == '['){
				f = 2;
				s++;
			}
			else if (str[p] == ']'){
				if (f == 1) break;
				f = 0;
				s--;
			}
			if (c < 0 || s < 0) break;
			if (p == str.size() - 1) res = true;
		}
		if (res && !c && !s) puts("yes");
		else puts("no");
	}
	
	return 0;
}

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

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    while(getline(cin,s)&&s!="."){
        string c;
        for(int i=0;i<s.size();i++)if(s[i]==')'||s[i]=='('||s[i]=='['||s[i]==']')c+=s[i];
        int d=1;
        stack<char> w;
        for(int i=0;i<c.size();i++){
            if(w.empty()||c[i]=='['||c[i]=='(')w.push(c[i]);
            else if((c[i]==']'&&w.top()=='[')||(c[i]==')'&&w.top()=='('))w.pop();
            else break;
        }
        if(w.empty())cout<<"yes"<<endl;
        else fail:cout<<"no"<<endl;
    }
    return 0;
}

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

int main(){
	while(1){
		std::string str;
		char bef;
		int count=0;
		std::getline(std::cin,str);
		if(str==".")break;
		for(int i=0;i<str.size();i++){
			if(str[i]=='('||str[i]=='['){
				count++;
				bef=str[i];
			}else if(str[i]==')'||str[i]==']'){
				count--;
				if(!((str[i]==')'&&bef=='(')||(str[i]==']'&&bef=='['))){
					std::cout<<"no"<<std::endl;
					goto end;
				}
			}
			if(count<0){
				std::cout<<"no"<<std::endl;
				goto end;
			}
		}
		if(count==0)std::cout<<"yes"<<std::endl;
		else std::cout<<"no"<<std::endl;
		end:;
	}
	return 0;
}

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

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

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

using namespace std;

int main(void){
  string s;
  stack<char> str;

  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];

    for(int i=0;i<ch.length();i++){
      
      if(ch[i]=='(' || ch[i]=='[')str.push(ch[i]);
      if(ch[i]==')' && str.top()=='(')str.pop();
      if(ch[i]==']' && str.top()=='[')str.pop();
    }

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

  }

  return 0;
}