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 <stdio.h>
#include <string.h>
int kakko(char *c,char tmp,int count){
	int flag = 0;
	char wtmp;
	*c = getchar();
	count++;
	if(tmp == ')')
		wtmp = ']';
	else
		wtmp = ')';
	while(*c != '.' && *c != tmp && *c != wtmp){
		if(*c == '(' || *c == '['){
			if(*c == '(')
				tmp = ')';
			else
				tmp = ']';
			flag = kakko(c,tmp,count);
		}
		if(*c != '.' && *c != tmp && *c != wtmp){
			*c = getchar();
			count++;
		}
	}
	if(*c == '.' || *c == wtmp)
		flag = 1;
	return flag;
}

int main(void){
	int count = 0, flag = 0;
	char c, tmp;
	c = getchar();
	while(c != '.' || count != 0){
		if(c == '(' || c == '['){
			if(c == '(')
				tmp = ')';
			else
				tmp = ']';
			flag = kakko(&c,tmp,count);
		}
		if(c == '.'){
			if(flag == 0)
				printf("yes\n");
			else
				printf("no\n");
			flag = 0;
			count = 0;
			getchar(); //改行読取ばs
			c = getchar();
		}
		else{
			c = getchar();
			count++;
		}
	}
	return 0;
}

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

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

C++: #include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<queue>
#include<stack>
#define N (1000000000+7)
typedef long long ll;
using namespace std;

int main(void){
    string s;
    stack<char>p,emptyp;
    while(true){
        getline(cin,s);
        if(s==".")break;
        while(!p.empty())p.pop();
        bool flag=true;
        //if(p.empty())cout<<"progin"<<" ";
        string t;
        for(int i=0;i<s.length();i++)if((s[i]=='(')||(s[i]==')')||(s[i]=='[')||(s[i]==']'))t+=s[i];
        for(int i=0;i<t.length();i++){
            if((t[i]=='(')||(t[i]=='[')){
                p.push(t[i]);
            }
            else{
                 if(t[i]==')'){
                    if(p.empty()){
                        cout<<"no"<<endl;
                        flag=false;
                        break;
                    }
                    else{
                        char a=p.top();
                        p.pop();
                        if(a=='['){
                            cout<<"no"<<endl;
                            flag=false;
                            break;
                        }
                    }
                }
                else if(t[i]==']'){
                    if(p.empty()){
                        cout<<"no"<<endl;
                        flag=false;
                        break;
                    }
                    else{
                        char a=p.top();
                        p.pop();
                        if(a=='('){
                            cout<<"no"<<endl;
                            flag=false;
                            break;
                        }
                    }
                }
            }
        }
        if(flag){
            if(p.empty())cout<<"yes"<<endl;
            else cout<<"no"<<endl;
        }
    }
    return 0;
}

C++: #include<iostream>
#include<stack>
#include<string>
using namespace std;
int main()
{
  string s;
  char i,f;
  while(getline(cin,s),s[0]!='.'){
    stack<char> st;
    for(f=i=0;i<s.size();i++){
      if(s[i]=='('||s[i]=='['){
	st.push(s[i]);
      }else if(s[i]==')'||s[i]==']'){
	if(st.size()&&(st.top()+1==s[i]||st.top()+2==s[i]))st.pop();
	else f=1;
      }
    }
    puts(f&&st.size()?"no":"yes");
  }
}

C++: #include<iostream>
#include<stack>
#include<string>
using namespace std;
int main()
{
	while (true)
	{
		string str = "";
		while (true)
		{
			char ch = cin.get();
			if (ch == '\n')
				continue;
			if (ch == '.')
				break;
			str.push_back(ch);
		}
		if (str.empty())
			break;
		stack<char> S;
		bool flag = true;
		for (int i = 0; i < str.length(); i++)
		{
			if (str[i] == '(' || str[i] == '[')
				S.push(str[i]);
			else if (str[i] == ')')
				if (S.empty() || S.top() != '(')
					flag = false;
				else
					S.pop();
			else if (str[i] == ']')
				if (S.empty() || S.top() != '[')
					flag = false;
				else
					S.pop();
		}
		if (!S.empty())
			flag = false;
		cout << (flag ? "yes" : "no") << endl;
	}
}

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

int main()
{
  string str;

  while (getline(cin,str))
  {
    if (str == ".") return 0;

    stack<char> p;
    bool flag = true;

    for (int i=0;i<str.length();i++)
    {
      if (str[i] == '(') p.push('(');
      else if (str[i] == ')')
      {
        if (!p.empty() && (p.top() != '(')) { flag = false; break; }
        if (p.empty()) { flag = false; break; }
        p.pop();
      }
      else if (str[i] == '[')  p.push('[');
      else if (str[i] == ']')
      {
        if (!p.empty() && (p.top() != '[')) { flag = false; break; }
        if (p.empty()) { flag = false; break; }
        p.pop();
      }
    }
    if (flag && p.empty()) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

C++: // AOJ 1173 The Balance of the world
#include <iostream>
#include <string>
#include <stack>
using namespace std;

int main(){
	bool f;
	string s;
	while(getline(cin, s)){
		if(s == ".") break;
		stack<char> st;
		f = true;
		string::const_iterator it = s.begin();
		for(;it != s.end();++it){
			if(*it == '(' || *it == '['){
				st.push(*it);
			}
			else if(*it == ')'){
				if(st.size() && st.top() == '('){
					st.pop();
				}
				else{
					f = false;
					break;
				}
			}
			else if(*it == ']'){
				if(st.size() && st.top() == '['){
					st.pop();
				}
				else{
					f = false;
					break;
				}
			}
		}
		if(f){
			cout << "yes" << endl;
		}
		else{
			cout << "no" << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	char d[4]={'[',']','(',')'};
	string s;
	while(getline(cin,s),s!="."){
		rep(i,s.size()){
			bool h=false;
			rep(j,4)if(s[i]==d[j])h=true;
			if(!h){
				s.erase(s.begin()+i);
				i--;
			}
		}
		while(1){
			int it;
			if((it=s.find("[]"))!=string::npos)s.erase(it,2);
			else if((it=s.find("()"))!=string::npos)s.erase(it,2);
			else break;
		}
		if(s=="")cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
}