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 <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void solve(string s) {
    int st = 0, ed = s.size() - 2;
    while (true) {
        if (st == ed) {
            cout << "yes" << endl;
            return;
        }
        if (s[st] == '(') {
            while (true) {
                if (s[ed] == ')') break;
                ed--;
                if (st >= ed) {
                    cout << "no" << endl;
                    return;
                }
            }
        } else if (s[st] == '[') {
            while (true) {
                if (s[ed] == ']') break;
                ed--;
                if (st >= ed) {
                    cout << "no" << endl;
                    return;
                }
            }
        }
        st++;
    }
    return;
}

signed main(void) {
    int n, p, m, w, h;
    string s;
    int a, b, c, d;
    while (getline(cin, s)) {
        if (s == ".") return 0;
        solve(s);
        //return 0;
    }
}

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

int main(){
  stack<int> p;
  string str;
  bool a;
  while(1){
    getline(cin,str);
    a = true;
    if(str == ".") return 0;
    for(int i=0;i<str.length();i++){
      char ch = str[i];
      if(ch == '(') p.push(1);
      if(ch == '[') p.push(2);
      if(ch == ')'){
        if(p.empty()){
          a = false;
          break;
        }
        if(p.top() == 1){
          p.pop();
        } else{
          a = false;
          break;
        }
      }
      if(ch == ']'){
        if(p.empty()){
          a = false;
          break;
        }
        if(p.top() == 2){
          p.pop();
        }else{
          a = false;
          break;
        }
      }
    }
    cout << (a?"yes":"no");
    while(!p.empty()){
      p.pop();
    }
    cout << endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
const int INF = 1<<28;

string input;

int find(int a, int p) {
	int btn[2] = {};
	FOR(i, p, input.size()) {
		if(a) {
			if(input[i] == '[')
				btn[0]++;
			if(input[i] == ']')
				btn[0]--;
			if(input[i] == '(')
				btn[1]++;
			if(input[i] == ')') {
				btn[1]--;
				if(!btn[0] && !btn[1])
					return 0;
			}
		}
		else {
			if(input[i] == '(')
				btn[0]++;
			if(input[i] == ')')
				btn[0]--;
			if(input[i] == '[')
				btn[1]++;
			if(input[i] == ']') {
				btn[1]--;
				if(!btn[0] && !btn[1])
					return 0;
			}
		}
	}
	return 1;
}


int main() {
	while(getline(cin, input)) {
		if(input == ".") break;
		int cnt = 0;
		int chk[2] = {};
		REP(i, input.size()) {
			if(input[i] == '(') {
				cnt += find(1, i);
				chk[1]++;
			}
			if(input[i] == '[') {
				cnt += find(0, i);
				chk[0]++;
			}
			if(input[i] == ')') {
				chk[1]--;
				if(chk[1] < 0) cnt++;
			}
			if(input[i] == ']') {
				chk[0]--;
				if(chk[0] < 0) cnt++;
			}
		}
		if(chk[0] || chk[1]) cnt++;
		cout << (cnt ? "no" : "yes") << endl;
	}
	return 0;
}

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

int main(){
    while(true){
        bool ju = true;
        string s;
        stack <char> box;
        getline(cin,s); if(s == ".") break;
        for(int i=0;i<s.size();i++){
            if(s[i] == '(' || s[i] == '[') box.push(s[i]);
            else if(s[i] == ')'){
                if(box.empty() || box.top()!= '(') ju = false;
                else box.pop();
            }
            else if(s[i] == ']'){
                if(box.empty() || box.top()!= '[') ju = false;
                else box.pop();
            }
            if(!ju) break;
        }
        cout << ((ju&&box.empty())? "yes" : "no") << endl;
    }
}

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

stack<bool> s;
char c[128];

int main(){
	char *p;
	bool f;
	while (gets(c), c[0] != '.') {
		s = stack<bool>();
		p = &c[0];
		f = false;
		while (*p != '.') {
			switch (*p)
			{
			case'(':
				s.push(true); break;
			case'[':
				s.push(false); break;
			case')':
				if (!s.empty() && s.top()) {
					s.pop();  break;
				}
				f = true;
				break;
			case']':
				if (!s.empty() && !s.top()) {
					s.pop(); break;
				}
				f = true;
				break;
			default:
				break;
			}
			if (f) {
				break;
			}
			p++;
		}
		if (f || !s.empty()) {
			printf("no\n");
		}
		else {
			printf("yes\n");
		}
	}

	return 0;
}