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;

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


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

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

int main(){

  string str;
  stack < int > a;
  stack < int > b;
  int count;
  while(1){

    count = 0;

    getline(cin,str);
    if(str == ".")break;

    for(int i=0;i<str.size();i++){

      if((a.size() == 0 && str[i] == ')') || (b.size() == 0 && str[i] == ']')){
	count = 1;
	break;
      }

      if(str[i] == '(') a.push(1);
      else if(str[i] == ')') a.pop();
      else if(str[i] == '[') b.push(1);
      else if(str[i] == ']') b.pop();
    }

    if(a.size() == 0 && b.size() == 0 && count == 0) printf("yes\n");
    else printf("no\n");
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    while(getline(cin,s),s!="."){
        string c;
        int d=1;
        stack<char> w;
        for(int i=0;i<s.size();i++)if(s[i]==')'||s[i]=='('||s[i]=='['||s[i]==']')c+=s[i];
            for(int i=0;i<c.size();i++){
            if(c[i]=='['||c[i]=='(')w.push(c[i]);
            else if(c[i]==']'&&w.top()=='['||c[i]==')'&&w.top()=='(')w.pop();
            else {d=0;break;}
        }
        if(d)cout<<"yes"<<endl;
        else fail:cout<<"no"<<endl;
    }
    return 0;
}

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

int main(){
	string str;
	
	while(1){
		stack <int> sta;
		int si = 0, f = 1;
		getline(cin, str);
		
		if(str == ".") break;
		
		si = str.size();
		
		for(int i = 0; i < si; i++){
			switch(str[i]){
				case '[': sta.push(1); break;
				case ']': if(!sta.empty()){if(sta.top() != 1)f = 0; sta.pop();}else f = 0;break;
				case '(': sta.push(2); break;
				case ')': if(!sta.empty()){if(sta.top() != 2)f = 0; sta.pop();}else f = 0;break;
			}
			if(f == 0) break;
		}
		
		if(!sta.empty())f = 0;
		
		if(f) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
		
	}
	return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

//#define int long long

/*************** using variables ***************/
string s;
/**********************************************/

signed main(){
    while(getline(cin, s), s != "."){
        stack<char> st;
        st.push('.');
        auto itr = s.begin();
        bool flag = true;
        while(*itr != '.'){
            if(*itr == '['  || *itr == '(') st.push(*itr);
            if(*itr == ']'){
                if(st.top() != '['){
                    flag = false;
                    break;
                }else{
                    st.pop();
                }
            }
            if(*itr == ')'){
                if(st.top() != '('){
                    flag = false;
                    break;
                }else{
                    st.pop();
                }
            }
            ++itr;
        }
        cout << (flag ? "yes":"no") << endl;
        s = "";
    }
}

C++: #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i,a,n) for(ll i=a;i<(ll)(n);i++)

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

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

string str;

bool is_balance(){

  stack<char> s;

  for(int i=0 ; str[i] != '.' ; i++){
    if(str[i] == '(' || str[i] == '['){
      s.push(str[i]);
    }else if(str[i] == ')'){
      if(s.empty() || s.top() != '('){
	return false;
      }
      s.pop();
    }else if(str[i] == ']'){
      if(s.empty() || s.top() != '['){
	return false;
      }
      s.pop();
    }
  }
  
  return true;
  
}
int main(){

  while(1){

    getline(cin,str);

    if(str == ".")break;
    
    if(is_balance()){
      cout <<"yes"<<endl;
    }else{
      cout <<"no"<<endl;
    }
    
  }


  return 0;
}

C++: #include <iostream>
#include <string>
#include <stack>
using namespace std;
string s;
bool solve() {
  stack<char> stk;
  for(int i=0; i!=(int)s.length(); ++i) {
    if(s[i] == '[' || s[i] == '(') stk.push(s[i]);

    else if(s[i] == ']') {
      if(stk.empty()) return 0;
      if(stk.top() != '[') return 0;
      stk.pop();
    }
    else if(s[i] == ')') {
      if(stk.empty()) return 0;
      if(stk.top() != '(') return 0;
      stk.pop();
    }
  }
  return stk.empty();
}

int main() {
  while(getline(cin, s) && s != ".") {
    cout << (solve() ? "yes" : "no") << endl;
  }
  return 0;
}