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<stack>
#include<string>
using namespace std;

int main(void){

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

    stack<char>st;
    for(int i=0;i<s.size();i++){
      if(s[i]=='(' || s[i]=='[')st.push(s[i]);
      else if((s[i]==')' && st.top()=='[') || (s[i]==']' && st.top()=='(')){
	cout << "no" << endl;
	goto end;
      }
      else if(s[i]==')' || s[i]==']')st.pop();
    }
    cout << "yes" << endl;
  end:;
  }
  
  return 0;
}

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

using namespace std;

int main(void){
  string s;

  while(getline(cin,s) && s!="."){

    string ch;
    for(int i=0;i<s.size();i++)
      if(s[i]=='[' || s[i]=='(' || s[i]==']' || s[i]==')')ch+=s[i];

    stack<char> str;
    bool flag = true;
    for(int i=0;i<ch.length();i++){
      
      if(str.empty() || ch[i]=='(' || ch[i]=='[')str.push(ch[i]);
      else if((ch[i]==')' && str.top()=='(')||(ch[i]==']' && str.top()=='[')){str.pop();}
      else {
	flag = false;
	break;
      }
    }

    cout << (flag && str.empty()?"YES":"NO") << endl;

  }

  return 0;
}

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

char bl[5]= "([)]";

int main(){
    char str[101];
    while(1){
        cin.getline(str, sizeof(char)*100);
        if(str[1]==0)break;

        stack<char> seq;
        for(unsigned int i=0; i<strlen(str); i++){
            for(int j=0; j<2; j++){
                if(str[i]==bl[j]){
                    seq.push(str[i]);
                }
            }
            for(int j=2; j<4; j++){
                if(str[i]==bl[j]){
                    if(seq.empty() || seq.top()!=bl[j-2]){
                        seq.push(0);
                        break;
                    }else{
                        seq.pop();
                    }
                }
            }
        }
        if(seq.empty()){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }

    return 0;
}

C++: #include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void solve(string s) {
    int st = 0, ed = s.size() - 2;
    int k1 = 0, k2 = 0;
    FORE(el, s) {
        if (el == '(') k1++;
        if (el == ')') k1--;
        if (el == '[') k2++;
        if (el == ']') k2--;
    }
    if (k1 || k2) {
        cout << "no" << endl;
        return ;
    }
    while (true) {
        if (st >= ed) {
            cout << "yes" << endl;
            return;
        }
        if (s[st] == '(') {
            while (true) {
                if (s[ed] == ')') break;
                ed--;
                if (st >= ed) {
                    cout << "no" << endl;
                    return;
                }
            }
        } else if (s[st] == '[') {
            while (true) {
                if (s[ed] == ']') break;
                ed--;
                if (st >= ed) {
                    cout << "no" << endl;
                    return;
                }
            }
        }
        st++;
    }
    return;
}

signed main(void) {
    int n, p, m, w, h;
    string s;
    int a, b, c, d;
    while (getline(cin, s)) {
        if (s == ".") return 0;
        solve(s);
        //return 0;
    }
}

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

bool solve() {
    vector<char> stack;
    int stack_maru = 0;
    int stack_kaku = 0;
    bool ans = false;
    bool err = false;
    string str;
    getline(cin, str);
    if(str == ".") return false;
    else {
        for(auto c : str) {
            if(c=='(') stack.push_back('(');
            if(c=='[') stack.push_back('[');
            if(c==')') {
                if(stack.size()>0 && stack.back() == '(') {
                    stack.pop_back();
                } else {
                    err = true;
                    break;
                }
            }
            if(c==']') {
                if(stack.size()>0 && stack.back() == '[') {
                    stack.pop_back();
                } else {
                    err = true;
                    break;
                }
            }
        }
        if(stack.size()==0 && !err) cout << "yes" << endl;
        else cout << "no" << endl;
        return true;
    }
}

int main() {
    while(solve()) {}
}

C++: #include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <stack>

#define REP(i,n) for(int i=0; i<n; i++)
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
 
#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9

using namespace std;
typedef long long ll;

int main(){
	while(1){
		string str;
		bool ok=true;
		getline(cin, str);
		//debug(str);
		if (str.length()==1 && str[0]=='.') break;
		stack<int> po;
		for (int i=0; i<str.length(); i++){
			if (str[i]=='(') po.push(0);
			else if (str[i]=='[') po.push(1);
			else if (str[i]==')'){
				if (po.size()>0 && po.top()==0){
					po.pop();
				}else{
					printf("no\n");
					ok = false;
					break;
				}
			}else if (str[i]==']'){
				if (po.size()>0 && po.top()==1){
					po.pop();
				}else{
					printf("no\n");
					ok = false;
					break;
				}
			}
		}
		
		if (ok) printf("yes\n");
		
	}
	return 0;
}