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>
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()
{
	while (1) {
		getline(cin, s);
		if (s[0] == '.') {
			return 0;
		} else {
			bool flag = 0;
			stack<char> v;
			REP(i, s.size())
			{
				if (s[i] == '(') {
					v.push(s[i]);
				}
				if (s[i] == ')') {
					if (v.size() != 0 && v.top() == '(') {
						v.pop();
					} else {
						cout << "no" << endl;
						flag = 1;
					}
				}
				if (s[i] == '[') {
					v.push(s[i]);
				}
				if (s[i] == ']') {
					if (v.size() != 0 && v.top() == '[') {
						v.pop();
					} else {
						cout << "no" << endl;
						flag = 1;
					}
				}
			}
			if (flag == 0) {
				if (v.size() == 0) {
					cout << "yes" << endl;
				} else {
					cout << "no" << endl;
				}
			}
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;


int main(){

  while(1){
    string s;
    getline(cin,s);
    //    cout << s << endl;
    if(s == ".") break;
    stack<string> st;
    bool ok = true;
    for(int i=0; i<s.size(); i++){
      string si = s.substr(i,1);
    
      if(si == "(" or si == "["){
	st.push( s.substr(i,1) );
	continue;
      }
      else if(si == ")"){
	if(st.size() > 0 and st.top() == "("){
	  st.pop();
	  continue;
	}
	else{
	  ok = false;
	}
      }
      else if(si == "]"){
	if(st.size() > 0 and st.top() == "["){
	  st.pop();
	  continue;
	}
	else{
	  ok = false;
	}
      }
    }
    if(ok)
      cout << "yes" << endl;
    else
      cout << "no" << endl;
    
  }
}

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


int main(){
	while(1){
		string str;
		getline(cin,str);
		if(str==".") break;

		int i=0;
		int sum = 0;
		vector<int> inkakko;
		while(1){
			if(str[i]=='('){
				inkakko.push_back(1);
				sum++;
			}else if(str[i]==')'){
				if(inkakko.size()){
					if(inkakko[inkakko.size()-1]==1){
						inkakko.pop_back();
						sum--;
					}else{
						cout << "no" << endl;
						break;
					}
				}else{
					cout << "no" << endl;
					break;
				}
			}else if(str[i]=='['){
				inkakko.push_back(2);
				sum++;
			}else if(str[i]==']'){
				if(inkakko.size()){
					if(inkakko[inkakko.size()-1]==2){
						inkakko.pop_back();
						sum--;
					}else{
						cout << "no" << endl;
						break;
					}
				}else{
					cout << "no" << endl;
					break;
				}
			}else if(str[i]=='.'){
				if(inkakko.size()){
					cout << "no" << endl;
				}else{
					cout << "yes" << endl;
				}
				break;
			}
			i++;
		}
	}
}

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

int main() {
  string s;
  while(getline(cin, s)) {
    if(s[0] == '.') break;

    bool b = true;
    stack<char> sta;
    for(int i = 0; i < s.size(); i++) {
      char c = s[i];
      if(c == ')' || c == ']') {
	if(sta.empty()) {
	  b = false;
	  break;
	}
	if(c == ')' && sta.top() != '(') b = false;
	if(c == ']' && sta.top() != '[') b = false;
	sta.pop();
      }
      else if(c == '(' || c == '[') {
	sta.push(c);
      }      
    }
    if(b) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

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

int N;

bool balance(string s, int b, int e)
{
  N = 1;
  for(int i = b; i < e; i++){
    if(s.at(i) == '('){
      for(int j = i + 1; j < e; j++){
	if(s.at(j) == ')'){
	  string sub = s.substr(i + 1, j - i - 1);
	  cout << sub << endl;
	  if(balance(sub, 0, sub.size())){
	    N = 0;
	    continue;
	  }
	}
      }
      if(N)
	return false;
      else
	return true;
    }else if(s.at(i) == '['){
      for(int j = i + 1; j < e; j++){
	if(s.at(j) == ']'){
	  string sub = s.substr(i + 1, j - i - 1);
	  cout << sub << endl;
      	  if(balance(sub, 0, sub.size())){
	    N = 0;
	    continue;
	  }
	}
      }
      if(N)
	return false;
      else
	return true;
    }
  }
  return true;
}
       
int main()
{
  string s;
  while(getline(cin, s)){
    if(balance(s, 0, s.size()))
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

const int mx = 300000;
int prime[mx], ps[mx];

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    string ln;
    while (true) {
        getline(cin, ln);
        if (ln == ".") break;

        bool bd = false;
        stack<char> s;
        for (char c : ln) {
            switch(c) {
                case '(':
                case '[':
                    s.push(c);
                    break;
                case ')':
                    if (s.size() && s.top() == '(') s.pop();
                    else bd = true;
                    break;
                case ']':
                    if (s.size() && s.top() == '[') s.pop();
                    else bd = true;
                    break;
            }
        }
        if (s.size()) bd = true;
        cout << (!bd ? "yes" : "no") << endl;
    }
}