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 <stack>
using namespace std;

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

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

using namespace std;

int main() {
	string s;

	while (cin >> s && s[0] != '.') {
		int sa1 = 0;
		int sa2 = 0;
		int i = 0;
		while (s[i] != '\0'&& sa1 >= 0 && sa2 >= 0) {

			if (s[i] == '(')
				sa1++;
			if (s[i] == '[')
				sa2++;
			if (s[i] == ')')
				sa1--;
			if (s[i] == ']')
				sa2--;

		}
		if (sa1 == 0 && sa2 == 0)
			cout << "yes" << endl;
		else
			cout << "no" << endl;

		sa1 = 0;
		sa2 = 0;
		i = 0;

	}

	return 0;
}

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

C++: #include<iostream>
#include<cstdio>
#include<stack>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
int main(){
    map<char,int>M;
    M['(']=M[')']=1;
    M['[']=M[']']=2;
    string str;
    while(getline(cin,str),str!="."){
        bool flag=true;
        stack<int>S;
        for(int i=0;i<str.length();i++){
            char c=str[i];
            if(c=='('||c=='['){
                S.push(M[c]);
            }
            if(c==')'||c==']'){
                if(S.size()==0){
                    flag=false;
                    break;
               }
                if(S.top()!=M[c]){
                    flag=false;
                    break;
                }
                S.pop();
            }
        }
        puts(flag?"yes":"no");
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    while(getline(cin,s),s!="."){
        string c;
        stack<char> w;
        int d=0;
        for(int i=0;i<s.size();i++){
            if(s[i]=='['||s[i]=='(')w.push(s[i]);
            else if(s[i]==']'){
                if(w.top()=='[')w.pop();
                else goto fail;
            }
            else if(s[i]==')'){
                if(w.top()=='(')w.pop();
                else goto fail;
            }
        }
        if(w.empty())cout<<"yes"<<endl;
        else fail:cout<<"no"<<endl;
    }
    return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)

bool solve(const string& s) {
    vector<char> st;
    rep(i, s.size()) {
        if(s[i]=='(' || s[i]=='[') st.push_back(s[i]);
        if(s[i]==')' || s[i]==']') {
            if(st.empty()) return false;
            if(s[i]==')' && st.back()!='(') return false;
            if(s[i]==']' && st.back()!='[') return false;
            st.pop_back();
        }
    }
    return st.empty();
}

int main() {
    for(;;) {
        string s;
        getline(cin, s);
        if(s==".") return 0;
        puts(solve(s) ? "yes" : "no");
    }
}

C++: #include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int MOD=1000000007;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};



int main(){
	string s,t;
	while(1){
		cin>>s;
		if(s==".")break;
		t+=' ';
		t+=s;
		if(s[s.size()-1]!='.'){
			continue;
		}
		int a=0,b=0;
		rep(i,0,t.size()){
			if(t[i]=='(')a++;
			else if(t[i]==')'){
				if(a!=0)a--;
				else a=-1;
			}
			if(t[i]=='[')b++;
			else if(t[i]==']'){
				if(b!=0)b--;
				else b=-1;
			}
			if(a==-1||b==-1)break;
		}
		if((a==0&&b==0)?print("yes"):print("no"));
		t={};
	}
	return 0;
}

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

int main(){
	while(1){
		std::stack<char>Cstr;
		Cstr.push(' ');
		std::string str;
		int count=0;
		std::getline(std::cin,str);
		if(str==".")break;
		for(int i=0;i<str.size();i++){
			if(str[i]=='('||str[i]=='['){
				count++;
				Cstr.push(str[i]);
			}else if(str[i]==')'||str[i]==']'){
				count--;
				if(!((str[i]==')'&&Cstr.top()=='(')||(str[i]==']'&&Cstr.top()=='['))){
					std::cout<<"no"<<std::endl;
					goto end;
				}
				Cstr.pop();
			}
		}
		if(count==0)std::cout<<"yes"<<std::endl;
		else std::cout<<"no"<<std::endl;
		end:;
	}
	return 0;
}

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

using namespace std;

int main() {
	string str;
	while ( getline(cin, str), str != "." ) {
		int k = 0, K = 0;
		stack<int> last;
		bool ans = true;
		for (int i = 0; i < str.size(); ++i) {
			switch (str[i]) {
				case '(':
					++k;
					last.push(0);
					break;

				case ')':
					if (last.empty() || last.top() != 0) {
						ans = false;
					}
					else {
						if (--k < 0) ans = false;
						last.pop();
					}
					break;

				case '[':
					++K; last.push(1);
					break;

				case ']':
					if (last.empty() || last.top() != 1) {
						ans = false;
					}
					else {
						if (--K < 0) ans = false;
						last.pop();
					}
					break;
			}
		}
		if (k != 0 || K != 0) ans = false;
		if (ans) cout << "yes" << endl;
		else cout << "no" << endl;
	}
}

C++: #include<iostream>
#include<stack>
#include<string>
using namespace std;
int main(){
	string n;
	while(getline(cin,n),n!="."){
		stack<char>x;
		bool ans=true;
		for(int i=0;i<n.size();i++){
			char now;
			if(n[i]=='(')x.push(n[i]);
			if(n[i]=='[')x.push(n[i]);
		
			if(n[i]==')'){
				if(x.empty()){
					ans=false;
					break;
				}
			now=x.top();
			x.pop();
			if(now!='(')ans=false;
			}
			if(n[i]==']'){
				if(x.empty()){
					ans=false;
					break;
				}
				now=x.top();
				x.pop();
				if(now!='[')ans=false;
			}
		}
		
	if(x.empty()==false)ans=false;
	if(ans)cout<<"yes"<<endl;
	else cout<<"no"<<endl;
	}
	return 0;
}