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<cstdio>
#include<iostream>
#include<stack>
#include<string>

#define loop(lp) for(int i = 0;i < lp;i++)

using namespace std;       
int main(){
  string s;
  stack<char> a;
  int i=0,j=0;
  while(getline(cin,s)){
    while(s[i] != '.'){
      
      if(s[i] == '('){
	a.push('(');  
      }else if(s[i] == ')'){
	if(a.size() == 0){
	  j = 1;
	  break;
	}
	if(a.top() == '('){
	  a.pop();  
	}else{
	  j = 1;
	  break;
	}
      }else if(s[i] == '[' ){
	a.push('[');  
      }else if(s[i] == ']'){
	if(a.size() == 0){
	  j = 1;
	  break;
	}
	if(a.top() == '['){
	  a.pop();  
	}else{
	  j = 1;
	  break;
	}
      }
      i++;
    }
    if(i == 0){
      break;
    }
    if(a.size() == 0 && j != 1){
	cout <<"yes"<<endl;
      }else{
	cout <<"no"<<endl;   
      }
    i = 0;
    while(a.size() != 0){
      a.pop();
    }
    j = 0;
  }
    
    
    return 0;
}

C++: #include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, int> pli;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 300010;

int main(){
        string s;
        while(getline(cin, s) && s!="."){
                stack<char> st;
                bool flag=true;
                for(char c: s){
                        if(c=='(' || c=='[') st.push(c);
                        if(c==')'){
                                if(st.empty() || st.top()!='('){
                                        flag=false;
                                        break;
                                }
                                else st.pop();
                        }
                        if(c==']'){
                                if(st.empty() || st.top()!='['){
                                        flag=false;
                                        break;
                                }
                                else st.pop();
                        }
                }
                if(flag && st.empty()) printf("yes\n");
                else printf("no\n");
        }
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	string s;
	while (getline(cin,s),s!=".") {
		stack<char>S;
		for (int i = 0; i < s.length(); i++) {
			if (s[i] == '(' || s[i] == '[') {
				S.push(s[i]);
			}
			
			else switch (s[i]) {
			case ')':if (!S.empty()&&S.top() == '(')S.pop(); break;
			case ']':if (!S.empty()&&S.top() == '[')S.pop(); break;
			default: break;
			}
		}
		if (S.empty()) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
	return 0;
}

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

int main(){
    char buf[110],stack[110]={0},*sp,*p;
    while(fgets(buf,103, stdin),*buf!='.'){
        sp=stack+1;
        p=buf;
        for(;*p!='.';p++){
            if(*p == '(' || *p == '['){
                *sp++ = *p;
            }else if(*p == ')' || *p == ']'){
                sp--;
                if(!((*sp =='(' && *p == ')') || (*sp =='[' && *p == ']'))){
                    puts("no");
                    break;
                }
            }
        }
        if(*p=='.')puts(sp==stack+1?"yes":"no");
    }
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  string s;
  while(getline(cin, s) && s!= "."){
    bool ok = true;
    stack<char> stk;
    REP(i, s.size()){
      if(s[i] == '(' || s[i] == '['){
        stk.push(s[i]);
      }else if(s[i] == ')' || s[i] == ']'){
        if(stk.empty()){
          ok = false;
          break;
        }
        char t = stk.top(); stk.pop();
        if(t == '(' && s[i] == ']'){
          ok = false;
           break;
        }
        if(t == '[' && s[i] == ')'){
          ok = false;
           break;
        }
      }
    }
    if(ok && stk.empty()) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }

  return 0;
}

C++: #include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

bool check(string s){
	bool res=true;
	rep(i,s.size()){
		if(s[i]=='('){
			int cnt[2]={0,0};
			bool con=false;
			loop(j,i+1,s.size()){
				if(cnt[0]==0 && cnt[1]==0 && s[j]==')'){
					string next=s.substr(i+1,j-i-1);
					i=j;
					if(!check(next))return false;
					con=true;
					break;
				}else if(s[j]=='(')cnt[0]++;
				else if(s[j]==')')cnt[0]--;
				else if(s[j]=='[')cnt[1]++;
				else if(s[j]==']')cnt[1]--;
			}
			res&=con;
		}else if(s[i]=='['){
			int cnt[2]={0,0};
			bool con=false;
			loop(j,i+1,s.size()){
				if(cnt[0]==0 && cnt[1]==0 && s[j]==']'){
					string next=s.substr(i+1,j-i-1);
					i=j;
					if(!check(next))return false;
					con=true;
					break;
				}else if(s[j]=='(')cnt[0]++;
				else if(s[j]==')')cnt[0]--;
				else if(s[j]=='[')cnt[1]++;
				else if(s[j]==']')cnt[1]--;
			}
			res&=con;
		}else if(s[i]==')')return false;
		else if(s[i]==']')return false;
	}
	return res;
}

int main(){
	string s;
	while(1){
		getline(cin,s);
		if(s==".")break;
		if(check(s))cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}	
	return 0;
}