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++: //The Balance of the World
#include<bits/stdc++.h>
using namespace std;

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

C++: #include <bits/stdc++.h>
#include <cstdint>
#include <sys/time.h>

typedef std::int_fast32_t  s32;
typedef std::uint_fast32_t u32;
typedef std::int_fast64_t  s64;
typedef std::uint_fast64_t u64;

typedef std::pair<int, int> P;

char str[128];
int i;

bool L1(void) {
  while( not ( str[i] == '(' or str[i] == ')' or str[i] == '[' or str[i] == ']' or str[i] == '\0' ) ) i += 1;
  return true;
}

bool L0(void) {
  if( str[i] == '\0' ) return true;

  L1();

  if( str[i] == ')' or str[i] == ']' ) return false;
  if( str[i] == '\0' ) return true;
  
  if( str[i] == '(' ) {
    i += 1;
    L0();
    if( str[i] != ')' ) return false;
    i += 1;
  }
  else if( str[i] == '[' ) {
    i += 1;
    L0();
    if( str[i] != ']' ) return false;
    i += 1;
  }  
  return L0();
}

int main(void) {
  
  for(;;) {
    std::string s;
    std::getline(std::cin, s);
    if( s == "." ) break;

    strcpy(str, s.c_str());
    i = 0;

    std::cout << (L0() ? "yes" : "no") << std::endl;
  }
  
  return 0;
}

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

bool solve(){
  stack<char> st;
  for(int i=0;i<(int)str.size();i++){
    if(str[i]=='(')st.push(str[i]);
    else if(str[i]=='[')st.push(str[i]);
    else if(str[i]==')'){
      if(st.empty())return false;
      if(st.top()!='(')return false;
      st.pop();
    }else if(str[i]==']'){
      if(st.empty())return false;
      if(st.top()!='[')return false;
      st.pop();
    }
  }
  return st.empty();
}

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

C++: #include <iostream>
#include <stdio.h>
#include <stack>
using namespace std;
void empty(){
  while(getchar()!='.');
   
}
int main(){
  char i;
  char* tmp;
  int flag;
  stack<char> s;
  i=getchar();
  s.push(0);
  if(i=='.') return 0;
  do{

    if(i=='\n') continue;
    if(i!='.') flag=0;
    
    if(i=='['|| i=='(' ){

      s.push(i);

    }

    if(i==']'){

      if(s.top()=='[') {
	
	s.pop();
	continue;
      }
      else {
	cout <<"no\n";
	empty();
	s.empty();
	s.push(0);
      }
    }
    if(i==')')
      if(s.top()=='('){
	s.pop();
	continue;
      }
      else {
	cout <<"no\n";
	empty();
	s.empty();
	s.push(0);  
    }

    if(i=='.'){
      if(flag) return 0;
      if(s.top()){

	cout <<"no\n";
	s.empty();
	s.push(0);  

      }
      else {
	cout <<"yes\n";
	flag=1;	
      }
    }

  } while(i=getchar());
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>

using namespace std;

#define REP(i, x) for(int i=0;i<(int)(x);i++)
#define REPS(i, x) for(int i=1;i<=(int)(x);i++)
#define RREP(i, x) for(int i=(int)(x)-1;i>=0;i--)
#define RREPS(i, x) for(int i=(int)(x);i>0;i--)
#define FOR(it, x) for(auto it=x.begin();it!=x.end();++it)
#define pb push_back
typedef long long ll;
typedef vector<int> vi;

int n, p[300000];

int solve(string s){
        vector<char> st(1, '#');
        FOR(q, s){
                char c = *q;
                if(c == '(' || c == '[') st.pb(c);
                if(c == ')'){
                        if(st.back() != '(') return 0;
                        st.pop_back();
                }
                if(c == ']'){
                        if(st.back() != '[') return 0;
                        st.pop_back();
                }
        }       
        return st.size() == 1;
}

int main(){
        string s;
        while(getline(cin, s), s != "."){
                cout << (solve(s) ? "yes" : "no") << endl;
        }
        return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265


bool f(string s){
  vector<char> q;

  rep(i,s.size()){
    if(s[i]=='('||s[i]=='[') q.push_back(s[i]);
    if(s[i]==')'){
      if(q.size()==0) return false;
      if(q[q.size()-1]=='[') return false;
      q.pop_back();
    }
    if(s[i]==']'){
      if(q.size()==0) return false;
      if(q[q.size()-1]=='(') return false;
      q.pop_back();
    }
  }

  if(q.size()) return false;

  return true;
}

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

using namespace std;

bool is_balanced(string str) {
    stack<char> nest;
    for (int i=0; i<(int)str.length(); i++) {
        switch (str[i]) {
            case '(':
                nest.push('(');
                break;
            case '[':
                nest.push('[');
                break;
            case ')':
                if (!nest.empty() && nest.top() == '(') {
                    nest.pop();
                }
                else {
                    return false;
                }
                break;
            case ']':
                if (!nest.empty() && nest.top() == '[') {
                    nest.pop();
                }
                else {
                    return false;
                }
                break;
        }
    }
    return true;
}

int main() {
    string s;
    while (true) {
        getline(cin, s);
        if (s == ".") {
            return 0;
        }
        if (is_balanced(s)) {
            cout << "yes" << endl;
        }
        else {
            cout << "no" << endl;
        }
    }
}

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

int main () {
    string str;
    map<char,char> c;
    c[']'] = '[';
    c[')'] = '(';
    while (getline(cin,str), str != ".") {
        stack<char> s;
        bool flag = true;
        for (int i = 0; flag && i < str.size(); i++) {
            if (string("[(").find(str[i]) != string::npos) {
                s.push(str[i]);
            }
            else if (string("])").find(str[i] != string::npos)) {
                if (s.size() == 0) flag = false;
                else if (c.find(str[i]) != c.end() && c[str[i]] == s.top()) s.pop();
                else if (c.find(str[i]) != c.end() && c[str[i]] == s.top()) s.pop();
                else flag = false;
            }
        }

        cout << (flag && !s.size() ? "YES" : "NO") << endl;
    }
}