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<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;
}



int main(){

  while(1){
    string s;
    char c;
    c = getchar();
    while(c!='\n'){
      s+=c;
      c = getchar();
    }
    if(s.size()==1&&s[0]=='.') break;
    if(f(s))
      cout<<"yes"<<endl;
    else
      cout<<"no"<<endl;
  }


  return 0;
}

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

int main(){
  stack<int> p;
  string str;
  bool a;
  while(1){
    getline(cin,str);
    a = true;
    if(str == ".") break;
    for(int i=0;i<str.length();i++){
      char ch = str[i];
      if(ch == '(') p.push(1);
      if(ch == '[') p.push(2);
      if(ch == ')'){
        if(p.empty()){
          a = false;
          break;
        }
        if(p.top() == 1){
          p.pop();
        } else{
          a = false;
          break;
        }
      }
      if(ch == ']'){
        if(p.empty()){
          a = false;
          break;
        }
        if(p.top() == 2){
          p.pop();
        }else{
          a = false;
          break;
        }
      }
    }
    cout << (a?"yes":"no");
    while(!p.empty()){
      p.pop();
    }
    cout << endl;
  }
  return 0;
}

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

using namespace std;



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

C++: #include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

string solve(string s) {
    // queue<int> stack;
    stack<int> stack;
    bool flag = true;
    int check;

    for (int i = 0; i < s.length(); i++) {
        if (s[i] == '(')
            stack.push(1);
        else if (s[i] == '[')
            stack.push(2);
        if (s[i] == ')' && !stack.empty()) {
            check = stack.top();
            stack.pop();
            if (check != 1) {
                flag = false;
                break;
            }
        } else if (s[i] == ']' && !stack.empty()) {
            check = stack.top();
            stack.pop();
            if (check != 2) {
                flag = false;
                break;
            }
        }
    }
    if (!stack.empty()) flag = false;
    if (flag) return "yes";
    return "no";
}

int main() {
    string st;
    vector<string> ans;
    while (1) {
        // cout << 1;
        getline(cin, st);
        // cout << 2;
        if (st == ".") break;
        // cout << 3;
        // cout << st << endl;
        ans.push_back(solve(st));
        // cout << 4;
    }
    for (auto k : ans) cout << k << endl;
}

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) {
//	cout << str << endl;
	if (str == "") {
		return true;
	}
	else {
		string::size_type paren1 = str.rfind("()");
		string::size_type paren2 = str.rfind("[]");
		if (paren1 == string::npos && paren2 == string::npos) {
			return false;
		}
		else {
			if (paren1 != string::npos) {
				str.replace((int)paren1, 2, "");
			}
			else if (paren2 != string::npos) {
				str.replace((int)paren2, 2, "");
			}
			return isBalancedParens(str);
		}
	}
}

C++:  #include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long LL;
int N;
int main(){
    string str;
    while(getline(cin,str),str!="."){
       vector<string>s(1000);
       int num=0;
       bool check=true;
       REP(i,str.size()){
           if(str[i]=='('){
              s[num]="(";
              num++;
           }
           if(str[i]=='['){
              s[num]="[";
              num++;
           }
           if(str[i]==')'){
              if(num==0){
                 check=false;
                 break;
              }
              if(s[num-1]!="("){
                 check=false;
                 break;
              }
              num--;
           }
           if(str[i]==']'){
              if(num==0){
                 check=false;
                 break;
              }
              if(s[num-1]!="["){
                 check=false;
                 break;
              }
              num--;
           }
       }
       if(num!=0)check=false;
       if(check==true){
          cout<<"yes"<<endl;
       }else{
          cout<<"no"<<endl;
       }
    }
    return 0;
}