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 solve(string &s) {
  stack<char> st;
  for(int i = 0; i < (int)s.length(); ++i) {
    if(s[i] == '[' || s[i] == '(') st.push(s[i]);
    if(s[i] == ']') {
      if(st.top() != '[') return 0;
      st.pop();
    }
    if(s[i] == ')') {
      if(st.top() != '(') return 0;
      st.pop();
    }
  }
  return 1;
}

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

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
 

int main(){
	string s;
	while(getline(cin,s)){
		if(s==".") break;
		stack<char> st;
		bool flag = true;
		for(char c : s){
			if(c == '(' || c == '[') st.push(c);
			else if(c ==')') {
				if(st.empty() || st.top() != '(') {
					flag =false;
					break;
				}
				st.pop();
			} 
			else if(c ==']') {
				if(st.empty() || st.top() != '[') {
					flag =false;
					break;
				}
				st.pop();
			} 
		}
		if(!st.empty()) flag = false;
		cout<<(flag?"yes":"no")<<endl;
	}
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}


int main(void){
	string s;
	while(getline(cin, s) && s != "."){
		string t = "";
		REP(i, s.size()){
			if(string("()[]").find(s[i]) != string::npos){
				t += s[i];
			}
		}
		while(1){
			int32 l = 0;
			int32 cnt = 0;
			REP(i, t.size()){
				if(t[l] == '(' && t[i] == ')'){
					t[l] = t[i] = '.';
					cnt++;
				}else if(t[l] == '[' && t[i] == ']'){
					t[l] = t[i] = '.';
					cnt++;
				}
				if(t[i] != '.')
					l = i;
			}
			if(cnt == 0)
				break;
		}
		int32 cnt = 0;
		REP(i, t.size())
			if(t[i] == '.') cnt++;

		if(cnt == t.size())
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
}

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

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

      stack<char> stk;
      int cnt = 0;
      bool ok = false;
      int n = s.size();
      for (int i = 0; i < n; i++) {
         if (s[i] == '(') stk.push(s[i]);
         if (s[i] == '[') stk.push(s[i]);
         if (s[i] == ')') {
            if (stk.empty() || stk.top() != '(') {
               ok = true;
               break;
            }
            stk.pop();
         }
         if (s[i] == ']') {
            if (stk.empty() || stk.top() != '[') {
               ok = true;
               break;
            }
            stk.pop();
         }
      }
      if (!ok && stk.empty()) {
         puts("yes");
      } else {
         puts("no");
      }
   }

   return 0;
}

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

int main(){
    char s[108];
    stack<int> stk;
    cin.getline(s, 101);
    while(s[0] != '.' && s[1] != '\0'){
        int rnd = 0, box = 0, no = 0;
        for(int i = 0; i < sizeof(s); i++){
            if(s[i] == '(') stk.push(0);
            if(s[i] == '[') stk.push(1);
            if(s[i] == ')'){
                if(stk.empty() || stk.top() != 0){
                    no = 1;
                    break;
                }
                stk.pop();
            }
            if(s[i] == ']'){
                if(stk.empty() || stk.top() != 1){
                    no = 1;
                    break;
                }
                stk.pop();
            }
            if(s[i] == '\0') break;
        }
        if(no == 0 && rnd == 0 && box == 0){
            printf("yes\n");
        } else {
            printf("no\n");
        }
        cin.getline(s, 101);
    }
}