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 int long long

char* Solve(string S)
{
    stack<char> s;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] == '(') s.push('(');
        else if (S[i] == '[') s.push('[');
        else if (S[i] == ')')
        {
            if (s.empty() || s.top() != '(') return "no";
            s.pop();
        }
        else if (S[i] == ']')
        {
            if (s.empty() || s.top() != '[') return "no";
            s.pop();
        }
    }
    return "yes";
}

signed main()
{
    string S;
    while (getline(cin, S), S != ".")
    {
        printf("%s\n", Solve(S));
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
bool solve(string c){
  stack<char> st;
  rep(i,c.size()){
    if(c[i] == '(') st.push(c[i]);
    else if(c[i] == '[' ) st.push(c[i]);
    else if(c[i] == ')'){
      if(st.top() != '(') return false;
      if(st.empty()) return false;
      st.pop();
    }
    else if(c[i] == ']'){
      if(st.top() != '[') return false;
      if(st.empty()) return false;
      st.pop();
    }
    return st.empty();
  }
}
int main(){
  string s;
  bool flag;
  while(1){
    getline(cin,s);
    if(s == ".") break;
    if(solve(s)) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

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

using namespace std;

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

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define clear(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


bool ok(const string& s)
{
	int maru = 0, sika = 0;
	stack<char> use;
	for (int i = 0; i < s.size(); ++i)
	{
		if (s[i] == '(')
			++maru;
		else if (s[i] == ')')
			--maru;
		else if (s[i] == '[')
			++sika;
		else if (s[i] == ']')
			--sika;

		if (strchr("([", s[i]))
			use.push(s[i]);
		else if (strchr(")]", s[i]))
		{
			if (use.empty())
				return false;

			char last = use.top(); use.pop();
			if (last == '(' && s[i] == ']'
				|| last == '[' && s[i] == ')')
				return false;
		}
	}
	return maru == 0 && sika == 0;
}
int main()
{
	string s;
	while (getline(cin, s), s.size() > 1 || s[0] != '.')
		puts(ok(s) ? "yes" : "no");
}

C++: /*
 * by purple
 * at 12-01-01 10:58:09
 */

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

#define sz(x) ((int)((x).size()))
#define out(x) printf(#x" %d\n", x)
#define rep(i,n) for(int i=0;i<(n);++i)
#define repf(i,a,b) for(int i=(a);i<=(b);++i)

const int maxn = 100 + 10;

char s[maxn];
bool st[maxn];
int top;

int main() {
    while (cin.getline(s, maxn)) {
        if (strcmp(s, ".") == 0) {
            break;
        }
        top = -1;
        bool f = true;
        for (int i = 0; s[i]; ++i) {
            if (s[i] == '[') {
                st[++top] = true;
            } else if (s[i] == ']') {
                if (top == -1 || st[top] != true) {
                    f = false;
                    break;
                }
                --top;
            } else if (s[i] == '(') {
                st[++top] = false;
            } else if (s[i] == ')') {
                if (top == -1 || st[top] != false) {
                    f = false;
                    break;
                }
                --top;
            }
        }
        if (top != -1) {
            f = false;
        }
        puts (f? "yes" : "no");
    }
    return 0;
}

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

int main()
{

	string text;

	getline(cin,text);
	while(text[0] != '.'){
		int ans=1 ,brac[50]={0} ,n=0;
		for(int i=0 ; text[i]!='.' && i<100 ; i++){
			//test	cout<<(int)text[i]<<" ";
			if(text[i]=='('){
				brac[n]=1;
				n++;
			}
			if(text[i]==')'){
				if(n==0) ans=0;
				else if(brac[n-1]!=1) ans=0;
				else{
					n--;
					brac[n]=0;
				}
			}
			if(text[i]=='['){
				brac[n]=2;
				n++;
			}
			if(text[i]==']'){
				if(n==0) ans=0;
				else if(brac[n-1]!=2) ans=0;
				else{
					n--;
					brac[n]=0;
				}
			}
			if(ans==0) break;
		}
		if(ans==0) cout<<"no"<<endl;
		else if(ans==1) cout<<"yes"<<endl;
		getline(cin,text);
	}
}

C++: #include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include <string>
#include <math.h>
#include <queue>
#include <stack>
#define cinf(n,x,y) for(int i=0;i<(n);i++) cin >> x[i] >>y[i];
typedef long long int ll;
using namespace std;

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