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 <stack>
#include <string>
using namespace std;

int main(void)
{
	string str;
	while (1){
		getline(cin, str);
		if (str[0] == '.' && str.length() == 1) break;

		stack <char> data;
		data.push('*');
		for (int i = 0; i < (int)str.length(); i++){
			if (str[i] == '(' || str[i] == '[') data.push(str[i]);
			if (str[i] == ')' && data.top() == '(') data.pop();
			if (str[i] == ']' && data.top() == '[') data.pop();
		}

		if (data.top() == '*'){
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

char str[1000];
int main() {
  while (gets(str), str[0] != '.') {
    stack<int> st;
    int len = strlen(str);
    bool ok = true;
    REP(i, len) {
      if (str[i] == '(') { st.push('('); }
      else if (str[i] == '[') { st.push('['); }
      else if (str[i] == ')') {
        if (st.empty() || st.top() != '(') { ok = false; break; }
        st.pop();
      } else if (str[i] == ']') {
        if (st.empty() || st.top() != '[') { ok = false; break; }
        st.pop();
      }
    }
    if (!st.empty()) { ok = false; }
    puts(ok ? "yes" : "no");
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
 while(1){
  int a[2]={},f=0,m[51]={},n[51]={},x=0,y=0;
  string s;
  getline(cin,s);
  if(s[0]=='.')break;
  
  for(int i=0;i<s.size();i++){
   if(s[i]=='.')break;
   if(s[i]=='['){
    a[0]++;
    x++;
    m[x]=i;
   }
   else if(s[i]==']'){
    if(n[y]>m[x]){f=1;break;}
    if(a[0]==0) {f=1;break;}
    a[0]--;
    x--;
   }
   else if(s[i]=='('){
    a[1]++;
    y++;
    n[y]=i;
   }
   else if(s[i]==')'){
    if(n[y]<m[x]){f=1;break;}
    if(a[1]==0){f=1;break;}
    a[1]--;
    y--;    
   }
  }
  if(f==1 || x!=0 || y!=0)cout<<"no"<<endl;
  else 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:;
  }
}

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

int main() {
    map<char, char> m;
    m[')'] = '(';
    m[']'] = '[';
    while(1){
        string str;
        getline(cin, str);
        // cout << str << endl;
        if(str == ".") break;
        stack<char> s;
        bool flag = false;
        for(auto c : str){
            if(c == '(' || c == '['){
                s.push(c);
            }
            if(c == ')' || c == ']'){
                if(s.size() > 0){
                    char taiou = s.top();
                    s.pop();
                    if(m[c] != taiou){
                        cout << "no" << endl;
                        flag = true;
                        break;
                    }
                }else{
                    cout << "no" << endl;
                    flag = true;
                    break;
                }
            }
        }

        if(!flag){
            if(s.size() == 0){
                cout << "yes" << endl;
            }else{
                cout << "no" << endl;
            }
        }
    }
    return 0;
}