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>

using namespace std;

template<typename Iter>
Iter ss( Iter it, Iter const end, typename Iter::value_type const c )
{
    for( ; it<end; ++it ) {
        if ( *it == c )
            return it;
        if ( *it == '(' )
            if ( (it = ss( it+1, end, ')' )) == end )
                break;
        if ( *it == '[' )
            if ( (it = ss( it+1, end, ']' )) == end )
                break;
    }
    return end;
}

template<typename Range>
bool ff( Range const& r )
{
    for( auto it=r.begin(); it<r.end(); ++it ) {
        if ( *it == ')' || *it == ']' )
            return false;
        if ( *it == '(' )
            if ( ( it = ss( it+1, r.end(), ')' ) ) == r.end() )
                return false;
        if ( *it == '[' )
            if ( ( it = ss( it+1, r.end(), ']' ) ) == r.end() )
                return false;
    }
    return true;
}



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

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

using namespace std;

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

void solve(string& s){
    int n=s.size();
    stack<char> st;
    st.push('a');
    rep(i,n){
        if(s[i]=='(')st.push('(');
        if(s[i]=='[')st.push('[');
        if(s[i]==')'){
            if(st.top()=='(')st.pop();
            else{
                cout<<"no"<<endl;
                return ;
            }
        }
        if(s[i]==']'){
            if(st.top()=='[')st.pop();
            else{
                cout<<"no"<<endl;
                return ;
            }
        }
    }
    if(st.size()==1)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
}
int main(){
    string s;
    while(getline(cin,s),s!=".")solve(s);
    return 0;
}

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

using namespace std;

int main(){
	string s;
	while(getline(cin, s), s != "."){
		vector<int> a;
		for(int i = 0; i < s.size(); i++){
			switch(s[i]){
			case '(':
			a.push_back(0);
			break;
	
			case '[':
			a.push_back(1);
			break;
	
			case ')':
			if(a.empty()){
				a.push_back(-1);
				break;
			}
			else if(a.back() == 0){
				a.pop_back();
				break;
			}else{
				a.push_back(-1);
				break;
			}

			case ']':
			if(a.empty()){
				a.push_back(-1);
				break;
			}else if(a.back() == 1){
				a.pop_back();
				break;
			}else{
				a.push_back(-1);
				break;
			}
		
			default :
			break;
			}	
			if(!a.empty() && a.back() == -1) break;
		}
		if(a.empty()) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdint>
#include <cassert>
#include <vector>
#include <stack>
#include <string>

bool is_paren(int c) {
  return (c == '(' || c == ')' || c == '[' || c == ']');
}

bool is_openparen(int c) {
  return (c == '(' || c == '[');
}

char to_closeparen(int c) {
  if (c == '(') return ')';
  if (c == '[') return ']';
  assert(false);
}

int testcase_ends() {
  char buf[128];
  fgets(buf, sizeof buf, stdin);
  std::string s = buf;
  if (s.back() == '\n') s.pop_back();
  if (s == ".") return 1;

  std::stack<char> st;
  for (auto c: s) {
    if (!is_paren(c)) continue;
    if (is_openparen(c)) {
      st.push(to_closeparen(c));
    } else {
      if (st.empty() || st.top() != c) return puts("no"), 0;
      st.pop();
    }
  }
  puts(st.empty()? "yes": "no");
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}

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

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

C++: #include<iostream>
#include<string>
#include<stack>
using namespace std;
int main(){
	while(1){
		bool flag;
		flag = true;
		string str;
		stack<int> num;
		getline(cin,str);
		if(str==".")	break;
		for(int i=0;i<str.size();i++){
			if(str[i]=='[')	num.push(1);
			else if(str[i]==']'){
				if(num.top()==1)	num.pop();
				else{
						flag=false;
						break;
				}
			}
			else if(str[i]==')'){
				if(num.top()==2)	num.pop();
				else{
						flag=false;
						break;
				}
			}
			else if(str[i]=='(')	num.push(2);
			
		}
		if(num.size()==0&&flag)	cout << "yes\n";
		else	cout << "no\n";
	}
}

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

using namespace std;

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

int main() {
  string str;
  while (true) {
    getline(cin, str);
    if (str == ".") break;
    stack<char> st;
    bool ok = true;
    rep (i, str.size()) {
      if (str[i] == '(') st.push('(');
      if (str[i] == '[') st.push('[');
      if (str[i] == ')') {
	if (st.empty()) {
	  ok = false;
	  break;
	}
	char c = st.top();
	st.pop();
	if (c != '(') {
	  ok = false;
	  break;
	}
      }
      if (str[i] == ']') {
	if (st.empty()) {
	  ok = false;
	  break;
	}
	char c = st.top();
	st.pop();
	if (c != '[') {
	  ok = false;
	  break;
	}
      }
    }
    if (!st.empty()) ok = false;
    if (ok) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}