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++: //
//  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 (str[i] == ')') {
                
                if (!st.empty()) {
                    yn = "no";
                    break;
                }
                if ('(' != st.back()) {
                    yn = "no";
                    break;
                }
                
                st.pop_back();
                
            }
            
            if (str[i] == ']') {
                
                if (!st.empty()) {
                    yn = "no";
                    break;
                }
                
                if ('[' != st.back()) {
                    yn = "no";
                    break;
                }
                
                st.pop_back();
                
            }
    
        

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

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

int N;

bool balance(string s, int b, int e)
{
  N = 1;
  int x = 0, y = 0;
  for(int i = 0; i < s.size(); i++){
    if(s.at(i) == '(' || s.at(i) == ')')
      x++;
    if(s.at(i) == '[' || s.at(i) == ']')
      y++;
  }
  if(x & 1 || y & 1)
    return false;
  for(int i = b; i < e; i++){
    if(s.at(i) == '('){
      for(int j = i + 1; j < e; j++){
	if(s.at(j) == ')'){
	  string sub = s.substr(i + 1, j - i - 1);
	  if(balance(sub, 0, sub.size())){
	    N = 0;
	    continue;
	  }
	}
      }
      if(N)
	return false;
      else
	return true;
    }else if(s.at(i) == '['){
      for(int j = i + 1; j < e; j++){
	if(s.at(j) == ']'){
	  string sub = s.substr(i + 1, j - i - 1);
      	  if(balance(sub, 0, sub.size())){
	    N = 0;
	    continue;
	  }
	}
      }
      if(N)
	return false;
      else
	return true;
    }else if(s.at(i) == ')'){
      for(int j = 0; j < i; j++){
	if(s.at(j) == '('){
	  string sub = s.substr(j + 1, i - j - 1);
	  if(balance(sub, 0, sub.size())){
	    N = 0;
	    continue;
	  }
	}
      }
      if(N)
	return false;
      else
	return true;
    }else if(s.at(i) == ']'){
      for(int j = 0; j < i; j++){
	if(s.at(j) == '['){
	  string sub = s.substr(j + 1, i - j - 1);
	  if(balance(sub, 0, sub.size())){
	    N = 0;
	    continue;
	  }
	}
      }
      if(N)
	return false;
      else
	return true;
    }
  }
  return true;
}
       
int main()
{
  string s;
  while(1){
    getline(cin, s);
    if(s == "."){
      break;
    }else{
      if(balance(s, 0, s.size()))
	cout << "yes" << endl;
      else
	cout << "no" << endl;
    }
  }
}

C++: #ifndef _WIN32
#include<iostream>
#endif // !_WIN32

#include<string>
#include<iomanip>
#include<vector>
#include<string>
#include<stack>
using namespace std;

#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()



int main() {
	string s;
	while (getline(cin, s), s != ".") {

		int n = s.size();
		vector<int> v;
		REP(i, n) {
			if (s[i] == '(')v.push_back(0);
			if (s[i] == ')')v.push_back(1);
			if (s[i] == '[')v.push_back(2);
			if (s[i] == ']')v.push_back(3);
		}
		string res=[&]() {
			stack<int> st;
			for (auto &it : v) {
				if (it & 1) {
					if (st.empty())return "no";
					if ((st.top() | 1) != it)return "no";
					st.pop();
				}
				else {
					st.push(it);
				}
			}
			if(st.empty())return "yes";
			else return "no";
		}();
		cout << res << endl;
	}

	return 0;
}

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

std::string str;

bool calc(int p){
	for(int i=p+1;i<str.size();i++){
		if(str[i]=='('){
			if(calc(i))return true;
			else return false;
		}
		if(str[i]==')'){
			if(str[p]=='(')return true;
			else return false;
		}
		if(str[i]=='['){
			if(calc(i))return true;
			else return false;
		}
		if(str[i]==']'){
			if(str[p]=='[')return true;
			else return false;
		}
	}
}

int main(){
	while(1){
		int l=0,l2=0;
		bool p=true;
		std::getline(std::cin,str);
		if(str==".")break;
		for(int i=0;i<str.size();i++){
			if(str[i]=='(')l++;
			if(str[i]==')')l--;
			if(str[i]=='[')l2++;
			if(str[i]==']')l2--;
			if(l<0||l2<0){
				std::cout<<"no"<<std::endl;
				goto end;
			}
			if(p){
				if(str[i]=='('||str[i]=='['){
					p=false;
					if(!calc(i)){
						std::cout<<"no"<<std::endl;
						goto end;
					}
				}
			}
		}
		if(l==0&&l2==0)std::cout<<"yes"<<std::endl;
		else std::cout<<"no"<<std::endl;
		end:;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
int main(){
  string str;
  string tmp;
  while(getline(cin, str) && str != "."){
    int p = 0, q = 0;
    bool flag = 1;
    tmp = "";
    
    for(int i = 0 ; i < str.size() ; i++){
      if(str[i] == '[' || str[i] == '(' || str[i] == ']' || str[i] == ')'){
	tmp += str[i];
      }
    }
    
    for(int i = 0 ; i < tmp.size() ; i++){
      if(tmp[i] == '(' && tmp[i+1] == ']') flag = 0;
      if(tmp[i] == '[' && tmp[i+1] == ')') flag = 0;
    }
    
    for(int i = 0 ; i < tmp.size() ; i++){
      if(p < 0 || q < 0){
	flag = 0;
	break;
      }
      if(tmp[i] == '(') p++;
      if(tmp[i] == '[') q++;
      if(tmp[i] == ')') p--;
      if(tmp[i] == ']') q--;
    }
    if(p != 0 || q != 0) flag = 0;
    
    
    stack<char> st;
    
    /*for(int i = 0 ; i < tmp.size() ; i++){
      if(tmp[i] == '(' || tmp[i] == '[') st.push(tmp[i]);
      else if(tmp[i] == ')'){
	if(st.empty() || st.top() != '('){ flag = 0; break;}
	else st.pop();
      }
      else if(tmp[i] == ']'){
	if(st.empty() || st.top() != '['){ flag = 0; break;}
	else st.pop();
      }
      }*/
    
    //cout << tmp << endl;
    //printf("p = %d, q = %d\n", p, q);*/
    if(flag) cout << "yes" << endl;
    else cout << "no" << endl;    
  }
  return 0;
}