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

using namespace std;

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

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
  string str;
  while(getline(cin, str)){
    if(str.length() == 1 && str[0] == '.')break;

    stack<char> st;
    bool ok = true;
    for(int i = 0; i < str.length(); i++){
      if(st.empty()){
        if(str[i] == ']' || str[i] == ')'){
          ok = false;
          break;
        }
      }

      if(str[i] == '[' || str[i] == '('){
        st.push(str[i]);
      }else if(str[i] == ')' || str[i] == ']'){
        if((st.top() == '(' && str[i] == ')') || (st.top() == '[' && str[i] == ']')){
          st.pop();
        }else{
          ok = false;
          break;
        }
      }
    }
    cout << (st.empty() && ok ? "yes" : "no") << endl;
  }
}

C++: #include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
	char buf[102],sta[102],c;
	int len,i,j,p,flg;
	while(1)	{
		fgets(buf,102,stdin);
		if(buf[0]=='.')	break;
		len=0;
		while(buf[len]!='.')	len++;
		
//		printf("len=%d %s\n",len,buf);
		
		p=0;
		flg=1;
		for(i=0;i<len;i++)	{
			if(buf[i]=='(' || buf[i]=='[')	{
				sta[p]=buf[i];
//				printf("i=%d c=%c\n",i,buf[i]);
				p++;
			}
			else if(buf[i]==')')	{
				if(p==0)	{
					flg=0;
					break;
				}
				if(sta[p-1]!='(')	{
					flg=0;
					break;
				}
				else {
					p--;
				}
			}
			else if(buf[i]==']')	{
				if(p==0)	{
					flg=0;
					break;
				}
				if(sta[p-1]!='[')	{
					flg=0;
					break;
				}
				else {
					p--;
				}
			}
		}
		if(p!=0)	{
			flg=0;
		}
		if(flg==1)	{
			printf("yes\n");
		}
		else {
			printf("no\n");
		}
	}
	
	return 0;
}

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

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

C++: #include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main(){
	string s; int i, j;
	while (getline(cin, s)) {
		if (s == ".")break;
		bool f = true;
		int mark[100];
		int len = s.length();
		for (i = 0; i < len; i++) {
			if (s[i] == '(') {
				mark[i] = 1;
			}
			else if (s[i] == '[') {
				mark[i] = 2;
			}
			else if (s[i] == ')') {
				mark[i] = -1;
			}
			else if (s[i] == ']') {
				mark[i] = -2;
			}
			else mark[i] = 0;
		}
		for (i = 0; i < len; i++) {
			if (mark[i] < 0) {
				for (j = i - 1; j >= 0; j--) {
					if (mark[i] + mark[j] == 0) {
						mark[i] = mark[j] = 0; break;
					}
					else if (mark[j] != 0) {
						f = false; break;
					}
				}
				if (j == -1)f = false;
			}
		}
		for (i = 0; i < len; i++) {
			if (mark[i] != 0)f = false;
		}
		if (f)cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

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

using namespace std;

string hantei(string line);

int main(void){
	string line;
	vector<string> result;
	while (getline(cin, line)){
		if (line == "."){
			return 0;
			//break;
		}
		cout << hantei(line) << endl;
		//result.push_back(hantei(line));
	}
	/*
	vector<string>::iterator it = result.begin();
	while( it != result.end()){
	cout << *it << endl;
	++it;
	}
	*/
	return 0;
}

string hantei(string line){
	stack<char> left;
	stack<char> right;

	for (int i=0; i<line.size(); ++i){
		if ((line[i] == '(') || (line[i] == '[')){
			left.push(line[i]);
		}
		if ((line[i] == ')') || (line[i] == ']')){
			right.push(line[i]);
		}
		if (!left.empty()){
			if ((left.top() == '(') && (line[i] == ')')){
				left.pop();
				right.pop();
			}
			else if ((left.top() == '[') && (line[i] == ']')){
				left.pop();	
				right.pop();
			} 
		}
	}
	if (left.empty() && right.empty()){
		return "yes";
	}
	else{
		return "no";
	}
}

C++: //The Balance of the World
#include<bits/stdc++.h>
using namespace std;

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