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

	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) {
				cout << "no" << endl;
			}
			st.pop();
		} else if(c == ']') {
			if(st.top() != 1) {
				cout << "no" << endl;
		}
			st.pop();
			}
		}

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

	}

	return 0;
}

C++: #include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

int main(){
    char buf[200];
    while(fgets(buf, sizeof(buf), stdin), buf[0] != '.'){
        stack<char> s;

        for(int i = 0; i < strlen(buf); i++){
            if(not s.empty()){
                if(s.top() == '(' && buf[i] == ')'){
                    s.pop();
                    continue;
                } else if(s.top() == '[' && buf[i] == ']'){
                    s.pop();
                    continue;
                }
            }

            if(buf[i] == '(' || buf[i] == ')' || buf[i] == '[' || buf[i] == ']') s.push(buf[i]);

        }
        if(s.empty()) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>
#include <stack>

using namespace std;

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

	bool success = true;
	stack<char> s;
	for ( char ch : input ) {
	  if ( ch == '[' or ch == '(' ) {
		s.push( ch );
	  } else if ( ch == ']' ) {
		if ( s.empty() or s.top() != '[' ) {
		  success = false;
		  break;
		}
		s.pop();
	  } else if( ch == ')' ) {
		if ( s.empty() or s.top() != '(' ) {
		  success = false;
		  break;
		}
		s.pop();
	  }
	}
	if ( success ) {
	  cout << "yes" << endl;
	} else {
	  cout << "no" << endl;
	}
  }
}

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

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

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

using namespace std;

int main(void){
	char letter[100];
	stack<char>st;
	while(1){
		fgets(letter, 100, stdin);
		if(letter[0] == '.') break;
		int i = 0;
		while(letter[i] != '\0'){
			if(letter[i] == '(' || letter[i] == '[')
			st.push(letter[i]);
			if(st.empty() == false){
			if(letter[i] == ')'){
				if(st.top() == '(')
				st.pop();
			}
			if(letter[i] == ']'){
				if(st.top() == '[')
				st.pop();
			}
			}
			i++;
		}
		if(st.empty())
		cout << "yes" << endl;
		else
		cout << "no" << endl;
		for(int i = 0; i < st.size(); i++)
			st.pop();
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <string>
#include <climits>

#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define PRINT(STR) cout << (STR) << endl

typedef long long ll;
using namespace std;

int main() {
	char stc[1024];
	int counter = 0;
	string str;
	while (str = "", getline(cin, str), str != ".") {
		counter = 0;
		bool flag = true;
		REP(i, str.size()) {
			if (flag == false ) break;
			if (str[i] == '[' || str[i] == '(') {
				stc[counter++] = str[i];
			} else if (str[i] == ']') {
				if (counter == 0 || stc[--counter] != '[') {
				  flag = false;
				}
			} else if (str[i] == ')') {
				if (counter == 0 || stc[--counter] != '(') {
				  flag = false;
				}
			}
		}
		if (counter == 0 && flag == true) {
			PRINT("yes");
		} else {
			PRINT("no");
		}
	}
	return 0;
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#include<string>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))
#define ALL(c) (c).begin(), (c).end()
// #define dump(a) cerr << #a << "=" << (a) << endl

using namespace std;

int main() {
	string line;
	char left_paren;
	bool is_yes;
	vector<char> left_parens;

	while(getline(cin,line)) {
		if (line[0] == '.') break;

		left_parens.clear();
		is_yes = true;

		rep(i,line.size()) {
			if (line[i] == '(') {
				left_parens.push_back(line[i]);
			}
			else if (line[i] == '[') {
				left_parens.push_back(line[i]);
			}
			else if (line[i] == ')') {
				left_paren = left_parens.back();
				if (left_paren != '(') {
					is_yes = false;
				}
				left_parens.pop_back();
			}
			else if (line[i] == ']') {
				left_paren = left_parens.back();
				if (left_paren != '[') {
					is_yes = false;
				}
				left_parens.pop_back();
			}
		}
		if (left_parens.size() > 0)
			is_yes = false;

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

	return 0;
}