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;
struct XY
{
	int x;
	int y;
};
int main ()
{
	string a;
	getline(cin,a);
	while(a!=".")
	{
		bool ok = false;
		stack<int> x;
		for(int i=0;i<a.size();i++)
		{
			if(a[i]=='(')x.push(1);
			if(a[i]==')')
			{
				if(x.empty())
				{
					ok =true;
				}
				else if(x.top()==1)
					x.pop();
				else 
					ok = true;
			}
			if(a[i]=='[')x.push(2);
			if(a[i]==']')
			{
				
				if(x.empty())
				{
					
					ok = true;
				}else 
				if(x.top()==2)
					x.pop();
				else ok = true;
			}
		}
		if(x.empty()&&!ok)cout<<"yes"<<endl;
		else cout<<"no"<<endl;
		getline(cin,a);
	}
}

C++: #include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

bool check(string s){
	string temp;
	bool flg=false;
	int point[4]={0,0,0,0};
	rep(i,s.size()){
		if(s[i]=='(')point[0]++;
		if(s[i]==')')point[1]++;
		if(s[i]=='[')point[2]++;
		if(s[i]==']')point[3]++;
	}
	if(point[0]!=point[1] || point[2]!=point[3])return false;
	rep(i,s.size()){
		if(s[i]=='('){
			flg=true;
			bool hata=true;
			for(int j=s.size()-1;j>=0;j--){
				if(s[j]==')'){
					hata=false;
					if(i<j){
						temp=s.substr(i+1,j-i-1);
						return check(temp);
					}else return false;
				}
			}
			if(hata)return false;
		}
		if(s[i]=='['){
			flg=true;
			bool hata=true;
			for(int j=s.size()-1;j>=0;j--){
				if(s[j]==']'){
					hata=false;
					if(i<j){
						temp=s.substr(i+1,j-i-1);
						return check(temp);
					}else return false;
				}
			}
			if(hata)return false;
		}
		if(s[i]==')'){
			flg=true;
			bool hata=true;
			rep(j,s.size()){
				if(s[j]=='('){
					hata=false;
					if(j<i){
						temp=s.substr(j+1,i-j-1);
						return check(temp);
					}else return false;
				}
			}
			if(hata)return false;
		}
		if(s[i]==']'){
			flg=true;
			bool hata=true;
			rep(j,s.size()){
				if(s[j]=='['){
					hata=false;
					if(j<i){
						temp=s.substr(j+1,i-j-1);
						return check(temp);
					}else return false;
				}
			}
			if(hata)return false;
		}
	}
	if(!flg)return true;
}

int main(){
	string s;
	while(1){
		getline(cin,s);
		if(s==".")break;
		if(check(s)){
			cout<<"yes"<<endl;
		}else cout<<"no"<<endl;
	}
	return 0;
}

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

using namespace std;

stack<char> a; // ()
stack<char> b; // []
string input;

int main() {
	bool yes;
	while(1) {
		while(!a.empty()) a.pop();
		while(!b.empty()) b.pop();
		yes = true;
		getline(cin,input);
		if (input == ".") break;
		for(int i=0; input[i] != '.'; i++) {
			if(input[i]=='(') a.push(input[i]);
			if(input[i]=='[') b.push(input[i]);
			if(input[i]==')'){
				if(a.empty()) yes = false;
				else a.pop();
			}
			if(input[i]==']'){
				if(b.empty()) yes = false;
				else b.pop();
			}
			//cout << input[i] << ":" << yes << endl;
		}
		if (!a.empty() || !b.empty()) yes = false;
		if (yes) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

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

int main(){
  string str;

  while(getline(cin,str) && str!="."){
    string c;
    for(int i=0;i<str.size();i++)
      if(str[i]==')' ||str[i]=='(' ||str[i]=='[' ||str[i]==']')
	c += str[i];

  stack<char> s;
  bool flag=false;
    for(int i=0;i<c.length();i++){
      if(s.empty()&&(c[i]==')'||c[i]==']')){flag=true;break;}
      if(c[i]=='(' || c[i]=='[')s.push(c[i]);
      else if((s.top()=='(' && c[i]==')' )||(s.top()=='[' && c[i]==']'))s.pop();
    }
    cout << (flag==false&&s.empty()?"YES":"NO") << endl;
  }
  
}

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

int main()
{
  string str;
  int i;
  while(true){
    getline(cin, str);
    if(str[0] == '.') break;
    
    int len = 0;
    while(str[len] != '\0'){
      len++;
    }
        
    int d[101] = {0}, j;
    for(i = 0, j = 0 ; i < len ; i++){
      if(str[i] == '('){
	d[++j] = 1;
      }
      if(str[i] == '['){
	d[++j] = 2;
      }
      if(str[i] == ')'){
	if(d[j--]-1){
	  break;
	}
      }
      if(str[i] == ']'){
	if(d[j--]-2){
	  break;
	}
      }
    }
    if(str[i] || j){
      cout << "no" << '\n';
    }else{
      cout << "yes" << '\n';
    }
  }
}

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

using namespace std;

int main()
{
  int no,size;
  string v;
  stack<char> sta;
  string end(".");
  char a5;

  while(1){
    no = 0;
    getline(cin,v);

    if(v == end){
      break;
    }

    for(char e : v){
      if(e == '[' || e == '('){
        sta.push(e);
      }
      else if(e == ']'){
        a5 = sta.top();
        sta.pop();

        if(a5 != '['){
          no = 1;
        }
      }
      else if(e == ')'){
        a5 = sta.top();
        sta.pop();

        if(a5 != '('){
          no = 1;
        }
      }
      if(no == 1){
        break;
      }
    }

    size = sta.size();

    if(size != 0){
      no = 1;
    }

    if(no == 1){
      cout<<"no"<<endl;
    }
    else{
      cout<<"yes"<<endl;
    }
  }

  return 0;
}

C++: #include<bits//stdc++.h>
using namespace std;
int main(){
    string str, t = "()[]";
    while(getline(cin,str) && str != "."){
        stack<char> s;bool judge = 1;
        for(char x : str){
            if(!count(t.begin(), t.end(), x))    continue;
            if(s.empty() || x == '(' || x == '['){
                s.push(x);
            }else if(!s.empty() && (x == ')' && s.top() == '(') || (x == ']' && s.top() == '[')){
                s.pop();
            }else{
                judge = 0;
                break;
            }
        }
        if(s.empty() && judge)  cout << "yes" << endl;
        else cout << "no" << endl;
    }
}

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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for(int i = m; i < (n); ++i)
#define pb push_back

int main()
{
    string str;
    
    while(getline(cin, str) && str != ".")
    {
        int t;
        stack<int> st;
        
        rep(i, str.size()) {
            switch (str[i]) {
                case '(':
                    st.push(1);
                    break;
                case '[':
                    st.push(2);
                    break;
                case ')':
                    if(st.empty()) goto no;
                    t = st.top(); st.pop();
                    if(t != 1) goto no;
                    break; 
                case ']':
                    if(st.empty()) goto no;
                    t = st.top(); st.pop();
                    if(t != 2) goto no;
                    break; 
            }
        }
        cout << "yes" << endl;
        continue;
        
    no:;
        cout << "no" << endl;
    }
}