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<string>
using namespace std;

int main()
{

	string text;

	getline(cin,text);
	while(text[0] != '.'){
		int ans=1 ,brac[50]={0} ,n=0;
		for(int i=0 ; text[i]!='.'; i++){
			//test	cout<<(int)text[i]<<" ";
			if(text[i]=='('){
				brac[n]=1;
				n++;
			}
			if(text[i]==')'){
				if(n==0) ans=0;
				else if(brac[n-1]!=1) ans=0;
				else{
					n--;
					brac[n]=0;
				}
			}
			if(text[i]=='['){
				brac[n]=2;
				n++;
			}
			if(text[i]==']'){
				if(n==0) ans=0;
				else if(brac[n-1]!=2) ans=0;
				else{
					n--;
					brac[n]=0;
				}
			}
			if(ans==0) break;
		}
		if(ans==0 ||  n!=0) cout<<"no"<<endl;
		else cout<<"yes"<<endl;
		getline(cin,text);
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;


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

    stack<bool> st;
    bool flag = true;
    for(int i=0; i<s.size(); i++) {
      if( s[i] == '(' ) st.push( true );
      if( s[i] == '[' ) st.push( false );
      if( s[i] == ')' ) {
	if( st.size() == 0 ) {flag = false; break;}
	bool tmp = st.top(); st.pop();
	if( !tmp ) {flag = false; break;}  
      }
      if( s[i] == ']' ) {
	if( st.size() == 0 ) {flag = false; break;}
	bool tmp = st.top(); st.pop();
	if( tmp ) {flag = false; break;}  
      }
    }

    if( flag ) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

C++: #include <iostream>
#include <stack>
#include <stdio.h>
using namespace std;
int main(){
  /* while(true){
    stack<char> st;
    string str;
    int flag = 0;
    cin >> str;
    if(str == ".")return 0;
    int i = 0;
    while(true){
      if(str[i] == '(' || str[i] == '['){
	st.push();
      }

    }
    
    
  }
  }*/
  
  int flag = 0;
  while(true){
    stack<char> st;
    char tmp;
    scanf("%c",&tmp);
    if(tmp == '.')return 0;
    if(tmp != '\n'){
      while(true){
	if(tmp == '(' || tmp == '['){
	  //cout << "入力" << tmp << endl;
	  st.push(tmp);
	}
	else if(tmp == ')' || tmp == ']'){
	  if(tmp == ')')tmp = '(';
	  if(tmp == ']')tmp = '[';
	  if(st.empty()){
	    flag = 1;
	    //break;
	  }
	  else if(st.top() != tmp){
	   
	    //  cout << tmp << endl;
	    flag = 1;
	  }
	  if(flag != 1)st.pop();
	}else if(tmp == '.'){
	  break;
	}
	scanf("%c",&tmp);
      }
    
      if(flag != 1){
	if(st.empty()){
	cout << "yes" << endl;
	}else cout << "no" << endl;
      }else cout << "no" << endl;
      flag = 0;
    }
  }
}

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]=='('){
				int num=st.top();
				if(num==0){
					st.pop();
				}
			}
			if(s[i]==']'){
				int num=st.top();
				if(num==1){
					st.pop();
				}
			}
		}
		if(st.empty()) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

string s;

int main()
{
    while (getline(cin, s))
    {
        if (s == ".")
            break;
        stack<char> st;
        bool flag = true;
        int N = s.size();
        for (int i = 0; i < N && flag; i++)
        {
            if (s[i] == '(')
                st.push(s[i]);
            if (s[i] == '[')
                st.push(s[i]);
            if (s[i] == ')')
            {
                if (st.size() > 0 && st.top() == '(')
                    st.pop();
                else
                    flag = false;
            }
            if (s[i] == ']')
            {
                if (st.size() > 0 && st.top() == '[')
                    st.pop();
                else
                    flag = false;
            }
        }
        if (st.empty() == false)
            flag = false;
        cout << ((flag ? "yes\n" : "no\n"));
    }
}