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<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<iomanip>
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<string> vs;
Def inf=1e9;
signed main(){
    string s;
    while(getline(cin,s),s!="."){
        stack<int>st;
        bool h=true;
        rep(i,s.size()){
            if(s[i]=='('){
                st.push(0);
            }else if(s[i]==')'){
                if(st.size()&&st.top()==0){
                    st.pop();
                }else{
                    h=false;
                    break;
                }
            }else if(s[i]=='['){
                st.push(1);
            }else if(s[i]==']'){
                if(st.size()&&st.top()==1){
                    st.pop();
                }else{
                    h=false;
                    break;
                }
            }
        }
        if(st.size())h=false;
        if(h)cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
}

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

bool func(string t) {
  stack<char> p;
  for (int i = 0; i < t.size(); i++) {
    if (t[i] == '(') {
      p.push(t[i]);
    }
    else if (t[i] == '[') {
      p.push(t[i]);
    }
    else if (t[i] == ')') {
      if (p.empty()) {
        return false;
      }
      else {
        if (p.top() == '(') {
          p.pop();
        }
        else {
          return false;
        }
      }
    }
    else if (t[i] == ']') {
      if (p.empty()) {
        return false;
      }
      else {
        if (p.top() == '[') {
          p.pop();
        }
        else {
          return false;
        }
      }
    }
  }
  if (p.empty()) {
    return true;
  }
  else {
    return false;
  }
}

int main() {
  string s;
  while (getline(cin, s)) {
    if (s[0] == '.') {
      break;
    }
    bool flag = func(s);
    if (flag) {
      cout << "yes" << endl;
    }
    else {
      cout << "no" << endl;
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

//#define int long long

/*************** using variables ***************/
string s;
/**********************************************/

signed main(){
    while(getline(cin, s), s != "."){
        stack<char> st;
        auto itr = s.begin();
        bool flag = true;
        while(*itr != '.'){
            if(*itr == '['  || *itr == '(') st.push(*itr);
            if(*itr == ']'){
                if(st.top() != '['){
                    flag = false;
                    break;
                }else{
                    st.pop();
                }
            }
            if(*itr == ')'){
                if(st.top() != '('){
                    flag = false;
                    break;
                }else{
                    st.pop();
                }
            }
            ++itr;
        }
        cout << (flag ? "yes":"no") << endl;
        s = "";
    }
}

C++: #ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

int main()
{
	string str, a;
	while (1)
	{
		getline(cin, str);
		if (str == ".")break;
		a.clear();
		bool f = 1;
		for (auto x : str)
		{
			switch (x)
			{
				case '[':a.push_back('['); break;
				case '(':a.push_back('('); break;
				case ']':{
						if (!a.empty() && *a.rbegin() == '[')
						{
							a.pop_back();
						} else
						{
							f = 0;
						}
						break;
					}
				case ')':{
						if (!a.empty()&&*a.rbegin() == '(')
						{
							a.pop_back();
						} else
						{
							f = 0;
						}
						break;
					}
				default:
					break;
			}
		}
		if (!a.empty())
		{
			f = 0;
		}
		cout << (f ? "yes" : "no") << endl;
	}
}