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>
using namespace std;

int N;

bool balance(string s, int b, int e)
{
  N = 1;
  int x, y, z, p;
  x = y = z = p = 0;
  for(int i = 0; i < e; i++)
    if(s.at(i) == '(')
      x++;
    else if(s.at(i) == ')')
      y++;
    else if(s.at(i) == '[')
      z++;
    else if(s.at(i) == ']')
      p++;
  if(x != y || z != p)
    return false;
  for(int i = b; i < e; i++){
    if(s.at(i) == '('){
      for(int j = i + 1; j < e; j++){
	if(s.at(j) == ')'){
	  string sub = s.substr(i + 1, j - i - 1);
	  cout << sub << endl;
	  if(balance(sub, 0, sub.size())){
	    N = 0;
	    continue;
	  }
	}
      }
      if(N)
	return false;
      else
	return true;
    }else if(s.at(i) == '['){
      for(int j = i + 1; j < e; j++){
	if(s.at(j) == ']'){
	  string sub = s.substr(i + 1, j - i - 1);
      	  if(balance(sub, 0, sub.size())){
	    N = 0;
	    continue;
	  }
	}
      }
      if(N)
	return false;
      else
	return true;
    }else if(s.at(i) == ')'){
      for(int j = 0; j < i; j++){
	if(s.at(j) == '('){
	  string sub = s.substr(j + 1, i - j - 1);
	  cout << sub << endl;
	  if(balance(sub, 0, sub.size())){
	    N = 0;
	    continue;
	  }
	}
      }
      if(N)
	return false;
      else
	return true;
    }else if(s.at(i) == ']'){
      for(int j = 0; j < i; j++){
	if(s.at(j) == '['){
	  string sub = s.substr(j + 1, i - j - 1);
	  if(balance(sub, 0, sub.size())){
	    N = 0;
	    continue;
	  }
	}
      }
      if(N)
	return false;
      else
	return true;
    }
  }
  return true;
}
       
int main()
{
  string s;
  while(getline(cin, s)){
    if(balance(s, 0, s.size()))
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  }
}

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






int main(){

stack<char> point;



while(true){
string n;
getline(cin,n); 
bool flag=0;
if(n=="."){break;}
for(int i=0;i<n.size();i++){
    if(n[i]=='(' or n[i]==')' or n[i]=='[' or n[i]==']'){
        if(point.empty() ){
            point.push(n[i]);
        }


        else if(!point.empty() and point.top()=='(' and n[i]==')'){
             point.pop(); // 末尾要素を削除
        }
        else if(!point.empty() and point.top()=='[' and n[i]==']'){
             point.pop(); // 末尾要素を削除
        }
        else point.push(n[i]);
    }
}

 /* while (!point.empty()) {
    cout << point.top() << " "; // 末尾要素を参照する
    point.pop(); // 末尾要素を削除
  }*/


if(!point.empty()){
    while (!point.empty()) {
    
    point.pop(); 
  }
    cout<<"no"<<endl;
}
else cout<<"yes"<<endl;






}
    return 0;
}

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

using namespace std;

int main(){
	for(char s[101];fgets(s,128,stdin),s[0]!='.'||(s[1]!='\n'&&s[1]!='\0');){
		bool ok=true;
		stack<char> St;
		for(int i=0;s[i];i++){
			if(s[i]=='(') St.push(s[i]);
			if(s[i]=='[') St.push(s[i]);
			if(s[i]==')') if(St.empty() || St.top()=='['){ ok=false; break; } else St.pop();
			if(s[i]==']') if(St.empty() || St.top()=='('){ ok=false; break; } else St.pop();
		}
		puts(ok?"yes":"no");
	}

	return 0;
}

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

using namespace std;
#define rep(i,n) for(int i =0;i<n;++i)

const int ma=3e6;
int ispr[ma];

int su[ma];


string in;

void solve(){
  stack<char> st;
  for(auto c:in){
    auto p = string("()[]").find(c);
    if( p == string::npos) continue;
    //cout << p << endl;
    if(p%2==0){
      st.push(c);
      continue;
    }
    
    if(st.empty()){
      cout << "no" << endl;
      return;
    }
    
    char c2 = st.top();
    st.pop();
    
    if(string("()[]").find(c2)+1==p) continue;
    
    cout << "no" << endl;
    return;
  }
  
  if(!st.empty())
    cout << "no" << endl;
  else
    cout << "yes"<< endl;
}

int main(){
  while(getline(cin,in) , in != ".") solve();
  
}

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

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

      stack<char> stk;
      bool ok = true;
      int n = s.size();
      for (int i = 0; i < n; i++) {
         if (s[i] == '(') stk.push(s[i]);
         if (s[i] == '[') stk.push(s[i]);
         if (s[i] == ')') {
            if (stk.empty() || stk.top() != '(') {
               ok = false;
               break;
            } else {
               stk.pop();
            }
         }
         if (s[i] == ']') {
            if (stk.empty() || stk.top() != '[') {
               ok = false;
               break;
            } else {
               stk.pop();
            }
         }
      }
      if (ok && stk.empty()) {
         puts("yes");
      } else {
         puts("no");
      }
   }
}

C++: #include<iostream>
#include<stack>
main(){for(char i,f,c,s[101];fgets(s,101,stdin),s[0]-46;){std::stack<int> t;for(f=i=0;c=s[i++],c-10;){if(c==40|c==91)t.push(c);if(c==41|c==93){if(t.size()&&(c==t.top()+1||c==t.top()+2))t.pop();else f=1;}}puts(f&t.size()?"no":"yes");}}

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

using namespace std;

int main()
{
  int no,size;
  string v;
  stack<char> sta;
  string end(".");
  char a5;

  while(1){
    no = 0;
    getline(cin,v);

    if(v == end){
      break;
    }

    for(char e : v){
      if(e == '[' || e == '('){
        sta.push(e);
      }
      else if(e == ']'){
        a5 = sta.top();
        sta.pop();

        if(a5 != '['){
          no = 1;
        }
      }
      else if(e == ')'){
        a5 = sta.top();
        sta.pop();

        if(a5 != '('){
          no = 1;
        }
      }
     if(no == 1){
        break;
      }
    }

    size = sta.size();

    if(size != 0){
      no = 1;
    }

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

  return 0;
}

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

#define int long long

signed main()
{
    string s;
    cin.get();
    while(getline(cin, s), s!=".") {
        stack<int> st;
        int f = 0;
        for(int i=0; i<s.size(); ++i) {
            char c = s[i];
            if(c=='(') st.push(0);
            else if(c=='[') st.push(1);
            else if(c==')') {
                if(st.empty()) {
                    cout << "no" << endl;
                    f++;
                    break;
                }
                if(st.top() == 0) st.pop();
                else {
                    cout << "no" << endl;
                    f++;
                    break;
                }
            }
            else if(c==']') {
                if(st.empty()) {
                    cout << "no" << endl;
                    f++;
                    break;
                }
                if(st.top() == 1) st.pop();
                else {
                    cout << "no" << endl;
                    f++;
                    break;
                }
            }
        }
        if(f==0) {
            if(st.empty()) cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }
    return 0;
}