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>
using namespace std;

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
int main(void){
  string s;
  while(getline(cin,s),s!="."){
    int c,b;
    c = b = 0;
   // cout<<s.size()<<" "<<s<<endl;
    string n = "";
    bool f = true;
    rep(i,s.size()){
     // cout<<s[i];
      if(s[i] == '(')c++;
      if(s[i] == ')'){
        c--;
        if(c<b){
          f = false;
          break;
        }
     //   cout<<c<<" "<<b<<endl;
//        cout<<i<<" "<<s[i]<<" "<<c<<" "<<b<<endl;
      }
      if(s[i] == '[')b++;
      if(s[i] == ']'){
        b--;

        
      }
      //cout<<b<<" "<<c<<endl;
      if(b<0 || c<0){
        f = false;
        break;
      }
    }
    cout<<(f?"yes":"no")<<endl;
    //cout<<s<<endl;
  }
}

C++: #include<iostream>
#include<stack>
#include<string>
using namespace std;
int main()
{
  string s;
  int i;
  bool f;
  while(getline(cin,s),s[0]!='.'){
    stack<char> st;
    f=true;
    for(i=0;i<s.size();i++){
      if(s[i]=='('||s[i]=='['){
	st.push(s[i]);
      }else if(s[i]==')'||s[i]==']'){
	if(!st.empty()&&(st.top()+1==s[i]||st.top()+2==s[i]))st.pop();
	else f=false;
      }
    }
    puts(f&&st.empty()?"yes":"no");
  }
}

C++: // AOJ 1173

#include <iostream>
#include <string>
#include <stack>
using namespace std;

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

C++: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a)), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

bool check(string s) {
  stack<bool> left, right; // 括弧の種類
  for (int i = 0; i < s.size(); i++) {
    char c = s[i];
    if (c != '(' && c != ')' && c != ']' && c != '[') continue;

    if (c == '(' || c == '[') {
      // debug3(1, i, c);
      left.push(c == '(');
    } else if (left.empty()) {
      // debug3(2, i, c);
      return false;
    } else if ((c == ')') == left.top()) {
      // debug3(3, i, c);
      left.pop();
    } else {
      // debug3(4, i, c);
      return false;
    }
  }
  // debug2(left.size(), right.size());
  return left.empty() && right.empty();
}

void solve() {
  while (true) {
    string s; getline(cin, s);
    if (s == ".") break;
    if (check(s)) outl("yes");
    else outl("no");
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}

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 << "yes" << endl;
  next:;
  }
}

C++: // 2013/07/08 Tazoe

#include <iostream>
#include <string>
#include <stack>
using namespace std;

int main()
{
	while(true){
		string S;
		getline(cin, S);

		if(S==".")
			break;

		stack<char> stk;

		bool flg = true;

		for(int i=0; i<S.size(); i++){
			if(S[i]=='(' || S[i]=='['){
				stk.push(S[i]);
			}
			else if(S[i]==')'){
				if(!stk.empty() && stk.top()=='('){
					stk.pop();
				}
				else{
					flg = false;
				}
			}
			else if(S[i]==']'){
				if(!stk.empty() && stk.top()=='['){
					stk.pop();
				}
				else{
					flg = false;
				}
			}

			if(!flg)
				break;
		}

		if(flg && stk.empty()){
			cout << "yes" << endl;
		}
		else{
			cout << "no" << endl;
		}
	}

	return 0;
}