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 <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <string.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

bool solve(const string S) {
    vector<char> stack;

    for (int i = 0; i < (int) S.size(); i++) {
        char c = S[i];
        if (c == '(') {
            stack.push_back(c);
        } else if (c == ')') {
            if (stack.size() == 0) {
                return false;
            }

            char prev = stack.back();
            stack.pop_back();

            if (prev != '(') {
                return false;
            }
        } else if (c == '[') {
            stack.push_back(c);
        } else if (c == ']') {
            if (stack.size() == 0) {
                return false;
            }

            char prev = stack.back();
            stack.pop_back();

            if (prev != '[') {
                return false;
            }
        }
    }

    if (stack.size() > 0) {
        return false;
    }

    return true;
}

int main(void) {
    while (true) {
        char buf[128];
        fgets(buf, 128, stdin);
        int len = strlen(buf);
        if (buf[len - 1] == '\n') {
            buf[len - 1] = '\0';
            len--;
        }

        string S(buf);
        if (S == ".") {
            break;
        }

        if (solve(S)) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
    return 0;
}

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

using namespace std;

int main(void){
  string str;

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

  stack<char> s;
  bool flag=true;
    for(int i=0;i<ch.length();i++){
      if(s.empty() || ch[i]=='(' || ch[i]=='[')s.push(ch[i]);
      else if((ch[i]==')' && s.top()=='(')||(ch[i]==']' && s.top()=='[')){
	s.pop();
      }else{
	flag=false;
	break;
}

    }
    cout << (flag && s.empty()?"YES":"NO") << endl;
  }
  
  return 0;
}

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

using namespace std;

int main()
{
  int a_figure,b_figure,c_figure,d_figure;
  stack <char> sta;

  string a("(");
  string b(")");
  string c("[");
  string d("]");
  string g;
  a_figure = atoi(a.c_str());
  b_figure = atoi(b.c_str());
  c_figure = atoi(c.c_str());
  d_figure = atoi(d.c_str());

  while(1){
    string v;
    cin>>v;

    if(v == "."){
      break;
    }

    for(char e : v){
      if(e == '(' || e == '['){
        sta.push(e);
      }
      else if(e == ')'){
        char t = sta.top();
        sta.pop();
        if(t != '('){
          g = "no";
          break;
        }
      }
     else if(e == ']'){
        char t = sta.top();
        sta.pop();
        if(t != '['){
          g = "no";
          break;
        }
      }
    }

    if(g == "no"){
    }
    else{
      g = "yes";
    }

    cout<<g<<endl;
  }
  return 0;
}

C++: // Tenbin_1173.cpp
#include <iostream>
#include <string>
using namespace std;
string lol(string str){
	string r;
	int cbcount,sbcount;
	int charcount = 0;
	cbcount = 0;
	sbcount = 0;
	while(true){
		if(str[charcount] == '('){
			cbcount++;
		}else if(str[charcount] == ')'){
			cbcount--;
		}else if(str[charcount] == '['){
			sbcount++;
		}else if(str[charcount] == ']'){
			sbcount--;
		}else if(str[charcount] == '.'){
			break;
		}
		if(cbcount<0||sbcount<0){
			r = "no";
		return r;
	}
		charcount ++;
	}
	if(cbcount==0&&sbcount==0){
		r = "yes";
		return r;
	}
	return "no";
}
int main()
{
	string str;
	while(getline(cin,str)){
		if(str=="."){
			break;
		}else{
		//	cout << endl;
		}
		cout << lol(str)<<endl;
	}
	return 0;
}

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

using namespace std;

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

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

    if(v == end){
      break;
    }

    for(auto 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;
      }
    }

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

  }

  return 0;
}

C++: 
#include<iostream>
#include<stack>
using namespace std;
main(){
int i,f,c;
for(string s;getline(cin,s),s[0]!='.';){
 stack<char> t;
 for(f=i=0;c=s[i++],c!='.';){
  if(c==40|c==91)t.push(c);
  if(c==41|c==93){
   if(!t.empty()&&c-t.top()<3)t.pop();
   else f=1;
  }
 }
 puts(!f&t.empty()?"yes":"no");
}}

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;
	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(!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<stdio.h>
#include<cstdio>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<utility>
#include<queue>
#include<stack>
#define pi 3.14159
#define Inf (int)pow(2., 12.)

using namespace std;
typedef std::pair<int, int> mypair;
queue<mypair> qu;
#define M 1000000

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