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 "stdio.h"
#include "limits"
#include "algorithm"
#include "iostream"
#include "cmath"
#include "string"
#include "map"
#include "iomanip"
#include "stack"
using namespace std;

int main(){
  char S[110];
  bool FLAG;
  stack<char> temp;
  while(1){
    FLAG=true;
    gets(S);
    if(S[0]=='.')break;
    for(int i=0;S[i]!='.';++i){
      if(S[i]=='(' || S[i]=='[')temp.push(S[i]);
      if(S[i]==')'){
        if(temp.empty()){
          FLAG=false;
          break;
        }
        char a=temp.top();
        temp.pop();
        if(a!='('){
          FLAG=false;
          break;
        }

      }
      if(S[i]==']'){
        if(temp.empty()){
          FLAG=false;
          break;
        }
        char a=temp.top();
        temp.pop();
        if(a!='['){
          FLAG=false;
          break;
        }
      }
    }
    if(FLAG&&temp.empty())cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    while(!temp.empty())temp.pop();
  }
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 27;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)

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

C++: //#include <bits/stdc++.h>
#include <iostream>
#include <stack>
using namespace std;
#define MAX 300000

int main(){
	string s, str;
	stack<char> st;
	st.push('.');
	while(getline(cin, str)){
		if(str == ".")break;
		while(st.top() != '.')st.pop();
		//cout << str << str.size() << endl;
		for(int i = 0;i < str.size();i++){
			if(str[i] == '[' || str[i] == '('){
				st.push(str[i]);
			}
			if(str[i] == ']' || str[i] == ')'){
				if(st.top() == '(' && str[i] == ')')st.pop();
				else if(st.top() == '[' && str[i] == ']')st.pop();
				else {st.push(']');break;}
			}
		}
		//cout << st.top();
		if(st.top() == '.' || st.top() != ']')
		cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

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

using namespace std;

main(){
  char c;
  while(scanf("%c", &c) != EOF){
    if(c == '.') break;
    stack<char> data;
    bool f = true;
    while(c != '\n'){
      if(f){
        if(c == '(' || c == '[') data.push(c);
        if(c == ')'){
          if(data.size() == 0 || data.top() != '(') f = false;
          else data.pop();
        }
        if(c == ']'){
          if(data.size() == 0 || data.top() != '[') f = false;
          else data.pop();
        }
      }
      scanf("%c", &c);
    }
    cout << (data.size() == 0 && f ? "yes" : "no") << endl;
  }
}

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

int main(void) {
    string s;

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

        stack<char> sc;
        char tmp;
        for (auto i : s) {
            switch (i) {
            case '(':
                sc.push('(');
                break;
            case '[':
                sc.push('[');
                break;
            case ')':
                if (sc.size() == 0) {
                    flag = true;
                    break;
                }

                tmp = sc.top();
                if (tmp == '(') {
                    sc.pop();
                } else {
                    flag = true;
                }
                break;
            case ']':
                if (sc.size() == 0) {
                    flag = true;
                    break;
                }

                tmp = sc.top();
                if (tmp == '[') {
                    sc.pop();
                } else {
                    flag = true;
                }
                break;
            }
            if (flag) break;
        }
        if (flag) {
            cout << "no" << endl;
        } else {
            cout << "yes" << endl;
        }
    }
    return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<math.h>
#include<string>
#include<stack>

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

using namespace std;

string str;

void solve() {
	stack<char> sta;
	rep(i,str.size()) {
		if(str[i]=='('||str[i]=='[') sta.push(str[i]);
		if(str[i]==')') {
			if(sta.empty()) {
				cout<<"no"<<endl;
				return;
			}
			if(sta.top()!='(') {
				cout<<"no"<<endl;
				//cout<<i<<endl;
				return;
			}
			else {
				sta.pop();
			}
		}
		if(str[i]==']') {
			if(sta.empty()) {
				cout<<"no"<<endl;
				return;
			}
			if(sta.top()!='[') {
				cout<<"no"<<endl;
				//cout<<i<<endl;
				return;
			}
			else {
				sta.pop();
			}
		}
	}
	cout<<"yes"<<endl;

}

int main() {
	while(getline(cin,str)) {
		if(str==".") return 0;
		solve();
	}

	return 0;
}

C++: #include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <stack>

#define REP(i,n) for(int i=0; i<n; i++)
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
 
#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9

using namespace std;
typedef long long ll;

int main(){
	while(1){
		string str;
		bool ok=true;
		getline(cin, str);
		//debug(str);
		if (str.length()==1 && str[0]=='.') break;
		stack<int> po;
		for (int i=0; i<str.length(); i++){
			if (str[i]=='(') po.push(0);
			else if (str[i]=='[') po.push(1);
			else if (str[i]==')'){
				if (po.size()>0 && po.top()==0){
					po.pop();
				}else{
					printf("no\n");
					ok = false;
					break;
				}
			}else if (str[i]==']'){
				if (po.size()>0 && po.top()==1){
					po.pop();
				}else{
					printf("no\n");
					ok = false;
					break;
				}
			}
		}
		
		if (ok && po.size()>0){
			printf("no\n");
			ok = false;
		}
		if (ok) printf("yes\n");
		
	}
	return 0;
}