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 <cstdio>
#include <algorithm>
#include <stack>
#include <string>

using namespace std;

int main()
{
	stack<char> s;

	while (true){
		char str[128];
		fgets(str, sizeof(str), stdin);

		if (str[0] == '.'){
			break;
		}

		bool flag = true;
		for (int i = 0; str[i] != '.'; i++){
			if (str[i] == '('){
				s.push('(');
			}
			if (str[i] == '['){
				s.push('[');
			}
			if (str[i] == ')'){
				if (s.empty()){
					flag = false;
					break;
				}
				else if (s.top() == '('){
					s.pop();
				}
				else if (s.top() == '['){
					flag = false;
					break;
				}
			}
			if (str[i] == ']'){
				if (s.empty()){
					flag = false;
					break;
				}
				else if (s.top() == '['){
					s.pop();
				}
				else if (s.top() == '('){
					flag = false;
					break;
				}
			}
		}

		if (flag){
			puts("Yes");
		}
		else {
			puts("No");
		}
	}

	return (0);
}

C++: /*
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1173&lang=jp
*/

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

bool solve(string str, int s, int t){
    // cout << s << " " << t << endl;
    int cntm = 0, cntk = 0;
    int findm = -1, findk = -1;
    int levelm = 0, levelk = 0;
    for(int i=s;i<t;i++){
        if(findm >= 0){
            if(str[i] == '(') levelm++;
            else if(str[i] == ')'){
                levelm--;
                if(levelm == 0){
                    if(!solve(str, findm + 1, i)) return false;
                    findm = -1;
                }
            }else if(str[i] == '['){
                levelk++;
            }else if(str[i] == ']'){
                levelk--;
                if(levelk < 0) return false;
            }
        }else if(findk >= 0){
            if(str[i] == '[') levelk++;
            else if(str[i] == ']'){
                levelk--;
                if(levelk == 0){
                    if(!solve(str, findk + 1, i)) return false;
                    findk = -1;
                }
            }else if(str[i] == '('){
                levelm++;
            }else if(str[i] == ')'){
                levelm--;
                if(levelm < 0) return false;
            }
        }else{
            if(str[i] == '('){
                // find corresponding )
                findm = i;
                levelm++;
            }else if(str[i] == '['){
                // find corresponding ]
                findk = i;
                levelk++;
            }else if(str[i] == ')'){
                return false;
            }else if(str[i] == ']'){
                return false;
            }
        }
    }
    if(levelm != 0 || levelk != 0){
        return false;
    }
    return true;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    vector<string> strs;
    while(1){
        string s; getline(cin, s);
        if(s == ".") break;
        strs.push_back(s);
    }
    for(string str: strs){
        bool ok = solve(str, 0, str.size());
        if(ok) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    while(getline(cin,s),s!="."){
        string c;
        int d=1;
        stack<char> w;
        for(int i=0;i<s.size();i++)if(s[i]==')'||s[i]=='('||s[i]=='['||s[i]==']')c+=s[i];
            for(int i=0;i<c.size();i++){
            if(c[i]=='['||c[i]=='(')w.push(c[i]);
            else if(c[i]==']'&&w.top()=='['||c[i]==')'&&w.top()=='(')w.pop();
            else {dbreak;}
        }
        if(w.empty())cout<<"yes"<<endl;
        else fail:cout<<"no"<<endl;
    }
    return 0;
}

C++: // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1173&lang=jp
#include <iostream>
#include <string>
#include <stdlib.h>
#include <vector>
using namespace std;

string removeExceptParens(string);
bool isBalancedParens(string);

int main() {
	vector<string> lines;
	while (true) {
		string line = "";
		getline(cin, line);
		if (line == ".") {
			break;
		}
		lines.push_back(line);
	}

	for (vector<string>::iterator it = lines.begin(); it != lines.end(); it++) {
		string parenRemovedLine = removeExceptParens(*it);
		if (isBalancedParens(parenRemovedLine)) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
	return 0;
}

string removeExceptParens(string str){
	string result = "";	
	for (string::iterator it = str.begin(); it != str.end(); it++) {
		if (*it == '(' || *it == ')' || *it == '[' || *it == ']') {
			result += *it;
		}
	}
	return result;
}

bool isBalancedParens(string str) {
	if (str == "") {
		return true;
	}
	else {
		string::size_type paren1 = str.find("()");
		string::size_type paren2 = str.find("[]");
		if (paren1 == string::npos && paren2 == string::npos) {
			return false;
		}
		else {
			if (paren1 != string::npos) {
				str.replace((int)paren1, 2, "");
			}
			if (paren2 != string::npos) {
				str.replace((int)paren2, 2, "");
			}
			return isBalancedParens(str);
		}
	}
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

int main() {
  string s;
  while( getline(cin,s), s != "." ) {
    int a=0,b=0;
    bool ok = true;
    rep(i,(int)s.size()) {
      if( s[i] == '(' ) ++a;
      if( s[i] == '[' ) ++b;
      if( s[i] == ')' ) --a;
      if( s[i] == ']' ) --b;
      if( a < 0 || b < 0 ) { ok = false; break; }
    }
    if( a != 0 || b != 0 ) ok = false;
    puts(ok?"yes":"no");
  }
  return 0;
}

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

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

        stack<char> paren;
        bool flag = true;
        for (auto i = 0; i < s.size(); i++) {
            if (s[i] == '(' || s[i] == '[') {
                paren.push(s[i]);
            } else if (s[i] == ')') {
                if (!paren.empty()) {
                    char t = paren.top(); paren.pop();
                    if (t != '(') {
                        flag = false;
                    }
                } else {
                    flag = false;
                }
            } else if (s[i] == ']') {
                if (!paren.empty()) {
                    char t = paren.top(); paren.pop();
                    if (t != '[') {
                        flag = false;
                    }
                } else {
                    flag = false;
                }
            }
        }

        if (flag) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }

    return 0;
}