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 <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define PR pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;

//#define int ll

// the balance of the world

signed main(){
  while(1){
    stack<char> s;
    string str;
    getline(cin, str);
    if(str==".") break;
    
    bool ans=1;
    for(int i=0; i<str.size(); i++){
      if(str[i]=='('||str[i]=='['){
        s.push(str[i]);
      }else if(str[i]==')'||str[i]==']'){
        if(s.empty()) ans=0;
        else if(str[i]==']'&&s.top()=='['){
          s.pop();
        }else if(str[i]==')'&&s.top()=='('){
          s.pop();
        }else{
          ans=0;
        }
      }else if(str[i]=='.'){
        if(ans) cout<<"yes"<<en
        else cout<<"no"<<en
          break;
      }
    }
  }
  RE
}

C++: /*
 * balance_of_world.cpp
 *
 *  Created on: 2017/02/11
 *      Author: Nishio
 */
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;

int main(){
	 while(1) {
	    string c;
	    getline(cin, c);
	    if(c.size()==1 && c[0]=='.') break;
		stack<char> st;
		for(int i=0;c[i]!='.';i++){
			if((c[i]==')'||c[i]==']')&&st.empty())  st.push('?');
			if(c[i]=='('||c[i]=='[')		st.push(c[i]);
			else if(c[i]==')'&&st.top()=='(')	st.pop();
			else if(c[i]==']'&&st.top()=='[')	st.pop();
		}

		if(st.empty()){
			p("yes");
		}else{
			p("no");
		}
	}

	return 0;
}

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

using namespace std;

int main() {
	string a;
	const string b = "()[]";
	while (getline(cin, a)) {
		if (a.size() == 1 && a[0] == '.') {
			break;
		}
		int count[4] = {0};
		bool hantei = true;
		bool hantei2;
		stack<int> stk;
		for (int i = 0; i < a.size(); i++) {
			int j;
			hantei2 = false;
			for (j = 0; j < 4; j++) {
				if (a[i] == b[j]) {
					count[j]++;
					hantei2 = true;
					break;
				}
			}
			if (hantei2) {
			if (j == 0) {
				stk.push(1);
			} else if (j == 2) {
				stk.push(3);
			} else if (!stk.empty() && stk.top() != j) {
				//cout << 'a' << endl;
				hantei = false;
				break;
			} else if (!stk.empty()){
				stk.pop();
			}
			}
			if (count[0] < count[1]) {
				hantei = false;
				break;
			} else if (count[2] < count[3]) {
				hantei = false;
				break;
			}
		}

		if (hantei && (count[0] == count[1] && count[2] == count[3])) {
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}
	return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

#define Rep(b, e, i) for (int i = b; i <= e; i++)
#define Repr(e, b, i) for (int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n - 1, i)
#define repr(n, i) Repr(n - 1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T, vector<T>, greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false) std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<vec> mat;
typedef vector<vecll> matll;
typedef vector<vecd> matd;

template <class T>
ostream &operator<<(ostream &o, const vector<T> &v)
{
	o << "{";
	for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i];
	o << "}";
	return o;
}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const ll MOD = 1000000007;

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

//********************************template END****************************************//

void solve()
{
	stack<int> s;
	char c, pre = '~';
	while (~scanf("%c", &c))
	{
		if (c == '.')
		{
			if (pre == '\n') return;
			cout << (s.empty() ? "yes" : "no") << endl;
			stack<int> ns;
			swap(s, ns);
		}
		if (c == '(') s.push(1);
		if (c == ')')
		{
			if (s.empty() || s.top() != 1)
			{
				cout << "no" << endl;
				stack<int> ns;
				swap(s, ns);
				while (~scanf("%c", &c))
				{
					if (c == '.') break;
				}
			}
			else s.pop();
		}
		if (c == '[') s.push(-1);
		if (c == ']')
		{
			if (s.empty() || s.top() != -1)
			{
				cout << "no" << endl;
				stack<int> ns;
				swap(s, ns);
				while (~scanf("%c", &c))
				{
					if (c == '.') break;
				}
			}
			else s.pop();
		}
		pre = c;
	}
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}

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

int main(void){

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

    stack<char>st;
    for(int i=0;i<s.size();i++){
      if(s[i]=='(' || s[i]=='[')st.push(s[i]);
      else if(((s[i]==')' || s[i]==']') && st.empty()) ||
	      (s[i]==')' && st.top()=='[') ||
	      (s[i]==']' && st.top()=='(')){
	cout << "no" << endl;
	goto end;
      }
      else if(s[i]==')' || s[i]==']')st.pop();
    }
    if(st.empty())cout << "yes" << endl;
    else cout << "no" << endl;
  end:;
  }
  
  return 0;
}