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 <string>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define EPS 1e-14

#define all(v) v.begin(),v.end()
// #define INF
// #define mp
// #define pb

// #define fi
// #define se

// #define each

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef long long ll;

int main(){
	while(1){
		stack <char> st;
		string s = "";
		char q;
		q = getchar();
		//cout<<q<<endl;
		if(q=='\n'){
			q = getchar();
			if(q=='.'){
				return 0;
			}
		}
		
		s += q;

		while(1){
			string c;
			cin>>c;
			if(c[c.size()-1]!='.') s+= (' '+c);
			else{
				s += (' '+c);
				break;
			}
		}
		//cout<<s<<endl;
		if(s[0]=='.'&& s.size()==1) break;
		rep(i,s.size()){
			switch(s[i]){
				case '[': st.push('[');
				break;
				case '(': st.push('(');
				break;
				case ']': 
					if(st.empty()){
						cout << "no" << endl;
						goto END;
					}
					if(st.top()!='['){
						cout << "no" << endl;
						goto END;
					}else{
						st.pop();
					}
				break;
				case ')':
					if(st.empty()){
						cout << "no" << endl;
						goto END;
					}
					if(st.top()!='('){
					cout << "no" << endl;
					goto END;
					}else{
						st.pop();
					}
				break;
			}
		}
		if(!st.empty()) cout <<"no"<<endl;
		else cout << "yes"<<endl;
		END:;
	}
	return 0;
}

C++: #include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
using namespace std;
int main(void){
    string ken="()[]";
    while(1){
        bool frg=true;
        string in,nate="";
        getline(cin,in);
        if(in==".")break;
        for(int s=0;s<in.length();s++){
            if(in[s]==ken[0]||in[s]==ken[2]){
                nate+=in[s];
            }
            if(in[s]==ken[1]){
                if(nate[nate.length()-1]==ken[0]){
                    string work=nate;
                    nate="";
                    for(int i=0;i<work.length()-1;i++){
                        nate+=work[i];
                    }
                }else{
                    frg=false;
                    break;
                }
            }
            if(in[s]==ken[3]){
                if(nate[nate.length()-1]==ken[2]){
                    string work=nate;
                    nate="";
                    for(int i=0;i<work.length()-1;i++){
                        nate+=work[i];
                    }
                }else{
                    frg=false;
                    break;
                }
            }
        }
        if(frg&&nate=="")cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
 while(1){
  int a[2]={},f=0,m[51]={},n[51]={},x=0,y=0;
  string s;
  getline(cin,s);
  if(s[0]=='.')break;
  
  for(int i=0;i<s.size();i++){
   if(s[i]=='.')break;
   if(s[i]=='['){
    a[0]++;
    x++;
    m[x]=i;
   }
   else if(s[i]==']'){
    if(n[y]>m[x]){f=1;break;}
    if(a[0]==0) {f=1;break;}
    a[0]--;
    x--;
   }
   else if(s[i]=='('){
    a[1]++;
    y++;
    n[y]=i;
   }
   else if(s[i]==')'){
    if(n[y]<m[x]){f=1;break;}
    if(a[1]==0){f=1;break;}
    a[1]--;
    y--;    
   }
  }
  if(f==1 || x!=0 || y!=0)cout<<"no"<<endl;
  else cout<<"yes"<<endl;
 }
 return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <cstdio>
#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
using namespace std;
int main()
{
	while (1)
	{
		int id = 0;
		stack<int> stck;
		string str; getline(cin, str);
		if (str[0] == '.'  && str.size() == 1) { break; }
		rep(i, (int)str.size() + 1)
		{
			switch (str[i])
			{
			case '(':	stck.push(1);	break;
			case '[': stck.push(2); break;
			case ')': 
				if (stck.size() == 0) { id = 1; }
				else if (stck.top() == 1) { stck.pop(); }
				else { id = 1; } break;
			case ']': 
				if (stck.size() == 0) { id = 1; }
				else if (stck.top() == 2) { stck.pop(); }
				else { id = 1; } break;
			}
		}
		if (id == 1) { printf("no\n"); }
		else { printf("yes\n"); }
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;

string s;
bool check() {
	stack<char>S;
	for (string::iterator it = s.begin(); it != s.end(); it++) {
		switch (*it) {
		case '(':S.push(*it); break;
		case ')':if (S.empty() || S.top() != '(')return false; S.pop(); break;
		case '[':S.push(*it); break;
		case ']':if (S.empty() || S.top() != '[')return false; S.pop(); break;
		}
	}
	return S.empty();
}

int main() {
	while (getline(cin, s), s != ".") cout << (check() ? "yes" : "no") << endl;
return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void load(vector<string>& datas){
    while(1){
        string str;
        while(1){
            char word;
            if(!cin){
                datas.pop_back();
                datas.pop_back();
                return;
            }
            cin >> word;
            str += word;
            if(word == '.') break;
        }
        datas.push_back(str);
    }
}



int main()
{
    vector<string> datas;
    
    load(datas);
    
    for(auto data: datas){
        vector<bool> brackets;
        
        for(auto itr = data.begin(); itr != data.end(); itr++){
            if(*itr == '[') brackets.push_back(true);
            else if(*itr == '(') brackets.push_back(false);
            else if(*itr == ']' && brackets.size()) {
                if(brackets.back() == true) 
                    brackets.pop_back();
            }
            else if(*itr == ')' && brackets.size()) {
                if(brackets.back() == false) 
                    brackets.pop_back();
            }
        }
        if(brackets.size()) cout << "no" << endl;
        else cout << "yes" << endl;
    }
    
    return 0;
}

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

void solve(string s) {
    stack<char> S;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] != '(' && s[i] != ')' && s[i] != '[' && s[i] != ']') continue;
        if (S.empty()) S.push(s[i]);
        else {
            if (S.top() == '(' && s[i] == ')') S.pop();
            else if (S.top() == '[' && s[i] == ']') S.pop();
            else S.push(s[i]);
        }
    }
    if (S.empty()) cout << "yes" << endl;
    else cout << "no" << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    while (true) {
        getline(cin, S);
        if (S == ".") break;
        solve(S);
    }
    return 0;
}