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 <string>
#include <stack>
#include <algorithm>

using namespace std;

#define all(c) (c).begin(), (c).end()

bool solve(string& s){
    s.erase(remove_if(all(s), [](char c){return string("()[]").find(c) == string::npos;}), s.end());
    stack<char> st;
    for(auto c: s){
        if(c == '(' || c == '[')st.push(c);
        else if(st.empty() || st.top() != (c == ')'? '(': '['))return false;
        else st.pop();
    }
    return st.empty();
}

int main(){
    for(string s; getline(cin, s) && s != "."; cout << (solve(s)? "yes\n": "no\n"));
    return 0;
}

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

int main(){
  while(1){
    string s;
    int i;
    getline(cin, s);
    int N = s.size();
//    printf("N = %d\n", N);
    if(s[0] == '.' && N == 1){
      return 0;
    }
    stack<char> st;
    int f = 1;
    for(i = 0; i < N; i++){
//      printf("i = %d\n", i);
      if(s[i] == '(' || s[i] == '['){
        st.push(s[i]);
      }
      if(s[i] == ')'){
        if(st.size() == 0 || st.top() != '('){
          printf("no\n");
          f = 0;
          break;
        }
        else{
          st.pop();
        }
      }
      if(s[i] == ']'){
        if(st.size() == 0 || st.top() != '['){
          printf("no\n");
          f = 0;
          break;
        }
        else{
          st.pop();
        }
      }
    }
    if(st.size() == 0 && f == 1){
      printf("yes\n");
    }
    else if(f == 1){
      printf("no\n");
    }
  }
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<functional>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define RREP(i, a, n) for(int i=n-1; i>=a; i--)

int main() {
	string str;
	while (1) {
		getline(cin, str);
		if (str == ".") break;

		stack<char> stk;
		bool flag = true;
		REP(i, 0, str.size()) {
			if (str[i] == '(' || str[i] == '[') stk.push(str[i]);
			else if (str[i] == ')') {
				if (stk.empty()) {
					flag = false;
					break;
				}
				
				char c = stk.top();
				stk.pop();
				if (c != '(') {
					flag = false;
					break;
				}
			}
			else if (str[i] == ']') {
				if (stk.empty()) {
					flag = false;
					break;
				}

				char c = stk.top();
				stk.pop();
				if (c != '[') {
					flag = false;
					break;
				}
			}
		}

		if (flag) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

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

using namespace std;

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

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

using namespace std;
int main(){
	string str;
	while(getline(cin,str)&& str!="."){
		string ss;

		for(int i=0;i<str.size();i++)
			if(str[i]=='(' || str[i]==')' || str[i]=='[' || str[i]==']')
				ss+=str[i];
	
		stack<char> s;
		bool f=true;

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

			if(ss.empty() || ss[i]=='(' || ss[i]=='[')
				s.push(ss[i]);

			else if( (s.top()=='(' && ss[i]==')') || (s.top()=='[' && ss[i]==']') )
					s.pop();
			else{
				f=false;
				break;
			}
		}
		if(f)
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	return 0;
}

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

map<char,char> m;


void check(string str){
	bool status = true;
	stack<char> st;		
	for(int i=0;i<str.size();i++){
		if(
			str[i]=='(' ||
			str[i]=='[' 
		){
			st.push(str[i]);
		} else if(
			str[i]==')' ||
			str[i]==']' 
		){
			if(!st.empty()){
				if(m[st.top()]==str[i]){
					st.pop();
				}
			}else{
				status=false;
			} 
		}else if(str[i]=='.'){
			break;
		}
	}
	if(status && st.empty()) cout<< "yes" << endl;
	else cout<< "no" << endl;
}


int main(){
	m['(']=')';
	m['[']=']';
	string str;
	while(getline(cin,str)){
		if(!str.compare(".")) break;
		check(str);
	}
	return 0;
}

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;
        rep(i,s.size()){
            if(s[i] =='(' || s[i] == '[')
                st.push(s[i]);
            if(s[i]==')'&&st.empty()!=true){
                 if(st.top()=='(') st.pop();
            }else if(s[i]==']' && st.empty()!=true){
                if(st.top()=='[')st.pop();
            }
        }
        if(st.empty()) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}

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

int main(){

	std::string str;
	while (true){
		std::getline(std::cin, str);
		std::stack<char>s;

		if (str == ".")break;

		s.push('?');
		bool flg = true;
		for (int i = 0; i < str.size(); i++){
			if (str[i] == '(' || str[i] == '[')s.push(str[i]);
			if (str[i] == ')' || str[i] == ']'){
				char a = s.top();
				s.pop();
				if (a == '('&&str[i] == ')');
				else if (a == '['&&str[i] == ']');
				else {
					std::cout << "no" << std::endl;
					flg = false;
					break;
				}
			}
		}
		if (flg)std::cout << "yes" << std::endl;
	}
	return 0;
}