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>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    string S;
    getline(cin, S);
    while(S.length() - 1){
        stack<char> st;
        bool flag = 0;
        for(char c:S){
            if(c == '[' || c == '(')st.push(c);
            if(c == ']' || c == ')'){
                if(st.size() == 0){
                    flag = 1;
                    break;

                }
                char t = st.top();
                st.pop();
                if(!(t == '[' && c == ']' || t == '(' && c == ')')){
                    flag = 1;
                    break;
                }
            }
        }
        if(!flag && st.size() == 1)cout << "yes" << endl;
        else    cout << "no" << endl;
        getline(cin, S);
    }
}

C++: #include <cstdio>

#include <cstdlib>

#include <cstring>

#include <string>

#include <map>

#include <vector>

#include <iostream>

#include <set>

#include <algorithm>

using namespace std;



char s[150];
int zhan[150];

bool solve(){
	int len,top,i;
	gets(s);
	len=strlen(s);
	if(len==1 && s[0]=='.')return false;
	top=0;
	for(i=0;i<len;++i){
		if(s[i]=='('){
			zhan[++top]=0;
		}else if(s[i]=='['){
			zhan[++top]=1;
		}else if(s[i]==')'){
			if(top==0 || zhan[top]==1){
				printf("no\n");
				return true;
			}
			--top;
		}else if(s[i]==']'){
			if(top==0 || zhan[top]==0){
				printf("no\n");
				return true;
			}
			--top;
		}
	}
	if(top==0)printf("yes\n");else printf("no\n");
	return true;
}


int main(){

	while(solve());

	return 0;

}
束 Back

C++: #include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<stack>

using namespace std;

#define INF 999999999

int main(){
	int i, j;
	char s[101];
	stack<int> st;
	int flag;
	
	while(1){
		fgets(s, 101, stdin);
		if(s[0]=='.')break;
		flag = 1;
		while(!st.empty()) st.pop();
		
		for(i=0;s[i]!='\0';i++){
			if(s[i]=='(') st.push(1);
			else if(s[i]=='[') st.push(2);
			else if(s[i]==')'){
				if(st.empty()||st.top()==2){
					flag = 0;
					break;
				}
				else{
					st.pop();
				}
			}
			else if(s[i]==']'){
				if(st.empty()||st.top()==1){
					flag = 0;
					break;
				}
				else{
					st.pop();
				}
			}
		}
		
		if(flag && st.empty()) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

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

int main(){
	string s;
	string left("([");
	string right(")]");
	while(getline(cin,s),s!="."){
		stack<char> acc;
		for(int unsigned i = 0;i<s.size();i++){
			for(int unsigned j=0;j<left.size();j++){
				if(s[i] == left[j]){
					acc.push(right[j]);	
				}
			}
			if(!acc.empty() && acc.top() == s[i]){
				acc.pop();
			}
		}
		if(acc.empty()){
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}

	return 0;
}

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

#define int long long

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

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  string s;
  while (getline(cin, s), s != ".") {
    stack<char> t;
    rep(i, s.size()) {
      if (s[i] == '[' || s[i] == '(') t.push(s[i]);
      if (s[i] == ')') {
        if (t.size() && t.top() == '(') {
          t.pop();
        } else {
          cout << "no" << endl;
          goto next;
        }
      }
      if (s[i] == ']') {
        if (t.size() && t.top() == '[') {
          t.pop();
        } else {
          cout << "no" << endl;
          goto next;
        }
      }
    }
    cout << (t.size() ? "no" : "yes") << endl;
  next:;
  }
}