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 <bits/stdc++.h>

using namespace std;

#define rep(i, n) REP((i), 0, (n))
#define REP(i, a, n) for(int i=(a); i<(n); i++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(1) {
        string s; 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 == ')' || c == ']') {
                if(st.empty() || st.top() != c) {
                    flag = false;
                    break;
                }
                st.pop();
            }
        }
        flag = flag? st.empty():flag;
        cout << (flag? "yes":"no") << endl;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <cassert>
// using namespace std;
// #define int long long
#define REP(i,s,n) for (int i = (s); i < (n); ++i)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) for (int i = n; i >= 0; i--)
#define INF (int)(1e9+7)
#define space " "
#define ENDL "\n"
#define MAXL 100

int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};

inline void init() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
}
// ??¢?????¬??????????????????????????????????????????!!
inline void nextInt(int *a) { scanf("%d", a); }
inline void nextInt(int *a, int *b) { scanf("%d %d", a, b); }
inline void nextInt(int *a, int *b, int *c) { scanf("%d %d %d", a, b, c); }
inline void nextDouble(double *a) { scanf("%lf", a); }
inline void nextDouble(double *a, double *b) { scanf("%lf %lf", a, b); }
inline void nextDouble(double *a, double *b, double *c) { scanf("%lf %lf %lf", a, b, c); }
inline void nextLine(char *c) { scanf("%s", c); getchar();/*?????????????????¨???*/ }
inline std::string nextLine() {
    std::string s = ""; char str[MAXL+1];
    scanf("%s", str); getchar(); /*?????????????????¨???*/
    return s += str;
}
inline void print(double *a, int n = 0) {
    std::cout << std::fixed << std::setprecision(n) << *a << ENDL;
}
inline void print(int a) {
    printf("%d\n", a);
}

/************************End of templete*************************/

int main() {
    std::string s;
    bool flag = true;
    std::stack<char> st, ini;

    init();

    while (true) {
        st = ini;
        flag = true;
        std::getline(std::cin, s);
        if (s[0] == '.') break;

        rep(i,s.size()) {
            if (s[i] == '(' || s[i] == '[') {
                st.push(s[i]);
            } else if (s[i] == ')' || s[i] == ']') {
                if (st.empty()) {
                    flag = false;
                    break;
                } else if ((s[i] == ')' && st.top() == '[') ||
                            (s[i] == ']' && st.top() == '(')) {
                            flag = false;
                            break;
                } else {
                    st.pop();
                }
            }
        }

        if (flag) std::cout << "yes" << ENDL;
        else std::cout << "no" << ENDL;
    }

    return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <stack>

using namespace std;


string words;

void solve(){
  stack<char> st;
  for(int i = 0; '.' != words[i];i++){
    if(words[i] == '(' || words[i] == '['){
      st.push(words[i]);
    }else if(words[i] == ')'){
      if(!st.empty()){
        if(st.top() == '('){
          st.pop();
        }else{
          cout << "no" << endl;
          return;
        }
      }else{
        cout << "no" << endl;
        return;
      }
    }else if(words[i] == ']'){
      if(!st.empty()){
        if(st.top() == '['){
          st.pop();
        }else{
          cout << "no" << endl;
          return;
        }
      }else{
        cout << "no" << endl;
        return;
      }
    }
  }
  if(st.empty()) cout << "yes" << endl;
  return;
}




int main(){
  while(true){
    words = "";
    //string x;
    getline(cin , words);
    //cin >> x;
    //cout << words << endl;
    if(words[0] == '.') break;
    solve();
  }
  return 0;
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-10;


int main() {
	string str;
	stack<int> st;

	bool successed = true;

	while(getline(cin, str) && str != ".") {
		st.push(2);

		FOR(i, 0, str.size()) {
			char c = str[i];

			if(c == '(') {
				st.push(0);
			} else if(c == '[') {
				st.push(1);
			} else if(c == ')') {
				if(st.top() != 0) {
					successed = false;
					break;
				}
				st.pop();
			} else if(c == ']') {
				if(st.top() != 1) {
					successed = false;
					break;
				}
				st.pop();
			}
		}

		if(successed) {
			if(st.top() == 2) {
				cout << "yes" << endl;
			} else {
				cout << "no" << endl;
			}
		} else {
			cout << "no" << endl;
		}

	}

	return 0;
}

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

int main(){
  string str;
			
  while(getline(cin, str)){
	if(str == ".") break;
	//cout << str << endl;
	bool flag  = false;
	stack<char> s;
	for(int i = 0; i < str.size(); i++){
	  if(str[i] == '(') s.push(str[i]);
	  else if(str[i] == '[') s.push(str[i]);
	  else if(str[i] == ')'){
		if(s.empty()){
		  flag = true;
		  break;
		}
		
		char tmp = s.top(); s.pop();
		//cout << "if ')' then tmp = " << tmp << endl;
		if(tmp != '('){
		  flag = true;
		  break;
		}
	  }
	  else if(str[i] == ']'){
		if(s.empty()){
		  flag = true;
		  break;

		}
		char tmp = s.top(); s.pop();
		//cout << "if ']' then tmp  = " << tmp << endl;
		if(tmp  != '['){
		  flag = true;
		  break;
		}
	  }
	}
	
	if(flag) cout << "no" << endl;
	else cout << "yes" << endl;
  }
  return 0;
}