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 <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <iomanip>
#include <cassert>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true){
        string s;
        getline(cin, s);
        if(s[0] == '.') break;
        int len = s.size();
        bool ok = true;
        stack<char> left_br;
        for(int i = 0; i < len; i++){
            if(s[i] == '('){
                left_br.push('(');
            }else if(s[i] == ')'){
                if(left_br.empty() || left_br.top() != '('){
                    ok = false;
                    break;
                }
                left_br.pop();
            }else if(s[i] == '['){
                left_br.push('[');
            }else if(s[i] == ']'){
                if(left_br.empty() || left_br.top() != '['){
                    ok = false;
                    break;
                }
                left_br.pop();
            }
        }
        if(ok && left_br.empty()){
            puts("yes");
        }else{
            puts("no");
        }
    }
    return 0;
}

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

int main(){
  
  string str;

  while(1){

    getline(cin, str);
    if(str[0] == '.') break;

    vector<int> v;

    for(int i = 0; i < (int)str.size(); i++){
      if(str[i] == '('){
	v.push_back(0);
      }else if(str[i] == ')'){
	v.push_back(1);
      }else if(str[i] == '['){
	v.push_back(2);
      }else if(str[i] == ']'){
	v.push_back(3);
      }
    }

    int cnt = 0, judge = 0, o[2] = {}, p[2] = {};

    for(int i = 0; i < (int)v.size(); i++){
      if(v[i] == 0){
	for(int j = i+1; j < (int)v.size(); j++){
	  if(v[j] == 1){
	    for(int l = i+1; l < j; l++){
	      if(v[l] == 0) o[0]++;
	      if(v[l] == 1) o[1]++;
	      if(v[l] == 2) p[0]++;
	      if(v[l] == 3) p[1]++;
	      //   cout << o[0] << o[1] << p[0] << p[1] << endl;
	    }
	    
	    if(o[0] == o[1] && p[0] == p[1] && p[0] != 0 && o[0] != 0){
	      v[i] = 7;
	      v[j] = 7; 
	      o[0] = o[1] = p[0] = p[1] = 0;
	    }
	    o[0] = o[1] = p[0] = p[1] = 0;
	  }
	}
      }else if(v[i] == 2){
	for(int j = i+1; j < (int)v.size(); j++){
	  if(v[j] == 3){
	    for(int l = i+1; l < j; l++){
	      if(v[l] == 0) o[0]++;
	      if(v[l] == 1) o[1]++;
	      if(v[l] == 2) p[0]++;
	      if(v[l] == 3) p[1]++;
	      //   cout << o[0] << o[1] << p[0] << p[1] <<  v[0] <<endl;
	    }
	    
	  }
	  if(o[0] == o[1] && p[0] == p[1] && o[0] != 0 && p[0] != 0){
	    v[i] = 7;
	    v[j] = 7;
	  }
	  o[0] = o[1] = p[0] = p[1] = 0;
	}
      }
         for(int k = 0; k < (int)v.size(); k++){
	cout << v[k];
      }
      cout << endl;
      
      }
     
    
    for(int i = 0; i < (int)v.size(); i++){
      if(v[i] == 7){
    	cnt++; 
      }
    }

    if(cnt == (int)v.size()){
      cout << "yes" << endl;
      cnt = 0;
    }else if(cnt != (int)v.size()) cout << "No" << endl;
    // cout << cnt << " " << (int)v.size() << endl;
  }
  
  return 0;
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	
	while(1){
		string str;
		getline(cin , str);
		stack<char> s;
		int cnt=0,cnt2=0;
		
		if(str=="."){
			break;
		}

		for(int i=0;i<str.size();i++){
			if(str[i]=='('||str[i]=='['){
				s.push(str[i]);
				cnt++;
			}

			if(str[i]==')'){
				cnt2++;
				if(s.top()=='('){
					s.pop();
				}else{
					break;
				}
			}

			if(str[i]==']'){
				cnt2++;
				if(s.top()=='['){
					s.pop();
				}else{ 
					break;
				}
			}
		}

		if(cnt==cnt2){
			cout << "yes" << endl;
		}
		else{
			cout << "no" << endl;
		}	
	}
	return 0;
}

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

 int main(){

   string str;

   while(1){

     getline(cin, str);
     if(str[0] == '.') break;

     vector<char> v;

     for(int i = 0; i < (int)str.size(); i++){
       if(str[i] == '[' || str[i] == '('){
	 v.push_back(str[i]);
       }else if(str[i] == ')'){
	 if(v.empty()){
	   v.push_back(str[i]);
	   break;
	 }

	   if(v.back() == '('){
	     v.pop_back();
	   }else break;

       }else if(str[i] == ']'){
	 if(v.empty()){
	   v.push_back(str[i]);
	   break;
	 }

	   if(v.back() == '['){
	     v.pop_back();
	   }else break;
       }
     }
     if(v.empty()) cout << "yes" << endl;
     else cout << "no" << endl;

   }

   return 0;
 }

C++: #include <stdio.h>
#include <string.h>
int kakko(char *c,char tmp,int count){
	int flag = 0;
	char wtmp,retmp;
	*c = getchar();
	count++;
	if(tmp == ')')
		wtmp = ']';
	else
		wtmp = ')';
	while(*c != '.' && *c != tmp && *c != wtmp){
		if(*c == '(' || *c == '['){
			if(*c == '(')
				retmp = ')';
			else
				retmp = ']';
			flag = kakko(c,retmp,count);
			if(*c != '.')
				*c = getchar();
		}
		if(*c != '.' && *c != tmp && *c != wtmp ){
			*c = getchar();
			count++;
		}
	}
	if(*c == '.' || *c == wtmp)
		flag = 1;
	return flag;
}

int main(void){
	int count = 0, flag = 0;
	char c, tmp;
	c = getchar();
	while(c != '.' || count != 0){
		if(c == '(' || c == '['){
			if(c == '(')
				tmp = ')';
			else
				tmp = ']';
			flag = kakko(&c,tmp,count);
			if(c != '.')
				c = getchar();
		}
		if(c == ')' || c == ']')
			flag = 1;
		if(c == '.'){
			if(flag == 0)
				printf("yes\n");
			else
				printf("no\n");
			flag = 0;
			count = 0;
			getchar(); //改行読取ばs
			c = getchar();
		}
		else{
			c = getchar();
			count++;
		}
	}
	return 0;
}