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 <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
const int INF = 1<<28;

string input;

int find(int a, int p) {
	int btn[2] = {};
	FOR(i, p, input.size()) {
		if(a) {
			if(input[i] == '[')
				btn[0]++;
			if(input[i] == ']')
				btn[0]--;
			if(input[i] == '(')
				btn[1]++;
			if(input[i] == ')') {
				btn[1]--;
				if(!btn[0] && !btn[1])
					return 0;
			}
		}
		else {
			if(input[i] == '(')
				btn[0]++;
			if(input[i] == ')')
				btn[0]--;
			if(input[i] == '[')
				btn[1]++;
			if(input[i] == ']') {
				btn[1]--;
				if(!btn[0] && !btn[1])
					return 0;
			}
		}
	}
	return 1;
}


int main() {
	while(getline(cin, input)) {
		if(input == ".") break;
		int cnt = 0;
		int chk[2] = {};
		REP(i, input.size()) {
			if(input[i] == '(') {
				cnt += find(1, i);
				chk[1]++;
			}
			if(input[i] == '[') {
				cnt += find(0, i);
				chk[0]++;
			}
			if(input[i] == ')') {
				chk[1]--;
				if(chk[1] < 0) cnt++;
			}
			if(input[i] == ']') {
				chk[0]--;
				if(chk[0] < 0) cnt++;
			}
		}
		if(chk[0] != 0 || chk[1] != 0) cnt++;
		cout << (cnt ? "no" : "yes") << endl;
	}
	return 0;
}

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

using namespace std;

bool balanced(string s)
{
    deque<char> deq;
    for(string::iterator itr = s.begin(); itr!=s.end(); itr++)
    {
        switch(*itr)
        {
            case '(':
                deq.push_back(')');
                break;
            case '[':
                deq.push_back(']');
                break;
            case ')':
            case ']':
                if(deq.empty() || deq.back() != *itr) return false;
                deq.pop_back();
                break;
        }
    }
    return deq.empty();
}

int main()
{
    string s;
    while(getline(cin, s), s!=".")
    {
        cout << (balanced(s) ? "yes" : "no") << endl;
    }
}

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

#define loop(lp) for(int i = 0;i < lp;i++)

using namespace std;       
int main(){
  string s;
  stack<int> a;
  int i=0,j;
  while(getline(cin,s)){
    while(s[i] != '.'){
      
      if(s[i] == '('){
	a.push('(');  
      }else if(s[i] == ')'){
	if(a.size() == 0){
	  j = 1;
	  break;
	}
	if(a.top() == '('){
	  a.pop();  
	}else{
	  j = 1;
	  break;
	}
      }else if(s[i] == '[' ){
	a.push('[');  
      }else if(s[i] == ']'){
	if(a.size() == 0){
	  j = 1;
	  break;
	}
	if(a.top() == '['){
	  a.pop();  
	}else{
	  j = 1;
	  break;
	}
      }
      i++;
    }
    if(i == 0){
      break;
    }
    if(a.size() == 0 && j != 1){
	cout << "yes" <<endl;
      }else{
	cout<<"no"<<endl;   
      }
    i = 0;
    while(a.size() != 0){
      a.pop();
    }
    j = 0;
  }
    
    
    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 (S[0]=='.'&&S[1]=='\0') break;
		solve(S);
	}
	return 0;
}