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++: /*
 * The Balance of the World
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1173&lang=jp
 */

#include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;

int main() {
  string s;
  while(getline(cin, s), s != ".") {
    stack<char> balance;
    REP(i, s.length()){
      switch (s[i]) {
      case '[':
        balance.push('[');
        break;
      case '(':
        balance.push(')');
        break;
      case ']':
        if(balance.empty() || balance.top() != '[') {
          cout << "no" << endl;
          goto END;
        }
        balance.pop();
        break;
      case ')':
        if(balance.empty() || balance.top() != ')') {
          cout << "no" << endl;
          goto END;
        }
        balance.pop();
        break;
      }
    }
    if(!balance.empty()) {
      cout << "no" << endl;
      goto END;
    }
    cout << "yes" << endl;
END:;
  }
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>

#pragma warning( disable: 4996 )

using namespace std;

typedef long long ll;

#define INF 1000000000
#define EPS 1e-10

string str;

string k[3];
int f[1000000];

vector<string> ans_list;

int main(){

	k[0] = "()";
	k[1] = "[]";

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

		int num;
		int f_c = -1;

		for (num = 0; num < str.length(); num++){
			if (k[0][0] == str[num]){
				f_c++;
				f[f_c] = 0;
			}
			else if (k[1][0] == str[num]){
				f_c++;
				f[f_c] = 1;
			}
			else if (k[0][1] == str[num]){
				if (f_c < 0 || f[f_c] != 0)
					break;
				f_c--;
			}
			else if (k[1][1] == str[num]){
				if (f_c < 0 || f[f_c] != 1)
					break;
				f_c--;
			}
		}

		if (num == str.length())
			ans_list.push_back("yes");
		else
			ans_list.push_back("no");


	}

	for (int i = 0; i < ans_list.size(); i++){
		cout << ans_list[i] << endl;
	}

	return 0;

}

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

using namespace std;

int main(int argc, char const *argv[])
{
	string s;

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

		stack<char> c;
		for(int i1=0;i1<s.size();i1++){
			if(s[i1]=='(') c.push('(');
			else if(s[i1]=='[') c.push('[');
			else if(s[i1]==')'){
				if(!c.empty() && c.top()=='(') c.pop();
				else c.push(')');
			} 
			else if(s[i1]==']'){
				if(!c.empty() && c.top()=='[') c.pop();
					else c.push(']');
			}
			else {}

		}
		if(c.empty()) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define MCLR(a) memset((a), -1 ,sizeof(a))
#define SZ(a) (sizeof(a))
#define FILL(a,v) fill((int*)a,(int*)(a+(SZ(a)/SZ(*(a)))),v)
bool cheak(int x, int y, int xMax, int yMax){return x >= 0 && y >= 0 && xMax > x && yMax > y;}
const int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, 1, 0, -1 };
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 10007;
const int INF = 2147483647;

int main()
{
	string s;

	while (getline(cin, s) && !(s[0] == '.' && s.size()==1)){
		int i;
		stack<char> sc;
		for(i = 0;i < s.size();i++){
			if (s[i] == '(' || s[i] == '[')sc.push(s[i]);

			if (s[i] == ')')if (sc.size() && sc.top() == '('){
				sc.pop();
			}
			else break;
			if (s[i] == ']')if (sc.size() && sc.top() == '['){
				sc.pop();
			}
			else break;
		}
		if (i == s.size())cout << "yes" << endl;
		else			  cout << "no"	<< endl;
	}

}

C++: #include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<ll,ll> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

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

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

int main() {
	string data;

	while (getline(cin, data) && data[0] != '.') {
		stack <char> S;
		int i = 0;
		bool ans = true;

		while (data[i] != '.') {
			if (data[i] == '(') {
				S.push('(');
			}
			else if (data[i] == '[') {
				S.push('[');
			}
			
			if (data[i] == ')') {
				if (S.empty()) {
					ans = false;
				} else if (S.top() != '(') {
					ans = false;
				}
				else {
					S.pop();
				}
			}
			else if (data[i] == ']') {
				if (S.empty()) {
					ans = false;
				} else if (S.top() != '[') {
					ans = false;
				}
				else {
					S.pop();
				}
			}
			i++;
		}

		if (!S.empty()) {
			ans = false;
		}

		if (ans) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
	return 0;
}