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
//  The Balance of the World
//
//  Created by x15071xx on 2017/06/16.
//  Copyright ?? 2017??´ AIT. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <string>
using namespace std;
int main(int argc, const char * argv[]) {
    
    
    while(1){
        string yn = "yes";
        string str;
        vector<char> st;
        getline(cin, str);
        
        
        if (str == ".") {
            break;
        }
        
        for (int i = 0;  i < str.size(); i++) {
            
            if (str[i] == '(' || str[i] == '[') {
                st.push_back(str[i]);
            }
            
            
            if (str[i] == ')') {
                
                if (!st.empty()) {
                    yn = "no";
                    break;
                }
                if ('(' != st.back()) {
                    yn = "no";
                    break;
                }
                
                st.pop_back();
                
            }
            
            if (str[i] == ']') {
                
                if (!st.empty()) {
                    yn = "no";
                    break;
                }
                
                if ('[' != st.back()) {
                    yn = "no";
                    break;
                }
                
                st.pop_back();
                
            }
    
        

        }
        
        if (!st.empty()) {
            yn = "no";
        }
        
        cout << yn << endl;
    }
    return 0;
}

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

using namespace std;

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

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

int main(){
    string str;
    while(getline(cin, str), str != "."){
        stack<char> kakko;
        int i;
        for(i=0; i<str.size(); ++i){
            if(str[i] == '(' || str[i] == '[') kakko.push(str[i]);
            if(str[i] == ')' || str[i] == ']'){
                if(kakko.size() == 0) break;
                else{
                    if((kakko.top()=='(')?str[i]==')':str[i]==']') kakko.pop();
                    else break;
                }
            }
        }
        cout << ((i==str.size()&&kakko.size()==0)?"yes":"no") << endl;
    }
    return 0;
}

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


int main(){

  while(1){
    string s;
    getline(cin,s);
    //    cout << s << endl;
    if(s == ".") break;
    stack<string> st;
    bool ok = true;
    for(int i=0; i<s.size(); i++){
      string si = s.substr(i,1);
    
      if(si == "(" or si == "["){
	st.push( s.substr(i,1) );
	continue;
      }
      else if(si == ")"){
	if(st.size() > 0 and st.top() == "("){
	  st.pop();
	  continue;
	}
	else{
	  ok = false;
	}
      }
      else if(si == "]"){
	if(st.size() > 0 and st.top() == "["){
	  st.pop();
	  continue;
	}
	else{
	  ok = false;
	}
      }
    }
    if(ok and st.empty())
      cout << "yes" << endl;
    else
      cout << "no" << endl;
    
  }
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int kako[110];
string str;

void g(){
	int c;
	str="";
	while(c=getchar(),c<' ');
	while(c>=' '){
		str+=(char)c;
		c=getchar();
	}
}

int main() {
	while(g(),str[0]!='.'){
//cout<<str<<endl;
		int i;
		int k=0;
		string res="yes";
		for(i=0;i<str.size();i++){
			if(str[i]=='[')kako[k++]=1;
			else if(str[i]=='(')kako[k++]=2;
			else if(str[i]==']'){
				if(k==0||kako[k-1]!=1){
					res="no";
					break;
				}
				k--;
			}else if(str[i]==')'){
				if(k==0||kako[k-1]!=2){
					res="no";
					break;
				}
				k--;
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
#define fi first
#define se second
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+7;

int main() {
    char a;
    bool end = false;
    stack<char> st;
    while (true) {
        a = getchar();
        
        if (a == '.') {
            if (end) {
                //dump("Yes");
                return 0;
            }
            else {
                dump(st.empty() ? "yes" : "no");
                end = true;
                while (!st.empty()) st.pop();
            }
        }
        else {
            if (a != '\n') end = false;
            if (a == '(') {
                st.push('(');
            }
            else if (a == '[') {
                st.push('[');
            }
            else if (a == ')') {
                if (!st.empty() && st.top() == '(') {
                    st.pop();
                    
                }
                else {
                    st.push(a);
                 //   dump("PO");
                }
            }
            else if (a == ']') {
                if (!st.empty() && st.top() == '[') {
                    st.pop();
                }
                else {
                    st.push(a);
                }
            }
        }
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;


int main() {
	cout << fixed << setprecision(18);
	string str;
	getline(cin,str);
	
	while(str!="."){
		stack<char>ch;
		for(int i=0;i<str.length();i++){
			if(str[i]=='('){ch.push('(');}
			if(str[i]=='['){ch.push('[');}
			if(str[i]==')'){
				if(ch.empty()){cout<<"no"<<endl;goto next;}
				if(ch.top()=='('){ch.pop();}
				else{cout<<"no"<<endl;goto next;}
			}
			if(str[i]==']'){
				if(ch.empty()){cout<<"no"<<endl;goto next;}
				if(ch.top()=='['){ch.pop();}
				else{cout<<"no"<<endl;goto next;}
			}
		}
		if(ch.empty()){cout<<"yes"<<endl;}
		else{cout<<"no"<<endl;}
		next:
		getline(cin,str);
	}
}