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_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//

int main() {
  while (1) {
    string input = "";

    getline(cin, input);

    bool endflag = true;
    rep(i, input.size()) {
      if (input[i] != '.') endflag = false;
    }
    if (endflag) break;

    stack<char> st;
    bool flag1 = true, flag2 = true;
    bool c1 = true, c2 = true;
    rep(i, input.size()) {
      if (input[i] == '(') {
        st.push(input[i]);
        flag1 = false;
      }
      if (input[i] == ')') {
        if (st.empty())
          c1 = false;
        else {
          char tmp = st.top();
          st.pop();
          if (tmp == '(') {
            flag1 = true;
          } else
            c1 = false;
        }
      }

      if (input[i] == '[') {
        st.push(input[i]);
        flag2 = false;
      }
      if (input[i] == ']') {
        if (st.empty())
          c2 = false;
        else {
          char tmp = st.top();
          st.pop();
          if (tmp == '[')
            flag2 = true;
          else
            c2 = false;
        }
      }
    }

    if (flag1 && flag2 && c1 && c2 && st.empty())
      cout << "yes\n";
    else
      cout << "no\n";
  }

  return 0;
}

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

int main(){
	string str;
	
	while(1){
		stack <int> sta;
		int si = 0, f = 1;
		getline(cin, str);
		
		if(str == ".") break;
		
		si = str.size();
		
		for(int i = 0; i < si; i++){
			switch(str[i]){
				case '[': sta.push(1); break;
				case ']': if(!sta.empty()){if(sta.top() != 1)f = 0; sta.pop();}else f = 0;break;
				case '(': sta.push(2); break;
				case ')': if(!sta.empty()){if(sta.top() != 2)f = 0; sta.pop();}else f = 0;break;
			}
			if(f == 0) break;
		}
		
		if(f) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
		
	}
	return 0;
}

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

int main(void){
  string str;

  while(getline(cin,str) && str!="."){
    string c;
    for(int i=0;i<str.size();i++)
      if(str[i]==')' ||str[i]=='(' ||str[i]=='[' ||str[i]==']')
	c += str[i];

  stack<char> s;
  bool f=true;
    for(int i=0;i<c.length();i++){
      if(s.empty() || c[i]=='(' || c[i]=='[')
	s.push(c[i]);
      else if((s.top()=='(' && c[i]==')' )||(s.top()=='[' && c[i]==']')){
	s.pop();
      }else{
	f=false;
	break;
      }
      
    }
    cout << (f && s.empty()?"YES":"NO") << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
bool r(int &i,string S);
bool a(int &i,string S);
bool r(int &i,string S){
    while(i<S.size()){
        switch(S[i]){
            case '(':
                i++;
                if(!r(i,S)) return false;
                break;
            case ')':
                i++;
                return true;
            case '[':
                i++;
                if(!a(i,S)) return false;
                break;
            case ']':
                i++;
                return false;
            default:
                i++;
                break;
        }
    }
    return false;
}
 
bool a(int &i,string S){
    while(i<S.size()){
        switch(S[i]){
            case '(':
                i++;
                if(!r(i,S)) return false;
                break;
            case ')':
                i++;
                return false;
            case '[':
                i++;
                if(!a(i,S)) return false;
                break;
            case ']':
                i++;
                return true;
            default:
                i++;
                break;
        }
    }
    return false;
}
 
int main(){
    string str;
    while(true){
        getline(cin,str);
        if(str==".") return 0;
        else str.push_back(']');
        int i=0;
        if(a(i,str)){
            cout<<"yes"<<endl;
        }else{
            cout<<"no"<<endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <stack>
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)

using namespace std;

void solve(string s) {
    bool balance = true;
    stack<char> S;
    for(char& c : s) {
        if(c == '(') S.push('(');
        if(c == '[') S.push('[');
        if(c == ')') {
            if(S.size() == 0) {balance = false; break;}
            if(S.top() == '(') S.pop();
            else balance = false;
        }
        if(c == ']') {
            if(S.size() == 0) {balance = false; break;}
            if(S.top() == '[') S.pop();
            else balance = false;
        }
    }
    if(S.size()) balance = false;
    cout << (balance ? "yes" : "no") << "\n";
}

int main() {
    string s;
    while(getline(cin,s)) {
        if(s[0] == '.') break;
        solve(s);
    }
    return 0;
}

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

bool solve(const string &s){
	stack<char> x;
	for(int i = 0; i < s.size(); ++i){
		if(s[i] == '[' || s[i] == '('){
			x.push(s[i]);
		}
		else if(s[i] == ']'){
			if(x.empty() || x.top() != '[')
				return false;
			x.pop();
		}
		else if(s[i] == ')'){
			if(x.empty() || x.top() != '(')
				return false;
			x.pop();
		}
	}
	return x.empty();
}

int main(){
	string s;
	while(getline(cin, s), s != "."){
		puts(solve(s) ? "yes" : "no");
	}
}