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>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
#define scanf scanf_s

string s;

int main()
{
	while (getline(cin, s))
	{
		if (s[0] == '.') return 0;
		vector<char> v;
		REP(i,85)v.push_back(0);
		bool f = true;
		REP(i, s.size())
		{
			if (s[i] == '[') v.push_back('[');
			if (s[i] == '(') v.push_back('(');
			if (s[i] == ']')
			{
				if (v.back() == '[')
				{
					v.pop_back();
				}
				else f = false;
			}
			if (s[i] == ')')
			{
				if (v.back() == '(')
				{
					v.pop_back();
				}
				else f = false;
			}
		}
		if (f) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

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

bool isPair(char top, char input) {
    if ((top == '(' && input ==')') 
        || (top == '[' && input ==']')) {
        return true;
    } 
    return false;
}

void check(string str) {
    stack<char> st;

    for (int i = 0; i < str.size(); ++i) {
        if (!st.empty()) {
            char top = st.top();
            if (isPair(top, str[i])) {
                st.pop();
                continue;
            }
        }
        
        if (str[i] == '(' || str[i] == ')' 
            || str[i] == '[' || str[i] == ']') {
            st.push(str[i]);
        }
    }

    if( st.empty() ) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
}

int main() {
    string str;
    while(getline(cin, str), str.front() != '.') {
        cout<<str<<endl;
        check(str);
    }
    return 0;
}

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

using namespace std;

int main()
{
    char str[128];
    char to[128];
    
    to['['] = ']';
    to['('] = ')';
    
    while (fgets(str, sizeof(str), stdin) != NULL){
        str[strlen(str) - 1] = 0;
        if (str[0] == '.' && str[1] == 0) break;
        
        char st[128];
        int ptr = 0;
        bool ok = true;
        
        for (int i = 0; str[i]; i++){
            if (str[i] == '(' || str[i] == '[') st[ptr++] = str[i];
            else if (str[i] == ')' || str[i] == ']'){
                if (ptr == 0 || to[st[--ptr]] != str[i]){
                    ok = false;
                    break;
                }
            }
        }
        
        printf("%s\n", ok && !ptr ? "yes" : "no");
    }
    
    return (0);
}

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

int main(){
  string s;
  while(1){
    getline(cin,s);
    if(s.size()==1&&s[0]=='.')break;
    string tmp;
    bool ok=true;
    for(int i=0;i<s.size();i++){
      if(s[i]=='(')tmp.push_back('(');
      if(s[i]=='[')tmp.push_back('[');

      if(s[i]==')'&&tmp[tmp.size()-1]=='('){
	tmp.pop_back();
      }else if(s[i]==')'&&(tmp[tmp.size()-1]=='['||tmp.size()==0)){
	ok=false;
	break;
      }

      if(s[i]==']'&&tmp[tmp.size()-1]=='['){
	tmp.pop_back();
      }else if(s[i]==']'&&(tmp[tmp.size()-1]=='('||tmp.size()==0)){
	ok=false;
	break;
      }
    }
    if(ok&&tmp.size()==0)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    
  }
  return 0;
}

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

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

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

using namespace std;

int main()
{
  int no;
  string end(".");
  char a5;

  while(1){
    no = 0;
    string v;
    stack<char> sta;
    getline(cin,v);

    if(v == end){
      break;
    }

    for(char e : v){
      if(e == '[' || e == '('){
        sta.push(e);
      }
      else if(e == ']'){
        a5 = sta.top();
        sta.pop();

        if(a5 != '['){
          no = 1;
        }
      }
      else if(e == ')'){
        a5 = sta.top();
        sta.pop();

        if(a5 != '('){
          no = 1;
        }
      }
      if(no == 1){
        break;
      }
    }

    if(no == 1){
      cout<<"no"<<endl;
    }
    else{
      cout<<"yes"<<endl;
    }
  }

  return 0;
}

C++: #include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S;
    while(getline(cin,S)){
        if(S == ".") break;
        string T = "";
        for(int i=0; i<S.size(); i++){
            if(S[i] == '(' or S[i] == ')' or S[i] == '[' or S[i] == ']') T += S[i];
        }
        bool ok = true;
        while(ok){
            if(T.size() == 0) break;
            ok = false;
            for(int i=0; i<T.size()-1; i++){
                if((T[i] == '(' and T[i+1] == ')') or(T[i] == '[' and T[i+1] == ']')){
                    ok = true;
                    T.erase(i,2);
                    break;
                }
            }
        }
        if(T.size() == 0){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
    return 0;
}