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++: //
//  main.cpp
//  AOJ1173
//
//  Created by aki33524 on 2014/07/09.
//  Copyright (c) 2014年 aki33524. All rights reserved.
//

#include <iostream>
#include <string>
#include <stack>
using namespace std;

string S;
void solve(){
    int a = 0, b = 0;
    char last = '.';
    
    for(int i=0; i<S.size(); i++){
        char c = S[i];
        if(c == '('){
            last = c;
            a++;
        }else if(c == ')'){
            a--;
            if(last == '[' || a < 0){
                cout << "no" << endl;
                return;
            }
            last = c;
        }else if(c == '['){
            last = c;
            b++;
        }else if(c == ']'){
            b--;
            if(last == '(' || b < 0){
                cout << "no" << endl;
                return;
            }
            last = c;
        }
    }
    cout << "yes" << endl;
}

void solve2(){
    stack<char> st;
    for(int i=0; i<S.size(); i++){
        char c = S[i];
        if(c != '(' && c != ')' && c != '[' && c != ']')
            continue;
        
        if((st.top() == '(' && c == ')') || (st.top() == '[' && c == ']')){
            st.pop();
        }else{
            cout << "no" << endl;
            return;
        }
        st.push(c);
    }
    cout << "yes" << endl;
}

int main(int argc, const char * argv[])
{
    while(getline(cin, S), S!="."){
//        cout << S << endl;
        solve2();
    }
    return 0;
}

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

int N;

bool balance(string s, int b, int e)
{
  N = 1;
  for(int i = b; i < e; i++){
    if(s.at(i) == '('){
      for(int j = i + 1; j < e; j++){
	if(s.at(j) == ')'){
	  string sub = s.substr(i + 1, j - i - 1);
	  cout << sub << endl;
	  if(balance(sub, 0, sub.size())){
	    N = 0;
	    continue;
	  }
	}
      }
      if(N)
	return false;
      else
	return true;
    }else if(s.at(i) == '['){
      for(int j = i + 1; j < e; j++){
	if(s.at(j) == ']'){
	  string sub = s.substr(i + 1, j - i - 1);
      	  if(balance(sub, 0, sub.size())){
	    N = 0;
	    continue;
	  }
	}
      }
      if(N)
	return false;
      else
	return true;
    }else if(s.at(i) == ')'){
      for(int j = 0; j < i; j++){
	if(s.at(j) == '('){
	  string sub = s.substr(j + 1, i - j - 1);
	  cout << sub << endl;
	  if(balance(sub, 0, sub.size())){
	    N = 0;
	    continue;
	  }
	}
      }
      if(N)
	return false;
      else
	return true;
    }else if(s.at(i) == ']'){
      for(int j = 0; j < i; j++){
	if(s.at(j) == '['){
	  string sub = s.substr(j + 1, i - j - 1);
	  if(balance(sub, 0, sub.size())){
	    N = 0;
	    continue;
	  }
	}
      }
      if(N)
	return false;
      else
	return true;
    }
  }
  return true;
}
       
int main()
{
  string s;
  while(getline(cin, s)){
    if(balance(s, 0, s.size()))
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <stack>

using namespace std;

void solve()
{
	string s;
	while (getline(cin, s))
	{
		if (s == ".")
		{
			return;
		}
		bool isBalanced = true;
		stack<char> Stack;
		for (int i = 0; i < s.size(); ++i)
		{
			if (s[i] == '(')
			{
				Stack.push('(');
			}
			else if (s[i] == '[')
			{
				Stack.push('[');
			}
			else if (s[i] == ')')
			{
				if (Stack.empty())
				{
					isBalanced = false;
					break;
				}
				char c = Stack.top();
				Stack.pop();
				if (c != '(')
				{
					isBalanced = false;
					break;
				}
			}
			else if (s[i] == ']')
			{
				if (Stack.empty())
				{
					isBalanced = false;
					break;
				}
				char c = Stack.top();
				Stack.pop();
				if (c != '[')
				{
					isBalanced = false;
					break;
				}
			}
		}
		if (isBalanced && Stack.size() == 0)
		{
			cout << "yes" << endl;
		}
		else
		{
			cout << "no" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#include<string>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))
#define ALL(c) (c).begin(), (c).end()
// #define dump(a) cerr << #a << "=" << (a) << endl

using namespace std;

int main() {
	string line;
	char left_paren;
	bool is_yes;
	vector<char> left_parens;

	while(getline(cin,line)) {
		if (line[0] == '.') break;

		left_parens.clear();
		is_yes = true;

		rep(i,line.size()) {
			if (line[i] == '(') {
				left_parens.push_back(line[i]);
			}
			else if (line[i] == '[') {
				left_parens.push_back(line[i]);
			}
			else if (line[i] == ')') {
				if (left_parens.empty()) {
					is_yes = false;
				}
				else {	
					left_paren = left_parens.back();
					if (left_paren != '(') {
						is_yes = false;
					}
					left_parens.pop_back();
				}
			}
			else if (line[i] == ']') {
				if (left_parens.empty()) {
					is_yes = false;
				}
				else {	
					left_paren = left_parens.back();
					if (left_paren != '[') {
						is_yes = false;
					}
					left_parens.pop_back();
				}
			}
		}
		if (left_parens.size() > 0)
			is_yes = false;

		if (is_yes) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	string S;
	while (getline(cin, S)) {
		if (S == ".") break;
		stack<char>sta;
		bool flag = false;
		for (ll i = 0; i < S.size(); i++) {
			if (S[i] == '(') sta.push('(');
			if (S[i] == '[')sta.push('[');
			if (S[i] == ')') {
				if (sta.size() == 0 || sta.top() != '(') {
					flag = true;
					break;
				}
				sta.pop();
			}
			if (S[i] == ']') {
				if (sta.size() == 0 || sta.top() != '[') {
					flag = true;
					break;
				}
				sta.pop();
			}
		}
		if (!flag&&sta.empty())
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
}

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;


bool solve(string str){
	if(str == ".") return true;
	bool ans = true;
	stack<char> s;
	for(int i=0;i<str.size();i++){
		if(str[i] == '(') s.push(')');
		if(str[i] == '[') s.push(']');
		if(str[i] == ')' || str[i] == ']'){
			if(s.empty()){
				ans = false;
				break;
			}
			char c = s.top();
			if(str[i] != c){
				ans = false;
				break;
			}
			s.pop();
		}
	}
	if(ans){
		cout<< "yes"<< endl;
	}else{
		cout<< "no"<< endl;
	}
	
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	string str;
	while(getline(cin, str)){
		solve(str);
	}
	return 0;
}