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++: // #define USE_CPP11
// #define USE_PRINTF

#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <utility>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <complex>
#include <memory>
#include <sstream>

#ifdef USE_CPP11
#include <unordered_map>
#include <unordered_set>
#include <functional>
#endif

#define PRINT(obj) cout << obj << endl
#define REP(i, n) for(int (i) = 0; (i) < (n); i++)
#define SPACE ' '

typedef long long ll;

using namespace std;

namespace Scanner {
#ifdef USE_PRINTF
  int    nextInt()    { int    d; scanf("%d" , &d); return d; }
  float  nextFloat()  { float  f; scanf("%f" , &f); return f; }
  double nextDouble() { double f; scanf("%lf", &f); return f; }  
  string nextString() { string s; scanf("%s" , &s); return s; }
  ll     nextll()     { ll     l; scanf("%ll", &l); return l; }
#else
  int    nextInt()    { int    d; cin >> d; return d; }
  float  nextFloat()  { float  f; cin >> f; return f; }
  double nextDouble() { double f; cin >> f; return f; }  
  string nextString() { string s; cin >> s; return s; }
  ll     nextll()     { ll     l; cin >> l; return l; }
#endif

  string getLine() { 
    string input;
    getline(cin, input);
    return input;
  }
};

namespace myLibrary {
  vector<string> split(const string& str, char delim) {
    vector<string> ret;
    size_t current = 0, found;
    while ((found = str.find_first_of(delim, current)) != string::npos) {
      ret.push_back(string(str, current, found - current));
      current = found + 1;
    }
    ret.push_back(string(str, current, str.size() - current));
    return ret;
  }
  
#ifdef USE_CPP11
  ///
  /// higher-order functional
  /// This is like map in haskell, python, etc.
  /// Sample usage:
  ///   vector<int> a = {1, 2, 3, 4, 5};
  ///   vector<int> b = myLibrary::_Map<int, int>(a, [](int n){
  ///     return n * n;
  ///   });
  /// Result:
  ///   b = 1, 4, 9, 16, 25
  ///
  template<typename T_IN, typename T_OUT, class Functor>
  vector<T_OUT> _Map(vector<T_IN> src, Functor func) {
    vector<T_OUT> ret;
    for (int i = 0; i < src.size(); i++) {
      ret.push_back(func(src[i]));
    }
    return ret;
  }
#endif
};

int main() {
  while (true) {
    string input = Scanner::getLine();
    if (input == ".") {
      break;
    }
    stack<char> s;
    bool flag = true;
    REP(i, input.size()) {
      if (!flag) break;
      switch (input[i]) {
        case '[': {
          s.push('[');
          break;
        }
        case ']': {
          if (s.empty() ||
              s.top() != '[') {
              flag = false;  
          }
          s.pop();
          break;
        }
        case '(': {
          s.push('(');
          break;
        }
        case ')': {
          if (s.empty() ||
              s.top() != '(') {
              flag = false;  
          }
          s.pop();
          break;
        }
      }
    }
    if (flag && s.empty()) {
      PRINT("yes");
    } else {
      PRINT("no");
    }
  }
  
  return 0;
}

C++: #include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
static const int INF = 1e+9+7;
ll n,m,l;
string s,t;
int d[200010],dp[1010][1010];
double w[1000],v[1000];
double box[200010];
char field[200][200];

int main(){
  while(1){
    getline(cin,s);
    if(s == ".")break;
    t = "";
    vc vec;
    rep(i,0,s.sz){
      if(s[i] == '(' || s[i] == ')' || s[i] == '[' || s[i] == ']')vec.pb(s[i]);
    }
    string ans = "yes";
    if(vec.sz % 2)ans = "no";
    else{
      while(1){
        bool f = true;
        if(vec.empty())break;
        rep(i,0,vec.sz-1){
          if((vec[i] == '(' && vec[i+1] == ')') || (vec[i] == '[' && vec[i+1] == ']')){
            f = false;
            vec.erase(vec.begin() + (i));
            vec.erase(vec.begin() + (i));
            break;
          }
        }
        if(f){
          ans = "no";
          break;
        }
      }
    }
    print(ans);
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cctype>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)

int search(vector<char> &v, char c){
    for(int j = v.size() - 1; j >= 0; j--){
        if(v[j] == c) return j;
    }
    return -1;
}

int main(){
    string str;
    while(getline(cin, str)){
        if(str == ".") break;
        bool OKflg = true;
        vector<char> v;
        REP(i, str.length()){
            if(str[i] == '(') v.push_back('(');
            else if(str[i] == '[') v.push_back('[');
            else if(str[i] == ')'){
                int tmp = search(v, '(');
                if(tmp == -1){
                    OKflg = false;
                    break;
                } else REP(j, v.size() - tmp) v.pop_back();
            }
            else if(str[i] == ']'){
                int tmp = search(v, '[');
                if(tmp == -1){
                    OKflg = false;
                    break;
                } else REP(j, v.size() - tmp) v.pop_back();
            }
        }
        if(OKflg && v.size() == 0) cout <<"yes" <<endl;
        else cout <<"no" <<endl;
    }
    return 0;
}