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;
using ll = long long;
const int MOD = 1e9+7;


int main(){
    string s;
    while(getline(cin, s)){
        if(s == "."){
            return 0;
        }
        stack<char> sta;
        bool f = true;
        for(char c : s){
            if(c == '('){
                sta.push(c);
            }
            if(c == ')'){
                if(sta.empty()){
                    f = false;
                    break;
                }
                if(sta.top() == '('){
                    sta.pop();
                }else{
                    f = false;
                    break;
                }
            }
            if(c == '['){
                sta.push(c);
            }
            if(c == ']'){
                if(sta.empty()){
                    f = false;
                    break;
                }
                if(sta.top() == '['){
                    sta.pop();
                }else{
                    f = false;
                    break;
                }
            }
        }
        if(!sta.empty())f = false;
        if(f){
            cout<<"yes"<<endl;
        }else{
            cout<<"no"<<endl;
        }
        s.clear();
    }
}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
 
using namespace std;
 
#define ll long long
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pii pair<int,pi>
#define X first
#define Y second
#define pb push_back
#define ab(x) ((x)<0?(-(x)):(x))
#define xx(x) ((x)*(x))
#define mp make_pair
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vpi vector<pi>
#define vpll vector<pll>
#define ALL(x) (x).begin(),(x).end()
#define Max (1<<30)
#define LLMax (1ll<<60)
template<class T>string ToString(T t){stringstream s;s<<t;return s.str();}
template<class T>void ToOther(T&t,string a){stringstream s(a);s>>t;}
 
char a[10005];
int main(){
	while(1){
		gets(a);
		string t=a;
		if(t==".")break;

		bool no=0;
		stack<char> st;
		for(int i=0;i<t.size();i++){
			if(t[i]=='('){
				st.push(')');
			}
			if(t[i]=='['){
				st.push(']');
			}

			if(t[i]==')'){
				if(st.size()==0 || st.top()!=t[i]){
					no=1;break;
				}
				st.pop();
			}
			if(t[i]==']'){
				if(st.size()==0 || st.top()!=t[i]){
					no=1;break;
				}st.pop();
			}
		}
		
		cout<<(no?"no":"yes")<<endl;
	}
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cctype>

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VII;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

string s;

bool solve(int idx, char symbol) {
	bool res = true;
	REP (i, idx, s.size()) {
		if (!res) break;
		switch (s[i]) {
			case '(':
				s[i] = '#';
				res = solve(i + 1, '(');
				break;
			case '[':
				s[i] = '#';
				res = solve(i + 1, '[');
				break;
			case ')':
				s[i] = '#';
				return (symbol == '(');
				break;
			case ']':
				s[i] = '#';
				return (symbol == '[');
				break;
			default:
				break;
		}
	}
	return res;
}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	while (1) {
		getline(cin, s);
		if (s == ".") break;
		cout << (solve(0, '#')? "yes" : "no") << endl;
	}
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

string s;

int main()
{
  while(getline(cin, s) && s != "."){
    stack<char> st;
    vrep(v, s){
      if(*v == '(' || *v == '[') st.push(*v);
      if(*v == ')' || *v == ']'){
        if(st.empty()){
          st.push('(');
          break;
        }
        if(st.top() == '(' && *v == ')'){ st.pop();  continue; }
        if(st.top() == '[' && *v == ']'){ st.pop();  continue; }
        break;
      }
    }
    puts(st.empty() ? "yes" : "no");
  }

  return 0;
}

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

typedef std::int_fast32_t  s32;
typedef std::uint_fast32_t u32;
typedef std::int_fast64_t  s64;
typedef std::uint_fast64_t u64;

typedef std::pair<int, int> P;

int N;
std::string str;
int i;

bool solve(char prev) {
  for(;;) {
    while( str[i] != '(' and str[i] != ')' and str[i] != '[' and str[i] != ']' and i != N ) i += 1;
    if( i == N ) return (prev == '\0');
    
    if( str[i] == '(' ) {
      i += 1;
      if( not solve('(') ) return false;
      i += 1;
      continue;
    }
    if( str[i] == '[' ) {
      i += 1;
      if( not solve('[') ) return false;
      i += 1;
      continue;
    }
    if( prev == '(' and str[i] == ')' ) {
      return true;
    }
    if( prev == '[' and str[i] == ']' ) {
      return true;
    }
    return false;
  }
  return false;
}

int main() {

  for(;;) {
    std::getline(std::cin, str);
    if( str == "." ) break;
    N = str.size();
    i = 0;
    std::cout << (solve('\0') ? "yes" : "no") << std::endl;
  }
  
  return 0;
}