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 <cstdio>
#include <utility>
#include <stack>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
//is(string &s){int c;
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T>
//void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

int main() {
	for (;;) {
		stack<char> s;
		bool world = true, b = false;
		for (char c; c = gcu(), c != '.'; b = true)
			if (world)
				switch(c) {
				case '(': s.push(')'); break;
				case '[': s.push(']'); break;
				case ')':
				case ']':
					if (s.empty() || s.top() != c)
						world = false;
					else
						s.pop();
					break;
				}
		if (b) {
			gcu();
			out(world && s.empty() ? "yes" : "no", '\n');
		} else
			break;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){

  while(1){
	char hoge[200];
	int i = 0;

	//	getline(cin, hoge);

	while(1){
	  scanf("%c",&hoge[i]);
	  if(hoge[i]=='\n') continue;
	  if(hoge[i]=='.') break;
	  i++;
	}
	if(hoge[0]=='.') break;

	int mini = 0;
	int big = 0;
	bool now[200] = {};
	int b=0;
 //????????§??????????????????

	REP(a,i){
	  if(hoge[a]=='('){
		mini++;
		b++;
		now[b] = false;
	  }else if(hoge[a]==')'){
		if(now[b] == false) {
		  mini--;
		  b--;
		}else break;
	  }else if(hoge[a]=='['){
		big++;
		b++;
		now[b] = true;
	  }else if(hoge[a]==']'){
		if(now[b] == true){
		  big--;
		  b--;
		}else break;
	  }
	  if(mini < 0||big < 0) break;
	}

	if(mini==0&&big==0) cout << "yes" << endl;
	else cout << "no" << endl;
  }
}

C++: // Tenbin_1173.cpp
#include <iostream>
#include <string>
using namespace std;
string lol(string str){
	string r;
	int lcb,rcb,lsb,rsb,cbcount,sbcount;
	int charcount = 0;
	lcb = 0;
	rcb = 0;
	lsb = 0;
	rsb = 0;
	cbcount = 0;
	sbcount = 0;
	while(true){
		if(str[charcount] == '('){
			lcb++;
		}else if(str[charcount] == ')'){
			rcb++;
		}else if(str[charcount] == '['){
			lsb++;
		}else if(str[charcount] == ']'){
			rsb++;
		}else if(str[charcount] == '.'){
			break;
		}
		if(lcb<rcb||lsb<rsb){
			r = "no";
			return r;
		}
		charcount ++;
	}
	if(lcb == rcb && lsb == rsb){
		r = "yes";
		return r;
	}else{
		r = "no";
		return r;
	}
	return "no";
}
int main()
{
	string str;
	while(getline(cin,str)){
		if(str=="."){
			break;
		}else{
			cout << endl;
		}
		cout << lol(str);
	}
	return 0;
}

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

int main(){
	string s;
	while( getline(cin,s) ){
		if( s == "." ) break;

		stack<char> st;
		bool flag = true;
		for(int i=0 ; i < (int)s.size() ; i++ ){
			char c = s[i];
			if( c == '(' ){
				st.push( c );
			}else if( c == '[' ){
				st.push( c );
			}else if( c == ')' ){
				if( st.empty() ){
					flag = false;
					break;
				}else if( st.top() == '(' ){
					st.pop();
				}else{
					flag = false;
					break;
				}
			}else if( c == ']' ){
				if( st.empty() ){
					flag = false;
					break;
				}else if( st.top() == '[' ){
					st.pop();
				}else{
					flag = false;
					break;
				}
			}
		}
		if( st.empty() && flag ){
			cout << "yes" << endl;
		}else{
			cout << "no" << endl;
		}
	}
}

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

using namespace std;

int main(void){
  string s;
  stack<char> str;

  while(getline(cin,s) && s!="."){

    string ch;
    for(int i=0;i<s.size();i++)
      if(s[i]=='[' || s[i]=='(' || s[i]==']' || s[i]==')')ch+=s[i];

    for(int i=0;i<ch.length();i++){
      
      if(ch[i]=='(' || ch[i]=='[')str.push(ch[i]);
      if(ch[i]==')' && str.top()=='(')str.pop();
      if(ch[i]==']' && str.top()=='[')str.pop();
    }

    cout << (str.empty()?"YES":"NO") << endl;

  }

  return 0;
}

C++: #include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
const int DX[8]={-1,0,1,0,-1,-1,1,1},DY[8]={0,-1,0,1,-1,1,-1,1};

const int NPrime=3000000;
bool prime[NPrime+1];
vi EnumeratePrime(){
	fill(prime+2,prime+NPrime+1,true);
	vi a;
	for(int i=2;i<=NPrime;i++) if(prime[i]){
		a.emplace_back(i);
		for(int j=2*i;j<=NPrime;j+=i) prime[j]=0;
	}
	return a;
}

string s;

int main(){
//	EnumeratePrime();
	while(1){
		getline(cin,s);
		if(s==".") break;
		int n=s.size();
		stack<char> st;
		bool B=1;
		for(int i=0;i<n;i++){
			if(s[i]=='('||s[i]=='[') st.push(s[i]);
			if(s[i]==')'){
				if(!st.empty()&&st.top()=='('){
					st.pop();
				}
				else{
					B=0;
					break;
				}
			}if(s[i]==']'){
				if(!st.empty()&&st.top()=='['){
					st.pop();
				}
				else{
					B=0;
					break;
				}
			}
		}
		if(!st.empty()) B=0;
		if(B) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
}