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 <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	string s;
	int x=0;
	stack<int> st;
	while(true){
		cinl(s);
		if(s==".") return 0;
        while(st.size() !=0 ){
        	st.pop();
        }	
        x=0;
        for(int i=0;i<s.size();i++){
        	if(s[i]=='('){
        		st.push(1);
        	}
        	if(s[i]=='['){
        		st.push(2);
        	}
        	if(s[i]==')'){
        		if(st.size()==0){
        			x=1;
        			break;
        		}
        		if(st.top()==1){
        			st.pop();
        		}
        		else{
        			x=1;
        			break;
        		}
        	}
        	if(s[i]==']'){
        		if(st.size()==0){
        			x=1;
        			break;
        		}
        		if(st.top()==2){
        			st.pop();
        		}
        		else{
        			x=1;
        			break;
        		}
        	}
        }
        if(st.size()!=0) x=1;
        if(x==0) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
	}
}

C++: //
//  main.cpp
//  The Balance of the World
//
//  Created by x15071xx on 2017/06/16.
//  Copyright ?? 2017??´ AIT. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <string>
using namespace std;
int main(int argc, const char * argv[]) {
    
    
    while(1){
        string yn = "yes";
        string str;
        vector<char> st;
        getline(cin, str);
        
        
        if (str == ".") {
            break;
        }
        
        for (int i = 0;  i < str.size(); i++) {
            
            if (str[i] == '(' || str[i] == '[') {
                st.push_back(str[i]);
            }
            
            if (!st.empty()) {
                if (str[i] == ')') {
                    
                    
                    if ('(' != st.back()) {
                        yn = "no";
                        break;
                    }
                    
                    st.pop_back();
                    
                }
                
                if (str[i] == ']') {
                    
                    if ('[' != st.back()) {
                        yn = "no";
                        break;
                    }
                    
                    st.pop_back();
                    
                }
            }
            

        }
        
        if (!st.empty()) {
            yn = "no";
        }
        
        cout << yn << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <bitset>
#include <stack>
#include <cstdlib>
#define REP(i,n) for(int i = 0; n > i; i++)
#define MOD 1000000007
using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;
typedef long long int ll;
char str[101];
map<char, char> kako = { {'(',')'},{'[',']'} };
int is_balanced(int s) {
	for (int i = s+1; strlen(str) > i; i++) {
		if (str[i] == ')' || str[i] == ']') {
			if(str[i] != kako[str[s]])
				return -1;
			else {
				return i;
			}
		}
		if (str[i] == '(' || str[i] == '[') {
			i = is_balanced(i);
			if (i == -1) return -1;
		}
	}
	return -1;
}

int main() {
	while (1) {
		memset(str, 0, sizeof(str));
		for(int i = 0; ;i++) {
			scanf("%c", &str[i]);
			if (str[i] == '.') break;
		}
		scanf("%*c");
		if (!strcmp(str, "."))
			return 0;
		bool f = true;
		REP(i, strlen(str)) {
			if (str[i] == ')' || str[i] == ']') {
				printf("no\n");
				f = false;
				break;
			}
			if (str[i] == '(' || str[i] == '[') {
				i = is_balanced(i);
				if (i == -1) {
					printf("no\n");
					f = false;
					break;
				}
			}
		}
		if (f) printf("yes\n");
	}

	return 0;
}

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

using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::stack;

int main(void) {
    string s; 
    stack<char> st; 
    char comp;
    bool check;

    while (getline(cin, s)) {
        if (s[0] == '.') {
            break;
        }
        check = true;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == '(' || s[i] == '[') {
                st.push(s[i]); 
            } else if (s[i] == ')' || s[i] == ']') {
                if (st.empty()) {
                    check = false;
                    break;
                }
                comp = st.top();   
                st.pop();
                if ((comp == '(' && s[i] == ']') || (comp == '[' && s[i] == ')')) {
                    check = false;
                    break;
                }
            }
        }
        if (check == true) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
    return 0;
}

C++:     #include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
using namespace std;


int main(){
    char c;
    queue<string> res;
    bool f = true;
    deque<int> deq;
    while(cin >> c){
        if(c == '.'){
            if(!deq.empty())f = false;
            deq.clear();
            res.push(f ? "yes" : "no");
            f = true;
        }
        
        if(c == '(')deq.push_back(1);
        if(c == '[')deq.push_back(2);
        if(f && c == ')'){
            if(deq.empty())f = false;
            if(f){
                int now = deq.back();
                deq.pop_back();
                if(now == 2)f = false;
            }
        }
        if(f && c == ']'){
            if(deq.empty())f = false;
            if(f){
                int now = deq.back();
                deq.pop_back();
                if(now == 1)f = false;
            }
        }
    }
    while(!res.empty()){
        string r = res.front();
        res.pop();
        if(res.empty())break;
        cout << r << endl;
    }
}