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;
string s;
int main(){
	G:
	while(getline(cin,s),s!="."){
		stack<char> p;
		for(int i=0;i<s.length();i++){
			if(s[i]=='('||s[i]=='[')p.push(s[i]);
			if(s[i]==')'){if(p.empty()||p.top()!='('){cout<<"no"<<endl;goto G;}p.pop();}
			if(s[i]==']'){if(p.empty()||p.top()!='['){cout<<"no"<<endl;goto G;}p.pop();}
		}
		cout<<(p.empty()?"yes":"no")<<endl;
	}

}

C++: #include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i, n) for(int i=0; i<(n); ++i)

bool isBalancedS(const string &s) {
    int cnt = 0;
    rep(i, s.size()) {
        if(s[i] == '[') cnt++;
        if(s[i] == ']') cnt--;
        if(cnt < 0) return false;
    }
    if(cnt > 0) return false;
    return true;
}
bool isBalancedR(const string &s) {
    int cnt = 0;
    rep(i, s.size()) {
        if(s[i] == '(') cnt++;
        if(s[i] == ')') cnt--;
        if(cnt < 0) return false;
    }
    if(cnt > 0) return false;
    return true;
}

bool isBalanced(const string &s) {
    if(!isBalancedS(s)) return false;
    if(!isBalancedR(s)) return false;
    // check substring
    for(int i=0; i<s.size(); ++i) {
        if(s[i] == '(') {
            int len = 0;
            int cnt = 1;
            for(int j=i+1; j<s.size(); ++j, ++len) {
                if(s[j] == '(') cnt++;
                if(s[j] == ')') cnt--;
                if(cnt==0) break;
            }
            if(!isBalancedS(s.substr(i+1, len))) return false;
        } else if(s[i] == '[') {
            int len = 0;
            int cnt = 1;
            for(int j=i+1; j<s.size(); ++j, len++) {
                if(s[j] == '[') cnt++;
                if(s[j] == ']') cnt--;
                if(cnt==0) break;
            }
            if(!isBalancedR(s.substr(i+1, len))) return false;
        }
    }
    return true;
}

int main(void){
    string s;
    while(getline(cin, s) && s!=".") {
        if(isBalanced(s)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}

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

using namespace std;

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

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

using namespace std;

int main(){
	string s;
	stack<char> st;
	while(getline(cin,s)){


		for(int i=0;i<s.size();i++){
		char ch=s[i];

		if(ch=='.')break;


		if(ch=='('||ch=='['){
			st.push(s[i]);
		}


		if(ch==')'){
			if(st.top()=='('){
				st.pop();
			}else if(st.top()=='('||st.empty())
				cout<<"no"<<endl;
			break;
		}

		if(ch==']'){
			if(st.top()=='['){
				st.pop();
			}else if(st.top()=='('||st.empty()){
				cout<<"no"<<endl;
				break;
			}
		}
	}


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


	}
}

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

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

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  string s;
  while(getline(cin,s)){
    if(s==".") return 0;
    stack<int> ss;
    for(int i=0;i<s.length();i++){
      if(s[i]=='('){
        ss.push(0);
      }else if(s[i]=='['){
        ss.push(1);
      }else if(s[i]==')'){
        if(ss.empty()){
          cout << "no" << endl;
          goto next;
        }
        if(ss.top()==0){
          ss.pop();
        }else{
          cout << "no" << endl;
          goto next;
        }
      }else if(s[i]==']'){
        if(ss.empty()){
          cout << "no" << endl;
          goto next;
        }
        if(ss.top()==1){
          ss.pop();
        }else{
          cout << "no" << endl;
          goto next;
        }
      }
    }
    if(ss.empty()){
      cout << "no" << endl;
    }else{
      cout << "yes" << endl;
    }
    next:
    continue;
  }
  return 0;
}

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

int main() {
	string b;
	int i, c=0,d=0,end=0;
	while (1) {
		getline(cin,b);
		for (i = 0; i<size(b); i++) {
				if (b[i] == '(') { c += 1; }
				if (b[i] == ')') { c -= 1; }
				if (b[i] == '[') { d += 1; }
				if (b[i] == ']') { d -= 1; }
				if (c < 0 || d < 0) { break; }
				if (b[i] == '.'&&end == 1) { end = 2; }
				if (b[i] == '.'&&end==0) {end = 1;}
		}

			if (c == 0 && d == 0) {cout << "yes"<<endl; }
			else { cout << "no"<<endl; }
			c = 0, d = 0;
			if (end == 2) { break; }
			end = 0;
	};
	return 0;
}

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


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