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>
using namespace std;

bool isYes(char input[]);

int main()
{
	char Input[100][101];
	int i=0;
	while(true){
		cin.getline(Input[i], sizeof(Input[i]));
		if(Input[i][0] == '.') break;
		i++;
	}
	for(int j=0; j<i; j++){
		if(isYes(Input[j])){
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}
	return 0;
}

bool isYes(char Input[])
{
	int prep[50], prepnum=0, p=3;
	for(int i=0; Input[i]!='.'; i++){
		if(Input[i] == '('){
			if(p != 3){
				prep[prepnum] = p;
				prepnum++;
			}
			p=0;
		} else if(Input[i] == '['){
			if(p != 3){
				prep[prepnum] = p;
				prepnum++;
			}
			p=1;
		} else if(Input[i] == ')'){
			if(p!=0){
				return false;
			} else {
				if(prepnum==0) p=3;
				else {
					p = prep[prepnum-1];
					prepnum--;
				}
			}
		} else if(Input[i] == ']'){
			if(p!=1){
				return false;
			} else {
				if(prepnum==0) p=3;
				else {
					p = prep[prepnum-1];
					prepnum--;
				}
			}
		}
	}
	return true;
}

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

using namespace std;

int main()
{
  int end;
  stack <char> sta;

  string a("(");
  string b(")");
  string c("[");
  string d("]");
  string g;

  while(1){
    string v;
    string t;

    end = 0;

    while(1){
      cin>>v;
      t = t+v;

      for(char s : v){
        if(s == '.'){
          end = 1;
          break;
        }
      }

      if(end == 1){
        break;
      }
    }

    if(t == "."){
      break;
    }
    for(char e : t){
      if(e == '(' || e == '['){
        sta.push(e);
      }
      else if(e == ')'){
        char t = sta.top();
        sta.pop();
        if(t != '('){
          g = "no";
          break;
        }
      }
      else if(e == ']'){
        char t = sta.top();
        sta.pop();
        if(t != '['){
          g = "no";
          break;
        }
      }
    }
    if(g == "no"){
    }
    else{
      g = "yes";
    }

    cout<<g<<endl;
  }
  return 0;
}

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

using namespace std;

#define rep(i, n) REP((i), 0, (n))
#define REP(i, a, n) for(int i=(a); i<(n); i++)



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

        stack<char> st;
        bool flag = true;
        for(char c : s) {
            if(c == '(' || c == '[') {
                st.push((c=='('? ')':']'));
            } else if(c == ')' || c == ']') {
                if(st.empty() || st.top() != c) {
                    flag = false;
                    break;
                }
                st.pop();
            }
        }
        
        cout << (flag? "yes":"no") << endl;
    }
}

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(st.empty() || (s[i]==')' && st.top()=='[') || (s[i]==']' && st.top()=='(')){
	cout << "no" << endl;
	goto end;
      }
      else if(s[i]==')' || s[i]==']')st.pop();
    }
    cout << "yes" << endl;
  end:;
  }
  
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	getline(cin, S);
	while (S != ".") {
		stack<int> st; //[]をカウント。(が出たら新しい値を積む
		st.push(0);
		bool ans = true;
		int n = 0;
		REP(i, SZ(S)) {
			switch (S[i])
			{
			case '[':
				if (SZ(st) == 0) {
					ans = false;
					break;
				}
				n = st.top();
				st.pop();
				st.push(n + 1);
				break;
			case ']':
				if (SZ(st) == 0) {
					ans = false;
					break;
				}
				if (st.top() == 0) {
					ans = false;
					break;
				}
				n = st.top();
				st.pop();
				st.push(n - 1);
				break;
			case '(':
				st.push(0);
				break;
			case ')':
				if (SZ(st) <= 1) {
					ans = false;
					break;
				}
				if (st.top()!= 0) {
					ans = false;
					break;
				}
				st.pop();
				break;
			default:
				break;
			}
			if (!ans)break;
		}
		
		if (SZ(st) != 1) {
			ans = false;
		}
		else {
			if (st.top() != 0) {
				ans = false;
			}
		}
		if (ans) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
		getline(cin, S);
	}
	return 0;
}

C++: #include<iostream>
#include<stack>
#include<string>
using namespace std;
main(){
string s;
int i;
bool f;
for(;getline(cin,s),s[0]!='.';){
 stack<char> t;
 for(f=i=0;i<s.size();i++){
  if(s[i]==40||s[i]==91)t.push(s[i]);
  if(s[i]==41||s[i]==93){
   if(t.size()&&s[i]-t.top()<3)t.pop();
   else f=1;
  }
 }
puts(f&t.size()?"no":"yes");
}}