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++: // 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:;
  }
}

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

using namespace std;

int main(void){
  string s;

  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];

    stack<char> str;
    bool flag = true;
    for(int i=0;i<ch.length();i++){
      
      if(str.empty() || ch[i]=='(' || ch[i]=='[')str.push(ch[i]);
      else if((ch[i]==')' && str.top()=='(')||(ch[i]==']' && str.top()=='[')){str.pop();}
      else {
	flag = false;
	break;
      }
    }

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

  }

  return 0;
}

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

using namespace std;

int main()
{
    while (true) {
        string s;
        getline(cin, s);
        if (s[0] == '.') {
            break;
        }

        stack<char> st;
        bool ok = true;
        for (auto&& c : s) {
            if (!ok) {
                break;
            }
            switch (c) {
            case '(':
                st.push(c);
                break;
            case '[':
                st.push(c);
                break;
            case ')':
                if (!st.empty() && st.top() == '(') {
                    st.pop();
                }
                else {
                    ok = false;
                }
                break;
            case ']':
                if (!st.empty() && st.top() == '[') {
                    st.pop();
                }
                else {
                    ok = false;
                }
                break;
            }
        }
        if (ok) {
            printf("yes\n");
        }
        else {
            printf("no\n");
        }
    }
}

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

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

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[1000];
	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<iostream>
#include<cstdio>

using namespace std;

int main(){
  char r[100];
  int count = 0;
  char s;
  char c;
  int maru=0;
  int shikaku=0;
  while(true){
    cin>>s;
    if(s=='.')break;
    else if(s=='('){
      r[count++]=')';
      maru++;
    }
    else if(s=='['){
      r[count++]=']';
      shikaku++;
    }
    else if(s==')'){
      if(r[count--]==s){
	maru--;
      }
    }
    else if(s==']'){
      if(r[count--]==s){
	shikaku--;
      }
    }
    
    
    while(true){
      cin>>c;
      if(c=='.'||maru<0||shikaku<0)break;
      else if(c=='('){
	r[count++]=')';
	maru++;
      }
      else if(c=='['){
	r[count++]=']';
	shikaku++;
      }
      else if(c==')'){
	if(r[count-1]==c){
	  count--;
	  maru--;
	}
	else maru=-1111111;
      }
      else if(c==']'){
	if(r[count-1]==c){
	  count--;
	  shikaku--;
	}
	else shikaku=-111111;
      }
    }

    if(maru==0&&shikaku==0)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    if(c!='.'){
      while(true){
	cin>>c;
	if(c=='.')break;
      }
    }
    maru=0;
    shikaku=0;
  }
     if(maru==0&&shikaku==0)cout<<"yes"<<endl;
      else cout<<"no"<<endl;
  

  return 0;
}