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

bool check(const string& s)
{
  stack<char> stk;
  for (string::const_iterator it = s.begin(); it != s.end(); ++it) {
    switch (*it) {
      case '(':
        stk.push(')');
        break;
      case '[':
        stk.push(']');
        break;
      case ')':
      case ']':
        if (stk.empty() || stk.top() != *it) {
          return false;
        }
        stk.pop();
        break;
    }
  }
  return stk.empty();
}

int main()
{
  for (string s; getline(cin, s) && s != ".";) {
    cout << (check(s) ? "yes" : "no") << endl;
  }
  return 0;
}

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

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

C++: #include<bits/stdc++.h>
#define REP(i,s,n) for(int i=s ; i < n ; i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int main(){
  
  string in;
  int cnt_left,cnt_right,cnt2_left,cnt2_right;
  bool balance;
  int sum,cnt_sum;

  while(1){
    
    getline(cin,in);
    if(in == ".")break;
    
    balance=true;
    cnt_left=0;cnt_right=0;
    cnt2_left=0;cnt2_right=0;
    sum=0;cnt_sum=0;

    rep(i,in.size()){
      if(in[i]=='('){
	if(cnt_sum%2 == 0){
	  sum++;
	}else{
	  sum--;
	}
	cnt_left++;
	cnt_sum++;
      }else if(in[i]==')'){
	if(cnt_sum%2 == 0){
	  sum++;
	}else{
	  sum--;
	}
	cnt_right++;
	cnt_sum++;
	if(cnt_right > cnt_left)break;
      }else if(in[i]=='['){
	if(cnt_sum%2 == 0){
	  sum+=2;
	}else{
	  sum-=2;
	}
	cnt2_left++;
	cnt_sum++;
      }else if(in[i]==']'){
	if(cnt_sum%2 == 0){
	  sum+=2;
	}else{
	  sum-=2;
	}
	cnt2_right++;
	cnt_sum++;
	if(cnt2_right > cnt2_left)break;
      }
    }
    
    if(cnt_right != cnt_left || cnt2_right != cnt2_left || sum!=0)balance=false;

    if(balance){
      cout <<"yes"<<endl;
    }else{
      cout <<"no"<<endl;
    }
    
  }
  return 0;
}

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

using namespace std;

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

int main(){

	solve();

	return 0;
}

C++: #include<iostream> 
#include<cstdio> 
#include<cstring> 
using namespace std; 
void test(int ); 
int f,count,count1; 
char ch[101];  

int main(){ 
  while(1){ 
    int j=0; 
    f=0,count=0,count1=0;
    while(1){ 
      scanf("%c",&ch[j]); 
      if(ch[j]=='.')break; 
      j++; 
    } 
    if(j==0)break; 
    for(int i=0;i<j;i++){ 
      if(ch[i]=='[')count++; 
      else if(ch[i]=='(')count1++; 
      else if(ch[i]==']' || ch[i]==')')test(i); 
      if(count1<0||count<0||f==1)break;  
    } 
    if(count==0&&count1==0)cout<<"yes"<<endl; 
    else cout<<"no"<<endl;   
    char a;
    scanf("%c",&a); 
  } 
  return 0; 
} 

void test(int x){ 
  f=0; 
  int count2=0; 
  if(ch[x]==')'){ 
    count1--; 
    for(int i=x-1;i>=0;i--) 
      if(ch[i]=='('){ 
	for(int j=x-1;j>i;j--) 
	  if(ch[j]=='[')count2++; 
	  else if(ch[j]==']')count2--; 
	break; 
      } 
  } 
  else if(ch[x]==']'){ 
    count--; 
    for(int i=x-1;i>=0;i--) 
      if(ch[i]=='['){ 
	for(int j=x-1;j>i;j--) 
	  if(ch[j]=='(')count2++; 
	  else if(ch[j]==')')count2--; 
	break; 
      } 
  } 
  if(count2>0)f=1; 
}

C++: 
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
#define out(S) cout<<(S)<<endl;
#define REP(i,b) for(size_t i=0;i<(b);i++)
#define rREP(i,b) for(int i=(b)-1;i>=0;i--)
#define FOR(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define Foreach(item,collection) for(auto item:collection)
#define mod(i) ((i) % (ll)(1e9 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9 + 5))))
#define Yes out("Yes")
#define No out("No")
#define NO out("NO")
#define YES out("YES")
#define INF 1e10;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define IfOut(condition,text) if((condition)){out(text);return 0;}
#define IfeOut(condition,itext,etext) if(condition){out(itext);return 0;}else{out(etext);return 0;}
#define Select(collection,condition,result) Foreach(i,collection){result+=condition;}
#define GetAuto(_N,vect) {cin>>_N;vect.resize(_N);REP(i,_N){cin>>vect[i];}}
#define beginend(vec) (vec).begin(),(vec).end()
#define pb(item) push_back(item)
#define removeAll(vec,deleg) auto itr=remove_if(beginend(vec),deleg);vec.erase(itr,vec.end());
void removeAt(string& s, int index) { s.erase(index, 1); }
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
ll manhattanDistance(ll x1, ll y1, ll x2, ll y2) { return (abs(x2 - x1) + abs(y2 - y1)); }
vector<ll> sieveOfEratosthenes(int max) {ll prime;double sqrtmax = sqrt(max);vector<ll> primeVec, searchVec;FOR(i, 2, max + 1) searchVec.push_back(i);do{prime = searchVec[0];primeVec.push_back(prime);auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; });searchVec.erase(itr, searchVec.end());} while (prime < sqrtmax);primeVec.reserve(primeVec.size() + searchVec.size());primeVec.insert(primeVec.end(), beginend(searchVec));return primeVec;}

int solve(string S) {
	int maru = 0, kaku = 0;
	Foreach(i, S) {
		if (i == '(') maru++;
		else if (i == '[') kaku++;
		else if (i == ')') {
			if (maru > 0) maru--;
			else {
				break;
			}
		}
		else if (i == ']') {
			if (kaku > 0)kaku--;
			else {
				break;
			}
		}
	}
	IfeOut(kaku == 0 && maru == 0, "yes", "no");
}

int main() {
	char S[100];
	while (cin.getline(S, sizeof(S)), S != ".")
	{
		solve(S);
	}
	return 0;
}