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 <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

  while(true){
    string s;
    getline(cin, s);
    if(s == ".") break;

    int len = s.length();
    int l1 = 0, l2 = 0;
    bool f = true;
    stack<int> st; // (:1 [:2
    REP(i,len){
      if(s[i] == '('){
        l1++;
        st.push(1);
      }else if(s[i] == ')'){
        l1--;
        if(st.empty()){
          f = false;
          break;
        }
        int tmp = st.top(); st.pop();
        if(tmp == 2) f = false;
      }else if(s[i] == '['){
        l2++;
        st.push(2);
      }else if(s[i] == ']'){
        l2--;
        if(st.empty()){
          f = false;
          break;
        }
        int tmp = st.top(); st.pop();
        if(tmp == 1) f = false;
      }
    }
    if(f && l1 == 0 && l2 == 0){
      cout <<"yes\n";
    }else{
      cout <<"no\n";
    }
  }
  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] == '[') {
			i = is_balanced(i)+1;
			if (i == 0) return -1;
		}
		if (str[i] == ')' || str[i] == ']') {
			if(str[i] != kako[str[s]])
				return -1;
			else {
				return i;
			}
		}
	}
	return -1;
}

int main() {
	while (fgets(str,101, stdin)) {
		if (!strcmp(str, ".\n"))
			return 0;
		bool f = true;
		REP(i, strlen(str)) {
			if (str[i] == '(' || str[i] == '[') {
				i = is_balanced(i)+1;
				if (i == 0) {
					printf("no\n");
					f = false;
					break;
				}
			}
		}
		if (f) printf("yes\n");
	}

	return 0;
}

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

int main(){
  string str;
  while(1){
    getline(cin,str);
    if(str[0] == '.')break;
    for(int i = 0; i < str.size(); i++){
      if(str[i] == '('){
	for(int j = i + 1; j< str.size() && j != ']'; j++){
	  if(str[j] ==')'){
	    str[i] = 'a';
	    str[j] = 'b';
	    break;
	  }
	}
      }
      if(str[i] == '['){
	for(int j = i + 1; j < str.size() && j != ')' ; j++){
	  if(str[j] ==']'){
	    str[i] = 'a';
	    str[j] = 'b';
	    break;
	  }
	}
      }
    }
    int n = 0;
    while(n < str.size() && str[n] != '(' && str[n] != ')' && str[n] !='[' && str[n] != ']')n++;
    //  cout << str <<"Size:" << str.size() <<"N: "<< n <<endl;
    if(n == str.size())cout << "yes" << endl;
    else cout <<"no" << endl;
  }
}

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

// Shrotening
#define fst first
#define snd second
#define pb push_back
#define mp std::make_pair

// Loop
#define FOR(i,a,b) for(auto i=(a);i<(b);++i)
#define RFOR(i,a,b) for(auto i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::pair<int,int> PII;

typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;
typedef std::vector<PII> VPII;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

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

        int paren = 0, bracket = 0;
        bool f = true;
        for(auto c: s) {
            switch(c) {
                case '(':
                    ++paren;
                    break;
                case ')':
                    --paren;
                    break;
                case '[':
                    ++bracket;
                    break;
                case ']':
                    --bracket;
                    break;
                default:
                    break;
            }

            if(paren < 0 || bracket < 0) {
                f = false;
                break;
            }
        }
        if(!f || (paren > 0 || bracket > 0)) {
            std::cout << "no" << std::endl;
        } else {
            std::cout << "yes" << std::endl;
        }
    }
}