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

bool f(string &s) {
  vector<char> stack;
  for(int i=0; i<s.length(); ++i) {
    if(s[i] == '(') {
      stack.push_back('(');
    }
    if(s[i] == '[') {
      stack.push_back('[');
    }
    if(s[i] == ']') {
      if(stack.empty()) return false;
      if(stack.back() == '[') {
        stack.pop_back();
      }else{
        return false;
      }
    }
    if(s[i] == ')') {
      if(stack.empty()) return false;
      if(stack.back() == '(') {
        stack.pop_back();
      }else{
        return false;
      }
    }
  }
  if(stack.size() == 0) return true;
  return false;
}

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

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

#define rep(i,x,y) for(int (i)=(x);(i)<(y);(i)++)

int main()
{
  while(true){

    char s;

    stack<char> st;
    bool endflag=true;
    bool flag=true;

    while((s=getchar())!='.'){
      endflag=false;
      if(s=='['){
        st.push('[');
      }
      if(s=='('){
        st.push('(');
      }
      if(s==']'){
        if(st.empty()==true){
          flag=false;
          break;
        }else{
          if(st.top()=='['){
            st.pop();
          }else{
            flag=false;
            break;
          }
        }
      }
      if(s==')'){
        if(st.empty()==true){
          flag=false;
          break;
        }else{
          if(st.top()=='('){
            st.pop();
          }else{
            flag=false;
            break;
          }
        }
      }
    }

    if(endflag==true){
      break;
    }
    if(st.empty()==false){
      flag=false;
    }

    if(flag==true){
      cout<<"yes"<<endl;
    }else{
      cout<<"no"<<endl;
    }
    while(getchar()!='\n');
  }

  return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;

template<typename A,typename B> inline void chmin(A &a,B b){if(a>b) a=b;}
template<typename A,typename B> inline void chmax(A &a,B b){if(a<b) a=b;}
//-----------------------------------------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    while(true)
    {
        getline(cin,s);
        if(s[0]=='.') break;

        stack<char> St;

        bool ok=true;
        REP(i,s.size()){
            if(s[i]=='(') St.push(s[i]);
            if(s[i]=='[') St.push(s[i]);
            if(s[i]==')'){
                if(St.empty() || St.top()!='('){ ok=false;break;}
                else St.pop();
            }
            if(s[i]==']'){
                if(St.empty() || St.top()!='['){ ok=false;break;}
                else St.pop();
            }
        }
        if(!St.empty()) ok=false;
        cout<<(ok?"yes":"no")<<endl;

    }
}

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

#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define PRINT(STR) cout << (STR) << endl

typedef long long ll;
using namespace std;

int main() {
	char stc[1024];
	int counter = 0;
	string str;
	while (str = "", getline(cin, str), str != ".") {
		counter = 0;
		REP(i, str.size()) {
			if (str[i] == '[' || str[i] == '(') {
				stc[counter++] = str[i];
			} else if (str[i] == ']') {
				if (counter == 0 || stc[--counter] != '[') {
					PRINT("no");
					break;
				}
			} else if (str[i] == ')') {
				if (counter == 0 || stc[--counter] != '(') {
					PRINT("no");
					break;
				}
			}
			if (i == str.size() - 1) {
				PRINT("yes");
			}
		}
	}
	return 0;
}

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

bool issame(char a,char b){
     if(a=='(')return b==')';
     if(a=='[')return b==']';
}

int main(){
     while(1){
	  string str;
	  getline(cin,str);
	  if(str[0]=='.')return 0;
	  char in;
	  stack<char> sta;
	  bool iscorrect=true;
	  int count=0;
	  while(in=str[count],in!='.'){
	       //cout<<in;
	       if(in=='('||in=='['){
		    sta.push(in);
		    //cout<<in<<endl;
	       }else if(in==')'||in==']'){
		    if(sta.empty()){
			 iscorrect=false;
			 break;
		    }
		    if(!issame(sta.top(),in)){
			 iscorrect=false;
			 break;
		    }
		    sta.pop();
	       }
	       count++;
	  }
	  cout<<((iscorrect&&sta.empty())? "yes":"no")<<endl;
     }
}

C++: #include<bits/stdc++.h>
#define dump(a) cout << (#a) << "=" << (a) << endl
using namespace std;

stack<char> store;

string pass(string &line)
{
	string new_line;
	for(int i=0; i<line.size(); i++) {
		if ((line[i] == '[') || (line[i] == '(') ||
			(line[i] == ']') || (line[i] == ')') ) {
			new_line+=line[i];
		}
	}
	return new_line;
}


void popper(bool &isCheck) {
}

int main() {
	string line;
	while(getline(cin, line))
	{
		if (line[0] == '.') { break; }
		bool isCheck=true;
		string new_line=pass(line);
		for(int i=0; i<new_line.size(); i++) {
			//dump(i);
			//dump(new_line[i]);
			if(new_line[i] == '[' || new_line[i] == '(') {
				store.push(new_line[i]);
			}
			else if(new_line[i] == ']') {
				if (store.size() == 0) { isCheck=false; }
				char value = store.top();
				store.pop();
				if (value != '[') {
					isCheck=false;
					continue;
				}
			}
			else if(new_line[i] == ')') {
				if (store.size() == 0) {
					isCheck=false;
					continue;
				}
				char value = store.top();
				store.pop();
				if (value != '(') {
					isCheck=false;
				}
			}
		}

		cout << (isCheck ? "yes":"no") << endl;
	}

	return EXIT_SUCCESS;
}

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

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