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<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
string str;
stack<char> s;
char c;
int main(){
	while(getline(cin,str)){
		while(!s.empty()){
			s.pop();
		}
		bool flag =true;
		if(str.length()==1&&str[0]=='.')
			break;
		for(int i = 0;i <str.length();i++){
			if(str[i]=='('){
				s.push('(');
			}else if(str[i]=='['){
				s.push('[');
			}else if(str[i]==')'){
				if(s.empty()){
					flag =false;
					break;
				}
				c = s.top();
				if(c!='('){
					flag = false;
					break;
				}
				s.pop();
			}else if(str[i]==']'){
				if(s.empty()){
					flag =false;
					break;
				}
				c =s.top();
				if(c!='['){
					flag =false;
					break;
				}
				s.pop();
			}
		}
		if(flag)
			cout <<"yes"<<endl;
		else
			cout <<"no"<<endl;
	}
	return 0;
}

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;


bool solve(string str){
	if(str == ".") return true;
	bool ans = true;
	stack<char> s;
	for(int i=0;i<str.size();i++){
		if(str[i] == '(') s.push(')');
		if(str[i] == '[') s.push(']');
		if(str[i] == ')' || str[i] == ']'){
			if(s.empty() || str[i] != s.top()){
				ans = false;
				break;
			}
			s.pop();
		}
	}
	if(ans && s.empty()){
		cout<< "yes"<< endl;
	}else{
		cout<< "no"<< endl;
	}
	
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	string str;
	while(getline(cin, str)){
		solve(str);
	}
	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() {
	cin.tie(0); //対話型には使えない
	ios::sync_with_stdio(false); //printfと共には使えない
	string str;
	while (str = "", getline(cin, str), str != ".") {
		stack<char> s;
		REP(i, str.size()) {
			if (str[i] == '[' || str[i] == '(') {
				s.push(str[i]);
			} else if(str[i] == ']') {
				if (s.size() == 0) {
					PRINT("no");
					break;
				}
				char t = s.top();
				s.pop();
				if (t != '[') {
					PRINT("no");
					break;
				}
			} else if(str[i] == ')') {
				if (s.size() == 0) {
					PRINT("no");
					break;
				}
				char t = s.top();
				s.pop();
				if (t != '(') {
					PRINT("no");
					break;
				}
			}
			if (i == str.size() - 1) {
				PRINT("yes");
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
using namespace std;

string str;

bool solve(int p, char c) {
	for (int i = p+1; i < str.size(); i++) {
		if (str[i] == ']' || str[i] == ')') {
			if (str[i] == c) {
				str[p] = str[i] = ' ';
				return 1;
			} else {
				break;
			}
		} else if (str[i] == '(' || str[i] == '[') {
			char t = (str[i] == '(' ? ')' : ']');
			if (!solve(i, t)) {
				break;
			}
		}
	}
	return 0;
}

int main()
{	
	while (getline(cin, str), str != ".") {
		bool f = 0;

		for (int i = 0; i < str.size(); i++) {
			if (str[i] == '(' || str[i] == '[') {
				f = 1;
				char t = (str[i] == '(' ? ')' : ']');
				if (solve(i, t)) f = 0;
			} else if (str[i] == ')' || str[i] == ']') f = 1;
			if (f) break;
		}
		if (!f) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	
	return 0;
}

C++: #include <stdio.h>
#include <vector>
#include <queue>
#include <memory.h>
#include <functional>
#include <algorithm>
using namespace std;
#include <stack>

//FILE * in = freopen("input.txt", "r" , stdin);
char data[1000];


int main() {
	
	while(true) {
		bool flag = false;
		gets(data);
		if(data[0] == '.' && data[1] == 0)break;
		int i = 0;
		stack<int> a;
		while(data[i] != '.'){
			switch(data[i])
			{
			case '(':
				a.push('(');
				break;
			case '[':
				a.push('[');
				break;
			case ')':
				if(a.empty()) {
					flag = true;
					goto out;
				}
				if(a.top() == '(')
					a.pop();
				else {
					flag = true;
					goto out;
				}
				break;

			case ']':
				if(a.empty()) {
					flag = true;
					goto out;
				}
				if(a.top() == '[')
					a.pop();
				else {
					flag = true;
					goto out;
				}
				break;
			default:
				break;
			}
			i++;
		}
		out:
		if(!flag)
			puts("yes");
		else
			puts("no");
	}

	return 0;
}

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

using namespace std;
typedef long long ll;

#define LOOP(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) LOOP(i, 0, n)
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359

int main(void) {
  vector<string> ans;
  while (true) {
    string s;
    getline(cin, s);
    if (s == ".")
      break;
    stack<int> st;
    bool flag = true;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '(')
        st.push(1);
      else if (s[i] == '[')
        st.push(2);
      else if (s[i] == ')') {
        if (!st.empty() && st.top() == 1)
          st.pop();
        else {
          flag = false;
          break;
        }
      } else if (s[i] == ']') {
        if (!st.empty() && st.top() == 2)
          st.pop();
        else {
          flag = false;
          break;
        }
      }
      /*
      stack<int> debug;
      debug = st;
      while (!debug.empty()) {
        cout << debug.top() << " ";
        debug.pop();
      }
      cout << endl; */
    }
    if(!st.empty()) flag = false;
    if (flag) {
      ans.push_back("yes");
    } else {
      ans.push_back("no");
    }
  }

  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }

  return 0;
}