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 <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){
	  hoge[i] = getchar();
	  //	  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++: #include<stack>
#include<cstdio>

using namespace std;

int main(){
	for(char s[128];fgets(s,128,stdin),s[0]!='.'||(s[1]!='\n'&&s[1]!='\0');){
		bool ok=true;
		stack<char> St;
		for(int i=0;s[i];i++){
			if(s[i]=='(') St.push(s[i]);
			if(s[i]=='[') St.push(s[i]);
			if(s[i]==')') if(St.empty() || St.top()=='['){ ok=false; break; } else St.pop();
			if(s[i]==']') if(St.empty() || St.top()=='('){ ok=false; break; } else St.pop();
		}
		puts(ok?"yes":"no");
	}

	return 0;
}

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

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

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

int main(){
  stack<int> p;
  string str;
  bool a;
  while(1){
    getline(cin,str);
    a = true;
    if(str == ".") break;
    for(int i=0;i<str.length();i++){
      char ch = str[i];
      if(ch == '(') p.push(1);
      if(ch == '[') p.push(2);
      if(ch == ')'){
        if(p.empty()){
          a = false;
          break;
        }
        if(p.top() == 1){
          p.pop();
        } else{
          a = false;
          break;
        }
      }
      if(ch == ']'){
        if(p.empty()){
          a = false;
          break;
        }
        if(p.top() == 2){
          p.pop();
        }else{
          a = false;
          break;
        }
      }
    }
    cout << (a?"yes":"no");
    while(!p.empty()){
      p.pop();
    }
    cout << endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <stack>


int main(void){
  char c;
  bool ok;

  while(1){
    char s[101] = {0};
    ok = true;
    std::stack<char> st;
    for(int i=0; i<101; i++){
      scanf("%c", &c);
      if(c == '\n'){
	s[i] = '\0';
	break;
      }else{
	s[i] = c;
      }
    }
    
    if(s[0] == '.'){
      break;
    }
    
    for(int i=0; i<101; i++){
      if(s[i] == '.'){
	break;
      }
      if(s[i] == '(' || s[i] == '['){
	st.push(s[i]);
      }else if(s[i] == ')'){
	if(st.empty() || st.top()!='('){
	  ok = false;
	  break;
	}else{
	  st.pop();
	}
      }else if(str[i] == ']'){
	if(st.empty() || st.top() != '['){
	  ok = false;
	  break;
	}else{
	  st.pop();
	}
      }
    }
    
    if(!st.empty()){
      ok = false;
    }
    
    if(ok){
      printf("yes\n");
    }else{
      printf("no\n");
    }
    
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
bool f(string s){
  int n=s.length();
  if(n==0) return true;
  if(n%2) return false;
  char c = s[0];
  if(c==')'||c==']') return false;
  char d = (c=='(')?')':']';
  int lv=1;
  int l = -1;
  for(int i=1;i<n;++i){
    if(s[i]==d) --lv;
    if(s[i]==c) ++lv;
    if(!lv){
      l = i;
      break;
    }
  }
  if(l==-1) return false;
  return f(s.substr(1,l-1))&&f(s.substr(l+1,n-l-1));
}

int main(){
  string s;
  while(getline(cin,s),s!="."){
    int t1=0,t2=0;
    int n = s.length();
    string t="";
    for(int i=0;i<n;++i){
      if(s[i]=='(' ||
	 s[i]==')' ||
	 s[i]=='[' ||
	 s[i]==']') t+=s[i];
    }
    if(f(t)) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  string s;
  while (getline(cin, s), s != ".") {
    stack<char> t;
    rep(i, s.size()) {
      if (s[i] == '[' || s[i] == '(') t.push(s[i]);
      if (s[i] == ')') {
        if (t.size() && t.top() == '(') {
          t.pop();
        } else {
          cout << "no" << endl;
          goto next;
        }
      }
      if (s[i] == ']') {
        if (t.size() && t.top() == '[') {
          t.pop();
        } else {
          cout << "no" << endl;
          goto next;
        }
      }
    }
    cout << (t.size() ? "no" : "yes") << endl;
  next:;
  }
}