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 <math.h>
#include <algorithm>
#include <vector>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main(){
	string sentence;
	bool flag;
	string answer;
	vector<int> kakko; //1: mkakkko 2: kkakkko
	int leng = -1;


	while(1){
		answer = "yes";
		getline(cin,sentence);

		if(sentence == "."){
			break;
		}
		for(int i = 0 ; i < leng+1;i++){
			kakko.pop_back();
		}
		leng = -1;

		for(int i = 0; i < sentence.length();i++){
			if(sentence[i] == '('){
				kakko.push_back(1);
				leng++;
				//cout << " testcase 1 " << endl;
			}else if(sentence[i] == '['){
				kakko.push_back(2);
				leng++;
				//cout << " testcase 2" << endl;
			}else if(sentence[i] == ')'){
				if(leng == -1){
					answer = "no";
					break;
				}else{
					if(kakko[leng] == 1){
						kakko.pop_back();
						leng--;
					}else{
						answer = "no";
						break;
					}
				}
				//cout << " testcase 3" << endl;
			}else if(sentence[i] == ']'){
				if(leng == -1){
					answer = "no";
					break;
				}else{
					if(kakko[leng] == 2){
						kakko.pop_back();
						leng--;
					}else{
						answer = "no";
						break;
					}
				}
				//cout << " testcase 4" << endl;

			}else{}
		}
		if(leng > -1){
			answer = "no";
		}
			
		cout << answer << endl;

	}

}

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

int main() {
  char str[128];
  while (fgets(str, sizeof(str), stdin)) {
    if (str[0] == '.') { break; }
    stack<char> S;
    for (int i = 0; str[i]; ++i) {
      char c = str[i];
      switch (c) {
      case '(': S.push(')'); break;
      case '[': S.push(']'); break;
      case ')': case ']':
        if (S.empty() || S.top() != c) { goto bad; }
        S.pop();
      }
    }
    if (!S.empty()) { goto bad; }
    puts("yes");
    continue;
bad:
    puts("no");
  }
}

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

using namespace std;

int main(){

	string str;

	while(1){
		getline(cin,str);
stack<int> data;
		if(str.at(0)=='.')break;

		int flag=0;
	
	for(int i=0;i<str.size();i++){

		if(str.at(i) =='('){
			data.push(1);
		}

		if(str.at(i) == '['){
			data.push(2);
		}

		if(str.at(i) ==')'){
			if(data.size()==0){
				cout<<"no"<<endl;
				flag=1;
			}
			else if(data.top() != 1){
				cout<<"no"<<endl;
				flag=1;
			}
			else{
				data.pop();
			}
		}
		if(str.at(i) == ']'){
			if(data.size()==0){
				cout<<"no"<<endl;
				flag=1;
			}
			else if(data.top() != 2){
				cout<<"no"<<endl;
				flag=1;
			}
			else{
				data.pop();
			}
		}

		if(flag==1)break;
	}

	if(flag==1)continue;

	cout<<"yes"<<endl;
	}

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)


int main() {
	string s;
	while (getline(cin, s), (s != ".")) {
		stack<char> st;
        st.push('a');
		bool ok = true;
		for (char c : s) {
			if (c == '(' || c == '{'){ st.push(c); }
			if (c == ')'){ if(st.top() == '(') st.pop(); else ok = false; }
			if (c == '}'){ if(st.top() == '{') st.pop(); else ok = false; }
		}
		cout << (ok && st.size() == 1 ? "yes" : "no") << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<utility>
#include<set>
#include<stack>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX  999999
int main(){
    string s;
    while(getline(cin,s)){
        if(s.size()==1&&s[0]=='.') break;
        stack<char>st;
        bool check=true;
        rep(i,s.size()){
            if(s[i] =='(' || s[i] == '[')
                st.push(s[i]);
            else if(s[i]==')'){
                if(st.empty()) check=false;
                else if(st.top()=='(') st.pop();
            }else if(s[i]==']'){
                if(st.empty())check=false;
                else if(st.top()=='[')st.pop();
            }
            if(!check) break;
        }
        if(st.empty() &&check) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    string s;
    while(getline(cin,s),s!="."){
        stack<int> st;
        bool ans=true;
        int n=s.size();
        --n;
        int c1=0,c2=0;
        rep(i,n){
            if(s[i]=='('){
                ++c1;
                st.push(0);
            }
            else if(s[i]=='['){
                ++c2;
                st.push(1);
            }
            else if(s[i]==')'){
                --c1;
                if(c1<0||st.top()==1) ans=false;
                st.pop();
            }
            else if(s[i]==']'){
                --c2;
                if(c2<0||st.top()==0) ans=false;
                st.pop();
            }
            if(!ans) break;
        }
        if(ans&&c1==0&&c2==0) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}

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

int main(){
  string s;
  while(1){
    getline(cin,s);
    if(s.size()==1&&s[0]=='.')break;
    string tmp;
    bool ok=true;
    for(int i=0;i<s.size();i++){
      if(s[i]=='(')tmp.push_back('(');
      if(s[i]=='[')tmp.push_back('[');

      if(s[i]==')'&&tmp[tmp.size()-1]=='('&&tmp.size()!=0){
	tmp.pop_back();
      }else if(s[i]==')'&&tmp[tmp.size()-1]=='['){
	ok=false;
	break;
      }

      if(s[i]==']'&&tmp[tmp.size()-1]=='['&&tmp.size()!=0){
	tmp.pop_back();
      }else if(s[i]==']'&&tmp[tmp.size()-1]=='('){
	ok=false;
	break;
      }
    }
    if(ok&&tmp.size()==0)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    
  }
  return 0;
}