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 <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <complex>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << "\n"
#define input(X) getline(cin,X)
static const int INF = 1e+9+7;
static const ll INFL = 1e+18+7;
ll n,m,l;
int p;
string s,t;
ll d[200010],dp[300][300];
char field[200][200];

vc split(string args){
  vc res;
  rep(i,0,args.sz){
    switch(args[i]){
      case '(':
      case ')':
      case '[':
      case ']':
        res.pb(args[i]);
        break;
      default:
        break;
    }
  }
  return res;
}

int main(){
  while(input(s),s != "."){
    stack<char> ans;
    vc vec = split(s);
    rep(i,0,vec.sz){
      if(vec[i] == '[' || vec[i] == '(')ans.push(vec[i]);
      else{
        if(ans.empty())ans.push(vec[i]);
        else if(vec[i] == ']'){
          if(ans.top() == '[')ans.pop();
          else ans.push(vec[i]);
        }else if(vec[i] == ')'){
          if(ans.top() == '(')ans.pop();
          else ans.push(vec[i]);
        }
      }
    }
    if(ans.empty())puts("yes");
    else puts("no");
  }
  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(s[i]);
      if(ch[i]==')' && str.top()=='(')str.pop();
      if(ch[i]==']' && str.top()==']')str.pop();
    }

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

  }

  return 0;
}

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

#define pb         push_back

const int INF = 100000000;

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

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

				char c = st.top();
				st.pop();
				if(c != '[') success = false;
			}
		}
		if(st.size() != 0) success = false;

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

	}
	
	return 0;
}

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

int main(){
  
  string str;

  while(1){

    getline(cin, str);
    if(str[0] == '.') break;

    vector<int> v;

    for(int i = 0; i < (int)str.size(); i++){
      if(str[i] == '('){
	v.push_back(0);
      }else if(str[i] == ')'){
	v.push_back(1);
      }else if(str[i] == '['){
	v.push_back(2);
      }else if(str[i] == ']'){
	v.push_back(3);
      }
    }

    int cnt = 0, judge = 0, o[2] = {}, p[2] = {};

    for(int i = 0; i < (int)v.size(); i++){
      if(v[i] == 0){
	for(int j = i+1; j < (int)v.size(); j++){
	  if(v[j] == 1){
	    for(int l = i+1; l < j; l++){
	      if(v[l] == 0) o[0]++;
	      if(v[l] == 1) o[1]++;
	      if(v[l] == 2) p[0]++;
	      if(v[l] == 3) p[1]++;
	      //   cout << o[0] << o[1] << p[0] << p[1] << endl;
	    }
	    
	    if(o[0] == o[1] && p[0] == p[1]){
	      v[i] = 7;
	      v[j] = 7; 
	    }
	      o[0] = o[1] = p[0] = p[1] = 0;

	  }
	}
      }else if(v[i] == 2){
	for(int j = i+1; j < (int)v.size(); j++){
	  if(v[j] == 3){
	    for(int l = i+1; l < j; l++){
	      if(v[l] == 0) o[0]++;
	      if(v[l] == 1) o[1]++;
	      if(v[l] == 2) p[0]++;
	      if(v[l] == 3) p[1]++;
	      //   cout << o[0] << o[1] << p[0] << p[1] <<  v[0] <<endl;
	    }
	    
	  
	    if(o[0] == o[1] && p[0] == p[1]){
	      v[i] = 7;
	      v[j] = 7;
	    }
	    o[0] = o[1] = p[0] = p[1] = 0;
  	  }
	}
      }
      /*   for(int k = 0; k < (int)v.size(); k++){
	   cout << v[k];
	   }
	   cout << endl;
      */
    }
     
    
    for(int i = 0; i < (int)v.size(); i++){
      if(v[i] == 7){
    	cnt++; 
      }
    }

    if(cnt == (int)v.size()){
      cout << "yes" << endl;
      cnt = 0;
    }else if(cnt != (int)v.size()) cout << "No" << endl;
    // cout << cnt << " " << (int)v.size() << endl;
  }
  
  return 0;
}

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

int si = 0;
string S;
bool parse(char c)
{
  bool ans = true;
  for(; si < S.length(); si++)
  {
    if(S[si] == c)
      return ans;
    switch(S[si])
    {
      case '(':
        si++;
        ans &= parse(')');
        break;
      case '[':
        si++;
        ans &= parse(']');
        break;
    }
  }
  return false;
}

int main()
{
loop:
  si = 0;
  getline(cin, S);
  if(S == ".")
    return 0;
  cout << (parse('.') ? "yes" : "no") << endl;
  goto loop;
}

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

int main(){

  string str;
  stack < int > a;
  stack < int > b;

  while(1){

    getline(cin,str);
    if(str == ".")break;

    for(int i=0;i<str.size();i++){
      if(str[i] == '(') a.push(1);
      else if(str[i] == ')') a.pop();
      else if(str[i] == '[') b.push(1);
      else if(str[i] == ']') b.pop();
    }

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

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

using namespace std;

bool check(const string & str)
{
	stack<int> stk;

	for (const auto & c : str)
	{
		if (c == '(')
		{
			stk.push(0);
		}
		else if (c == ')')
		{
			if (stk.empty())return false;
			int s = stk.top(); stk.pop();
			if (s != 0)return false;
		}
		else if (c == '[')
		{
			stk.push(1);
		}
		else if (c == ']')
		{
			if (stk.empty())return false;
			int s = stk.top(); stk.pop();
			if (s != 1)return false;
		}
	}

	if (stk.empty())return true;

	return false;
}

int main()
{
	while (true)
	{
		string str;
		getline(cin, str);
		
		if (str == ".")return 0;

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