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>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;

int main(){
    string s;
    while(1){
        getline(cin, s);
        if(s == ".") break;
        stack<char> st;
        bool f = true;
        rep(i, 0, s.size()){
            // cout << s[i] << endl;
            if(s[i] == '(') st.push(s[i]);
            if(s[i] == '[') st.push(s[i]);
            if(s[i] == ')'){
                if(st.empty()){
                    f = false;
                    break;
                }
                char c = st.top(); st.pop();
                if(c != '(') f = false;
            }
            if(s[i] == ']'){
                if(st.empty()){
                    f = false;
                    break;
                }
                char c = st.top(); st.pop();
                if(c != '[') f = false;
            }
        }
        // cout << 1 << endl;
        if(!st.empty()) f = false;
        cout << (f ? "yes" : "no") << endl;
    }
}

C++: #include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

char buf[109];

bool solve(){
	vector<char> st;
	for(int i=0; buf[i]!='.'; i++){
		char c = buf[i];
		if(c == '(' || c == '['){
			st.push_back(c);
		}
		else if(c == ')' || c == ']'){
			if(st.empty()) return false;
			else if(c == ')' && st.back() == '(') st.pop_back();
			else if(c == ']' && st.back() == '[') st.pop_back();
			else return false;
		}
	}
	return st.empty();
}

int main(){
	while(scanf("%[^\n]%*c", buf), strcmp(buf,".")){
		puts(solve()?"yes":"no");
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <string>
#include <climits>

#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define PRINT(STR) cout << (STR) << endl

typedef long long ll;
using namespace std;

int main() {
	char stc[1024];
	int counter = 0;
	string str;
	while (str = "", getline(cin, str), str != ".") {
		counter = 0;
		REP(i, str.size()) {
			if (str[i] == '[' || str[i] == '(') {
				stc[counter++] = str[i];
			} else if (str[i] == ']') {
				if (counter == 0 || stc[--counter] != '[') {
					PRINT("no");
					break;
				}
			} else if (str[i] == ')') {
				if (counter == 0 || stc[--counter] != '(') {
					PRINT("no");
					break;
				}
			}
			if (i == str.size() - 1) {
				PRINT("yes");
			}
		}
	}
	return 0;
}

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

using namespace std;

int main()
{

	while (true){
		char str[128];
		stack<char> s;
		fgets(str, sizeof(str), stdin);

		if (str[0] == '.'){
			break;
		}

		bool flag = true;
		for (int i = 0; str[i] != '.'; i++){
			if (str[i] == '('){
				s.push('(');
			}
			if (str[i] == '['){
				s.push('[');
			}
			if (str[i] == ')'){
				if (s.empty()){
					flag = false;
					break;
				}
				else if (s.top() == '('){
					s.pop();
				}
				else if (s.top() == '['){
					s.pop();
					flag = false;
					break;
				}
			}
			if (str[i] == ']'){
				if (s.empty()){
					flag = false;
					break;
				}
				else if (s.top() == '['){
					s.pop();
				}
				else if (s.top() == '('){
					s.pop();
					flag = false;
					break;
				}
			}
		}

		if (flag){
			puts("Yes");
		}
		else {
			puts("No");
		}
	}

	return (0);
}

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

bool solve(string str) {
  stack<char> stk;
  for (char c : str) {
    if (c == '[') {
      stk.push(c);
    } else if (c == '(') {
      stk.push(c);
    } else if (c == ']') {
      if (stk.empty() or stk.top() != '[') {
        return false;
      }
      stk.pop();
    } else if (c == ')') {
      if (stk.empty() or stk.top() != '(') {
        return false;
      }
      stk.pop();
    }
  }
  return stk.empty();
}

int main() {
  string query;
  while (getline(cin, query) and query != ".") {
    cout << (solve(query) ? "yes" : "no" ) << endl;
  }
}

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

bool solve(){
  stack<char> st;
  for(int i=0;i<(int)str.size();i++){
    if(str[i]=='(')st.push(str[i]);
    else if(str[i]=='[')st.push(str[i]);
    else if(str[i]==')'){
      if(st.empty())return false;
      if(st.top()!='(')return false;
      st.pop();
    }else if(str[i]==']'){
      if(st.empty())return false;
      if(st.top()!='[')return false;
      st.pop();
    }
  }
  return st.empty();
}

int main(){
  while(1){
    getline(cin,str);
    if(str==".")break;
    if(solve())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 s;

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

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

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