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 <cstdio>
#include <cstring>
#include <stack>
using namespace std;
int main(){
  string str;
  string tmp;
  while(getline(cin, str) && str != "."){
    int p = 0, q = 0;
    bool flag = 1;
    tmp = "";
    
    for(int i = 0 ; i < str.size() ; i++){
      if(str[i] == '[' || str[i] == '(' || str[i] == ']' || str[i] == ')'){
	tmp += str[i];
      }
    }
    
    for(int i = 0 ; i < tmp.size() ; i++){
      if(tmp[i] == '(' && tmp[i+1] == ']') flag = 0;
      if(tmp[i] == '[' && tmp[i+1] == ')') flag = 0;
    }
    
    /*for(int i = 0 ; i < tmp.size() ; i++){
      if(p < 0 || q < 0){
	flag = 0;
	break;
      }
      if(tmp[i] == '(') p++;
      if(tmp[i] == '[') q++;
      if(tmp[i] == ')') p--;
      if(tmp[i] == ']') q--;
    }
    if(p != 0 || q != 0) flag = 0;*/
    
    
    stack<char> st;
    
    for(int i = 0 ; i < tmp.size() ; i++){
      if(tmp[i] == '(' || tmp[i] == '[') st.push(tmp[i]);
      else if(tmp[i] == ')'){
	if(st.empty() || st.top() != '('){ flag = 0; break;}
	else st.pop();
      }
      else if(tmp[i] == ']'){
	if(st.empty() || st.top() != '['){ flag = 0; break;}
	else st.pop();
      }
      }
    
    //cout << tmp << endl;
    //printf("p = %d, q = %d\n", p, q);*/
    if(flag) cout << "yes" << endl;
    else cout << "no" << endl;    
  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

//#define int long long

/*************** using variables ***************/
string s;
/**********************************************/

signed main(){
    while(getline(cin, s), s != "."){
        stack<char> st;
        auto itr = s.begin();
        bool flag = true;
        while(*itr != '.'){
            if(*itr == '['  || *itr == '(') st.push(*itr);
            if(*itr == ']'){
                if(st.top() != '['){
                    flag = false;
                    break;
                }else{
                    st.pop();
                }
            }
            if(*itr == ')'){
                if(st.top() != '('){
                    flag = false;
                    break;
                }else{
                    st.pop();
                }
            }
            ++itr;
        }
        cout << (flag ? "yes":"no") << endl;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  string s;
  while(getline(cin,s), s!=".") {
    stack<char> stk;
    bool f = 1;
    REP(i,s.size()) {
      if (s[i]=='[' || s[i]=='(')
        stk.push(s[i]);
      if (s[i]==']') {
        if (stk.empty() || stk.top() != '[') {
          f = 0;
          break;
        } else
          stk.pop();
      } else if (s[i]==')') {
        if (stk.empty() || stk.top() != '(') {
          f = 0;
          break;
        } else
          stk.pop();
      }
    }
    if (f)
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  }
}

C++: #include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

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

C++: #include<iostream>
#include<string>
using namespace std;
int main(void) {
	string ch;
	char a[101] = {};
	getline(cin, ch);
	while (ch[0] != '.') {
		int i,j=0;
		for (i = 0; ch[i] != '.'; i++) {
			if (ch[i] == '(' || ch[i] == '[') {
				a[j] == ch[i];
				j++;
			}
			else if (ch[i] == ')' || ch[i] == ']') {
				j--;
				if (a[j] != ch[i]) {
					cout << "no" << endl;
					break;
				}
			}
		}
		if (j == 0) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
		getline(cin, ch);
	}
	return 0;
}

C++: #include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

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