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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <string.h>
#include <cassert>

#ifdef _DEBUG
#define typeof(X) std::identity<decltype(X)>::type //C++0x (for vs2010)
#else
#define typeof(X) __typeof__(X) // for gcc
#endif

#define sz(a)  int((a).size())
#define FOREACH(it, c) for (typeof((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define FOR(i,count) for (int i = 0; i < (count); i++)
#define V_CIN(v) do{for(int i = 0; i < sz(v); i++) cin >> (v)[i];}while(0)
#define all(c) (c).begin(),(c).end()

using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
const int MODULO = 1000000007;

typedef pair<int,int> Pii;

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

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    while(getline(cin,s)){
        stack<char> w;
        int d=0;
        if(s[0]=='.')break;
        for(int i=0;i<s.size();i++){
            if(s[i]=='['||s[i]=='(')w.push(s[i]);
            else if(s[i]==']'){
                if(w.top()=='[')w.pop();
            }
            else if(s[i]==')'){
                if(w.top()=='(')w.pop();
            }
        }
        if(w.empty())cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

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

using namespace std;

int main(void){

  string s;
  stack <string> st;
  string::iterator it;
  
  while(getline(cin,s)){
    
    //cin>>s;
    it=s.end();
    it--;
    if(s.size()==1&&*it=='.')
      break;
  
    for(it=s.begin();it!=s.end();it++){

      if(*it=='('){
	st.push("(");
      }

      else if(*it=='['){
	st.push("[");
      }

      else if(*it==')'){
	if(st.empty())
	  st.push(")");
	
	if(st.top()=="(")
	  st.pop();
	else
	  st.push(")");
      }

      else if(*it==']'){
	if(st.empty())
	  st.push("]");
	
	if(st.top()=="[")
	  st.pop();
	else
	  st.push("]");
      }
    }

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

    else
      cout <<"no"<<endl;

    while(!st.empty()){
      st.pop();
    }
    
  }
  return 0;

}

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

int main(void) {
    char str[105];
    while(1){
        int z  = 0;
        while(1){
            char c; cin >> c;
            if(c == '.'){str[z] = '\0'; break;}
            str[z] = c;
            z++;
        }
        cout << str << endl;
        if(str[0] == '\0') break;
        stack<char> s;
        s.push('0');
        int flag = 1;
        for(int i = 0; str[i] != '\0'; i++){
            if(str[i] == '(') s.push(')');
            if(str[i] == '[') s.push(']');
            if(str[i] == ')'){
                if(s.top() == ')'){
                    s.pop();
                }else{
                    cout << "no" << endl;
                    flag = 0;
                    break;
                }
            }
            if(str[i] == ']'){
                if(s.top() == ']'){
                    s.pop();
                }else{
                    cout << "no" << endl;
                    flag = 0;
                    break;
                }
            }
        }
        if(flag) cout << "yes" << endl;
    }
    return 0;

}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)

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

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  while(1){
    getline(cin,s);
    if(s==".")break;
    stack<char> st;
    bool flg=true;
    
    for(int i=0;i<s.size();i++){
      if(s[i]=='('||s[i]=='['){
	st.push(s[i]);
      }else if(s[i]==')'){
	if(st.empty()){
	  flg=false;
	  break;
	}
	if(st.top()=='('){
	  st.pop();
	}else{
	  flg=false;
	  break;
	}
      }else if(s[i]==']'){
	if(st.empty()){
	  flg=false;
	  break;
	}
	if(st.top()=='['){
	  st.pop();
	}else{
	  flg=false;
	  break;
	}
      }
    }
    if(flg==false||!st.empty()){
      cout<<"no"<<endl;
    }else{
      cout<<"yes"<<endl;
    }
  }
      //if(s=="()." || s=="[]." ||s==" .")cout << " yes" ;
      //else cout << "no" ;
      //if(getline==.)break;
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define PR pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;

#define int ll

// the balance of the world

signed main(){
  while(1){
    stack<char> s;
    string str;
    getline(cin, str);
    if(str==".") break;
    
    bool ans=1;
    for(int i=0; i<str.size(); i++){
      if(str[i]=='('||str[i]=='['){
        s.push(str[i]);
      }else if(str[i]==')'||str[i]==']'){
        if(s.empty()) ans=0;
        else if(str[i]==']'&&s.top()=='['){
          s.pop();
        }else if(str[i]==')'&&s.top()=='('){
          s.pop();
        }else{
          ans=0;
        }
      }else if(str[i]=='.'){
        if(ans) cout<<"yes"<<en
        else cout<<"no"<<en
          break;
      }
    }
  }
  RE
}