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

int check( string str ){
  stack <char> ch;
  int i;
  int len = str.size();
  for( i = 0; i < len; i++ ){
    if( !(str[i] == '(' || str[i] == ')' || str[i] == '[' || str[i] == ']' ))continue;
    if( str[i] == '(' || str[i] == '[') ch.push(str[i]);
    else {
     
      /* if( ch.empty() ){
	  return 0;
	}
      */
      if( ch.top() != '(' && str[i] == ')' ) return 0;
      else if( ch.top() == '(' && str[i] == ')' ) ch.pop();
      else if( ch.top() != '[' && str[i] == ']' ) return 0;
      else if( ch.top() == '[' && str[i] == ']' ) ch.pop();

    }
  }
    
  if( !( ch.empty() ) ) return 0;
  return 1;
}

int main(){
 
  string str;
  while( getline(cin,str) ){
    if( str == "." ) break;
    if( check(str) == 1 ) cout << "yes" << endl;
    else cout << "no" << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
bool solve(string str){
  map<char, int> t;
  t['['] = 1; t[']'] = 1;
  t['('] = 2; t[')'] = 2;
  stack<char> stk;
  REP(i,str.size()){
    if(str[i]=='['||str[i]=='('){
      stk.push(t[str[i]]);
    }else if(str[i]==']'||str[i]==')'){
      if(stk.empty()||stk.top()!=t[str[i]]) return false;
      else stk.pop();
    }
  }
  return stk.empty();
}
int main(){
  string str;
  while(getline(cin,str)){
    if(str==".") break;
    if(solve(str)) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}

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

int main() {
    string str;
    while(getline(cin, str), str != ".") {
        bool is_ok = [str]() {
            stack<char> before_par_type;
            for(int i=0; i<str.size(); ++i) {
                char c = str[i];
                if(c == '[' || c == '(') {
                    before_par_type.push(c);
                } else if(c == ']') {
                    if(before_par_type.size() == 0) return false;
                    if(before_par_type.top() == '[') {
                        before_par_type.pop();
                    } else {
                        return false;
                    }
                } else if(c == ')') {
                    if(before_par_type.size() == 0) return false;
                    if(before_par_type.top() == '(') {
                        before_par_type.pop();
                    } else {
                        return false;
                    }
                }
            }
            return before_par_type.size() == 0;
        }();
        
        cout << (is_ok ? "yes" : "no") << endl;
    }
}

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

using namespace std;

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

	bool flag=true;
	while(getline(cin,s)){

		if(s==".")break;

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

			




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


			else if(ch==')'){
				if(st.top()=='('){
					st.pop();
				}else if(st.top()=='['||st.empty())
					flag=false;
					break;
			}

			if(ch==']'){
				if(st.top()=='['){
					st.pop();
				}else if(st.top()=='('||st.empty()){
					flag=false;
					break;
				}
			}

		}


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

	}
return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<functional>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

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

		stack<char> stk;
		bool flag = true;
		REP(i, 0, str.size()) {
			if (str[i] == '(' || str[i] == '[') stk.push(str[i]);
			else if (str[i] == ')') {
				if (stk.empty()) {
					flag = false;
					break;
				}
				
				char c = stk.top();
				stk.pop();
				if (c != '(') {
					flag = false;
					break;
				}
			}
			else if (str[i] == ']') {
				if (stk.empty()) {
					flag = false;
					break;
				}

				char c = stk.top();
				stk.pop();
				if (c != '[') {
					flag = false;
					break;
				}
			}
		}

		if (flag && stk.empty()) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

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

#define int long long

char* Solve(string S)
{
    stack<char> s;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] == '(') s.push(')');
        else if (S[i] == '[') s.push(']');
        else if (S[i] == ')' || S[i] == ']')
        {
            if (s.empty() || s.top() != S[i]) return "no";
            s.pop();
        }
    }
    if (!s.empty()) return "no";
    return "yes";
}

signed main()
{
    string S;
    while (getline(cin, S), S != ".")
    {
        printf("%s\n", Solve(S));
    }
    return 0;
}

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

using namespace std;

int main(){
	int rk=0, sk=0, len=0;
	char in;
	bool check=false;
	stack<char> st;
	st.push(' ');
	while(true){
		scanf("%c", &in);
		if( in == '\n' ) continue;
		if( in == '.' && len == 0 ) break;
		len++;
		if( in == '(' ){ rk++; st.push('('); }
		if( in == '[' ){ sk++; st.push('['); }
		if( in == ')' ){
			if( --rk < 0 || st.top() != '(' )
				check=true;
			st.pop();
		}
		if( in == ']' ){
			if( --sk < 0 || st.top() != '[' )
				check=true;
			st.pop();
		}
		if( in == '.' ){
			cout << (check?"no":"yes") << endl;
			rk = 0;
			sk = 0;
			len = 0;
			check = false;
		//	st.clear();
		}
	}
	return 0;
}

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

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