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 <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    string s;
    while(getline(cin, s)) {
        if(s == ".") break;
        bool ok = true;
        stack<char> st;
        rep(i,0,s.length()) {
            if(s[i] == '(') st.push('(');
            else if(s[i] == '[') st.push('[');
            else if(s[i] == ')') {
                // printf("1: top = %c\n", st.top());
                if(!st.empty() && st.top() == '(') st.pop();
                else ok = false;
            }
            else if(s[i] == ']') {
                // printf("2: top = %c\n", st.top());
                if(!st.empty() && st.top() == '[') st.pop();
                else ok = false;
            }
        }
        if(!ok || !st.empty()) cout << "no" << endl;
        else cout << "yes" << endl;
    }
    return 0;
}

C++: #include <stdio.h>
#include <string.h>

#define MAX (1000)

int main(void)
{
	int sp;
	char stack[MAX];
	char str[MAX + 1];
	while (1){
		int i;

		fgets(str, MAX, stdin);
		if (str[0] == '.'){
			break;
		}

		if (str[strlen(str) - 1] == '\n'){
			str[strlen(str) - 1] = '\0';
		}

		sp = 0;
		for (i = 0; str[i] != '\0'; i++){
			if (str[i] == '[' || str[i] == '('){
				stack[sp++] = str[i];
			}
			else if (str[i] == ')' || str[i] == ']'){
				if (sp == 0){
					break;
				}
				char top = stack[--sp];
				if (top == '['){
					top = ']';
				}
				else {
					top = ')';
				}
				if (top != str[i]){
					break;
				}
			}
		}
	
		
		if (i != 0 && str[i] == '\0' && str[i - 1] == '.' && sp == 0){
			puts("yes");
		}
		else {
			puts("no");
		}
	}

	return (0);
}

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

using namespace std;

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

C++: #include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n,m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

int main()
{
NEXT:
	while (1) {
		getline(cin, s);
		if (s.size() == 1 && s[0] == '.') {
			return 0;
		} else {
			stack<char> v;
			REP(i, s.size())
			{
				if (s[i] == '(') {
					v.push(s[i]);
				}

				if (s[i] == ')') {
					if (v.empty() || v.top() != '(') {
						cout << "no" << endl;
						while (!v.empty()) {
							v.pop();
						}
						goto NEXT;
					} else {
						v.pop();
					}
				}

				if (s[i] == '[') {
					v.push(s[i]);
				}

				if (s[i] == ']') {
					if (v.empty() || v.top() != '[') {
						cout << "no" << endl;
						while (!v.empty()) {
							v.pop();
						}
						goto NEXT;
					} else {
						v.pop();
					}
				}
			}

			if (v.empty()) {
				cout << "yes" << endl;
			} else {
				cout << "no" << endl;
			}

			while (!v.empty()) {
				v.pop();
			}
		}
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <cstdio>
#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
using namespace std;
int main()
{
	while (1)
	{
		int id = 0;
		stack<int> stck;
		string str; getline(cin, str);
		if (str[0] == '.'  && str.size() == 1) { break; }
		rep(i, (int)str.size())
		{
			switch (str[i])
			{
			case '(':	stck.push(1);	break;
			case '[': stck.push(2); break;
			case ')': 
				if (stck.size() == 0) { id = 1; }
				else if (stck.top() == 1) { stck.pop(); }
				else { id = 1; } break;
			case ']': 
				if (stck.size() == 0) { id = 1; }
				else if (stck.top() == 2) { stck.pop(); }
				else { id = 1; } break;
			}
		}
		if (id == 1) { printf("no\n"); }
		else { printf("yes\n"); }
	}
	return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <iomanip>
#include <cassert>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true){
        string s;
        getline(cin, s);
        if(s.size() == 1 && s[0] == '.') break;
        int len = s.size();
        int rb = 0, sb = 0;
        bool ok = true;
        stack<char> left_br;
        for(int i = 0; i < len; i++){
            if(s[i] == '('){
                left_br.push('(');
            }else if(s[i] == ')'){
                if(left_br.empty() || left_br.top() != '('){
                    ok = false;
                    break;
                }
                left_br.pop();
            }else if(s[i] == '['){
                left_br.push('[');
            }else if(s[i] == ']'){
                if(left_br.empty() || left_br.top() != '['){
                    ok = false;
                    break;
                }
                left_br.pop();
            }
        }
        if(ok){
            puts("yes");
        }else{
            puts("no");
        }
    }
    return 0;
}