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

int main(){
  char ch;
  while(1){
    stack<int> S1,S2;
    scanf("%c",&ch);
    if(ch=='.')break;
    int i=0;
    bool flag=0;
    while(1){
      if(i!=0)scanf("%c",&ch);
      if(ch=='.')break;
      
      if(ch=='[') S1.push(i);
      else if(!S2.empty()){
	if(ch==']'&&S1.size()>0&&S1.top()>S2.top()) S1.pop();
      }else if(ch==']'&&S1.size()>0)S1.pop();
      else if(ch==']')flag=1;
      
      if(ch=='(')S2.push(i);
      else if(!S1.empty()){
	if(ch==')'&&S2.size()>0&&S2.top()>S1.top()) S2.pop();
      }else if(ch==')'&&S2.size()>0) S2.pop();
      else if(ch==')')flag=1;
      
      i++;
    }
    if(S1.size()==0&&S2.size()==0&&flag!=1) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    scanf("%c",&ch);
  }
 return 0;
}

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

char c[101];

int main(){
while(1){
	cin.getline(c, sizeof(c));

	int len = 0;
	while(1){
		if(c[len] == '.') break;
		len++;
	}
	if(len == 0) break;
	
	
	
	
	int rl=0, rr=0, gl=0, gr=0;
	bool flag = true;
	for(int i=0; i < len; i++){
		if(c[i] == '(') rl++;
		else if(c[i] == ')') rr++;
		else if(c[i] == '[') gl++;
		else if(c[i] == ']') gr++;
		
		//check!
		if(rl < rr) flag = false;
		if(gl < gr) flag = false;
	}
	//check!
	if(rl != rr) flag = false;
	if(gl != gr) flag = false;
	
	if(flag) cout << "yes" << endl;
	else cout << "no" << endl;
	
}//end	
	return 0;
}

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

int main(){

    while(1){
        stack<char> s;
        bool isBalance = true;
        string input;

        getline(cin, input);

        if(input[0] == '.' && input[1] == '\0') break;

        for(int i=0;i < input.length() ;i++){
            if(input[i] == '.') break;
            switch(input[i]){
                case '[': s.push(input[i]);
                          break;
                case '(': s.push(input[i]);
                          break;
                case ']':
                          if(s.empty()){ isBalance = false; break;}
                          else if(s.top() != '['){isBalance = false; break;}
                          else s.pop();
                          break;
                case ')':
                          if(s.empty()){ isBalance = false; break;}
                          else if(s.top() != '('){isBalance = false; break;}
                          else s.pop();
                          break;
            }
            if(!isBalance) break;
        }
        if(!isBalance || !s.empty()) cout << "no" << endl;
        else cout << "yes" << endl;

    }
    return 0;
}

C++: 
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
#define out(S) cout<<(S)<<endl;
#define REP(i,b) for(size_t i=0;i<(b);i++)
#define rREP(i,b) for(int i=(b)-1;i>=0;i--)
#define FOR(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define Foreach(item,collection) for(auto item:collection)
#define mod(i) ((i) % (ll)(1e9 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9 + 5))))
#define Yes out("Yes")
#define No out("No")
#define NO out("NO")
#define YES out("YES")
#define INF 1e10;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define IfOut(condition,text) if((condition)){out(text);return 0;}
#define IfeOut(condition,itext,etext) if(condition){out(itext);return 0;}else{out(etext);return 0;}
#define Select(collection,condition,result) Foreach(i,collection){result+=condition;}
#define GetAuto(_N,vect) {cin>>_N;vect.resize(_N);REP(i,_N){cin>>vect[i];}}
#define beginend(vec) (vec).begin(),(vec).end()
#define pb(item) push_back(item)
#define removeAll(vec,deleg) auto itr=remove_if(beginend(vec),deleg);vec.erase(itr,vec.end());
void removeAt(string& s, int index) { s.erase(index, 1); }
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
ll manhattanDistance(ll x1, ll y1, ll x2, ll y2) { return (abs(x2 - x1) + abs(y2 - y1)); }
vector<ll> sieveOfEratosthenes(int max) {ll prime;double sqrtmax = sqrt(max);vector<ll> primeVec, searchVec;FOR(i, 2, max + 1) searchVec.push_back(i);do{prime = searchVec[0];primeVec.push_back(prime);auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; });searchVec.erase(itr, searchVec.end());} while (prime < sqrtmax);primeVec.reserve(primeVec.size() + searchVec.size());primeVec.insert(primeVec.end(), beginend(searchVec));return primeVec;}

int solve(string S) {
	int maru = 0, kaku = 0;
	Foreach(i, S) {
		if (i == '(') maru++;
		else if (i == '[') kaku++;
		else if (i == ')') {
			if (maru > 0) maru--;
			else {
				break;
			}
		}
		else if (i == ']') {
			if (kaku > 0)kaku--;
			else {
				break;
			}
		}
	}
	IfeOut(kaku == 0 && maru == 0, "yes", "no");
}

int main() {
	char S[105];
	while (cin.getline(S, sizeof(S)))
	{
		if (strlen(S) == 1 && S[0] == '.') break;
		solve(S);
	}
	return 0;
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>

int testcase_ends() {
  char buf[128];
  fgets(buf, sizeof buf, stdin);
  std::string s=buf;
  if (s[0] == '.') {
    return 1;
  }

  std::stack<char> k;
  for (char ch: s) {
    if (ch == '(') {
      k.push(')');
    } else if (ch == '[') {
      k.push(']');
    } else if (ch == ')' || ch == ']') {
      if (k.empty()) 
        return !printf("no\n");
      if (k.top() == ch) {
        k.pop();
      } else {
        printf("no\n");
        return 0;
      }
    } 
  }
  printf("%s\n", k.empty()? "yes":"no");
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}

C++: #include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>

using namespace std;

int search(int i, char c);

char str[200];
int l;

int main()
{
	while(1){
		fgets(str, sizeof(str), stdin);
		if(str[0] == '.') break;
		int ans = 1;
		l = strlen(str);
		for(int i = 0; i < l; i++){
			if(str[i] == '(' || str[i] == '['){
				ans = search(i, str[i]);
				if(ans == 0) break;
			} else if(str[i] == ')' || str[i] == ']'){
				ans = 0;
				break;
			}
		}
		if(ans == 1) cout << "yes" << endl;
		else if(ans == 0) cout << "no"<< endl;
	}
	return 0;
}

int search(int i, char c)
{
	if(i == l-1) return 0;
	char d, e;
	if(c == '('){
		d = ')';
		e = ']';
		}else if(c == '['){
			d = ']';
			e = ')';
		}
	for(int j = i+1; j < l; j++){
		if(str[j] == '(' || str[j] == '['){
			return search(j, str[j]);
		} else if(str[j] == d){
			str[j] = '0';
			return 1;
		} else if(str[j] == e){
			str[j] = '0';
			return 0;
		}
	}
	return 0;
}