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 <bits/stdc++.h>
using namespace std;

int main(){
	stack<int>st;
	string s;
	while(1){
		getline(cin,s);
		if(s==".") return 0;
		for(int i=0;i<s.size();i++){
			if(s[i]=='(') st.push(0);
			if(s[i]=='[') st.push(1);
			if(s[i]==')'){
				if(st.empty()) break;
				int num=st.top();
				if(num==0){
					st.pop();
				}
			}
			if(s[i]==']'){
				if(st.empty()) break;
				int num=st.top();
				if(num==1){
					st.pop();
				}
			}
		}
		if(st.empty()) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}

C++: #include <algorithm>
#include <stack>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <utility>
#include <vector>

using namespace std;

typedef long long Long;
#define whole(xs) xs.begin(), xs.end()

string L;
bool input() {
    getline(cin, L);
    return L != ".";
}

bool Check() {
    stack<char> s;
    for (string::iterator i = L.begin(); i != L.end(); i++) {
        switch (*i) {
            case '(': 
                s.push(*i); 
                break;
            case ')': 
                if (s.empty() || s.top() != '(') return false;
                s.pop();
                break;
            case '[': 
                s.push(*i); 
                break;
            case ']':
                if (s.empty() || s.top() != '[') return false;
                s.pop();
                break;
        }
    }
    return s.empty();
}

void solve() {
    cout << (Check() ? "yes" : "no") << endl;
}

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

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;


int main(){
	
	string s;
	while(getline(cin,s),s!="."){
		bool f=true;
		stringstream ss;
		rep(i,s.size()){
			if(s[i]=='('||s[i]==')'||s[i]=='['||s[i]==']'){
				ss<<s[i];
			}
		}
		string s2;
		ss>>s2;
		//cout<<s2<<endl;
		string tmp=s2;
		while(1){
			//cout<<"s2 "<<s2<<endl;
			stringstream ss2;
			bool ff=false;
			rep(i,s2.size()){
				if(i==s2.size()-1){
					ss2<<s2[i];
					ff=true;
				}
				else if(s2[i]=='('&&s2[i+1]==')'){
					i++;
				}
				else if(s2[i]=='['&&s2[i+1]==']'){
					i++;
				}
				else{
					ss2<<s2[i];
					ff=true;
				}
			}
			if(ff) ss2>>tmp;
			else break;
			//cout<<"tmp "<<tmp<<endl;
			if(tmp==s2){
				f=false;
				break;
			}
			if(tmp.size()==0) break;
			s2=tmp;
		}
		if(f) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
				
	}
	return 0;
}

C++: 
#include<iostream>
#include<stack>
main(){
for(char i,f,c,s[101];gets(s),s[0]-'.';){
 std::stack<char> t;
 for(f=i=0;c=s[i++],c!='\0';){
  if(c==40|c==91)t.push(c);
  if(c==41|c==93){
   if(t.size()&&c-t.top()<3)t.pop();
   else f=1;
  }
 }
 puts(f&t.size()?"no":"yes");
}}

C++: #include<iostream>
#include<string>
#include<string.h>

using namespace std;


int main()
{
	string str,str2;
	
	cin >> str;


	if(str[str.length()-1] != '.')
	while(true)
	{
		string tmp;
		cin >> tmp;
		str += tmp;
		if(tmp[tmp.length()-1] == '.')break;
	}
	
	while(1)
	{
		bool flag = cin >> str2;

		if(str2[str2.length()-1] != '.' && flag)
		while(true)
		{
			string tmp;
			cin >> tmp;
			str2 += tmp;
			if(tmp[tmp.length()-1] == '.')break;
		}


		int f = 0;//( 1 [ 2
		bool judg = false;

		int tmp[2] = {0,0};
		int i = 0;
		for(i = 0;i < str.length();i++)
		{
			char c = str[i];

			if(f == 0){
				if(c == ')' && !tmp[0])break;
				if(c == ']' && !tmp[1])break;}

			if(f == 1)
			{	
				if(c == ']')break;
				if(c == ')')f = 0;
			}
			if(f == 2)
			{
				if(c == ')')break;
				if(c == ']')f = 0;
			}


			if(c == '('){
				f = 1;tmp[0]++;}
			if(c == '['){
				f = 2;tmp[1]++;}

			if(c == ')'){
				tmp[0]--;}
			if(c == ']'){
				tmp[1]--;}
		}
		if(i == str.length())judg = true;

		if(judg)cout << "yes" << endl;
		else	cout << "no" << endl;

		str = str2;

		if(!flag)break;

	}

	return 0;
}

C++: 
#include<iostream>
#include<stack>
using namespace std;
main(){
int i,f;
for(string s;getline(cin,s),s[0]!='.';){
 stack<char> t;
 for(f=i=0;c=s[i++],c!='.';){
  if(c==40|c==91)t.push(c);
  if(c==41|c==93){
   if(!t.empty()&&c-t.top()<3)t.pop();
   else f=1;
  }
 }
 puts(!f&t.empty()?"yes":"no");
}}

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 flag=false;
    for(int i=0;i<c.length();i++){
      if(s.empty()&&(c[i]==')'||c[i]==']')){flag=true;break;}
      if(c[i]=='(' || c[i]=='[')s.push(c[i]);
      else if((s.top()=='(' && c[i]==')' )||(s.top()=='[' && c[i]==']'))s.pop();
    }
    cout << (!flag && s.empty()?"yes":"no") << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int a[123456*2+10];

signed main()
{
	//IOS();
	vector<int>ans;
	while(1){
		string s;
		getline(cin,s);
		if(s==".")break;
		stack<int>a,b;
		int flg = 1;
		rep(i,0,s.size()){
			if(s[i]=='(')a.push(b.size());
			else if(s[i]=='[')b.push(a.size());
			else if(s[i]==')'){
				if(a.size()==0||b.size()!=a.top()){
					flg = 0;
					break;
				}
				a.pop();
			}else if(s[i]==']'){
				if(b.size()==0||a.size()!=b.top()){
					flg = 0;
					break;
				}
				b.pop();
			}
		}
		if(a.size()||b.size())flg = 0;
		ans.push_back(flg);
	}
	for(auto e:ans){
		if(e)cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
}