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<cstdio>

using namespace std;

int main(){
  char r[202];
  int count = 101;
  char s;
  char c;
  int maru=0;
  int shikaku=0;
  while(true){
    //はじめの文字の判定
    scanf("%c",&s);
    if(s=='\n')scanf("%c",&s);
    if(s=='.')break;
    if(s=='('){
      r[count++]=')';
      maru++;
    }
    else if(s=='['){
      r[count++]=']';
      shikaku++;
    }
    else if(s==')'){
      if(r[count--]==s){
	maru--;
      }
    }
    else if(s==']'){
      if(r[count--]==s){
	shikaku--;
      }
    }
    //終了条件ではないとき
    while(true){
      cin>>c;
      //    cout<<c;
      if(c=='.'||maru<0||shikaku<0)break;
      else if(c=='('){
	r[count++]=')';
	maru++;
      }
      else if(c=='['){
	r[count++]=']';
	shikaku++;
      }
      else if(c==')'){
	if(r[count-1]==c){
	  count--;
	  maru--;
	}
	else maru=-1111;
      }
      else if(c==']'){
	if(r[count-1]==c){
	  count--;
	  shikaku--;
	}
	else shikaku=-1111;
      }
    }
   if(c!='.'){
      while(true){
	cin>>c;
	//    cout<<c;
	if(c=='.')break;
      }
    }
     if(maru==0&&shikaku==0)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    maru=0;
    shikaku=0;
  }
  return 0;
}

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

using namespace std;

int main(void){
  string s;

  while(getline(cin,s) && s!="."){

    string ch;
    for(int i=0;i<s.size();i++)
      if(s[i]=='[' || s[i]=='(' || s[i]==']' || s[i]==')')ch+=s[i];

    stack<char> str;
    bool flag = true;
    for(int i=0;i<ch.length();i++){
      
      if(str.empty() || ch[i]=='(' || ch[i]=='[')str.push(ch[i]);
      else if((ch[i]==')' && str.top()=='(')||(ch[i]==']' && str.top()=='['))str.pop();
      else {
	flag = false;
	break;
      }
    }

    cout << (flag && str.empty()?"YES":"NO") << endl;

  }

  return 0;
}

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

using namespace std;
typedef long long ll;

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

int main(void) {
  string s;
  char brackets[] = {'(', ')', '[', ']'};
  while (getline(cin, s) && s != ".") {
    stack<char> stk;
    bool yes = true;
    rep(i, s.size()) {
      bool is_bracket = false;
      rep(j, 4) if (s[i] == brackets[j]) is_bracket = true;
      if (!is_bracket)
        continue;
      if (s[i] == '(' || s[i] == '[')
        stk.push(s[i]);
      else if ((stk.top() == '(' && s[i] == ')') ||
               (stk.top() == '[' && s[i] == ']'))
        stk.pop();
      else {
        yes = false;
        break;
      }
    }

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

C++: #include <iostream>
#include <utility>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

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

const int INF = 1 << 28;

int main()
{
  for(;;) {
    string str;
    getline(cin, str);

    if(str == ".") {
      break;
    }

    int pl = 0;
    int kl = 0;
    bool flag = true;
    for(char c : str) {
      switch (c) {
        case '(':
          ++pl;
          break;
        case '[':
          ++kl;
          break;
        case ')':
          flag &= pl > 0;
          --pl;
          break;
        case ']':
          flag &= kl > 0;
          --kl;
          break;
      }
    }
    flag &= pl == 0;
    flag &= kl == 0;

    cout << (flag ? "yes" : "no") << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <climits>
#include <string>
#include <cstring>
#include <stack>

using namespace std;

char s[1000];

string solve()
{
	stack<char> st;

	for(int i = 0; s[i] != '.'; i++)
	{
		if( s[i] == '(' )
		{
			st.push('(');
		}
		else if( s[i] == '[' )
		{
			st.push('[');
		}
		else if( s[i] == ')' )
		{
			if( !st.empty() && st.top() == '(' )
				st.pop();
			else
				st.push(')');
		}
		else if( s[i] == ']' )
		{
			if( !st.empty() && st.top() == '[' )
				st.pop();
			else
				st.push(']');
		}
	}

	if( st.empty() && st.empty() )
		return "yes";
	else 
		return "no";
}

int main()
{
	while( gets(s), s[0] != '.' )
	{
		cout << solve() << endl;
	}

	return 0;
}

C++: #pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
	string s;
while(getline(cin,s)&&s!="."){
	string t={};
	for(char c:s)if(c=='('||c==')'||c=='['||c==']')t+=c;
	stack<char> st;
	bool ok=true;
	for(auto c:t){
		if(c=='('||c=='[')st.push(c);
		else{
			if(st.empty())ok=false;
			else{
				if(c==')'&&st.top()!='(')ok=false;
				if(c==']'&&st.top()!='[')ok=false;
				st.pop();
			}
		}
	}
	ok&=st.empty();
	cout<<(ok?"yes":"no")<<endl;
}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
const int INF = 1<<28;

string input;

int find(int a, int p) {
	int btn[2] = {};
	FOR(i, p, input.size()) {
		if(a) {
			if(input[i] == '[')
				btn[0]++;
			if(input[i] == ']')
				btn[0]--;
			if(input[i] == '(')
				btn[1]++;
			if(input[i] == ')') {
				btn[1]--;
				if(!btn[0] && !btn[1])
					return 0;
			}
		}
		else {
			if(input[i] == '(')
				btn[0]++;
			if(input[i] == ')')
				btn[0]--;
			if(input[i] == '[')
				btn[1]++;
			if(input[i] == ']') {
				btn[1]--;
				if(!btn[0] && !btn[1])
					return 0;
			}
		}
	}
	return 1;
}


int main() {
	while(getline(cin, input)) {
		if(input == ".") break;
		int cnt = 0;
		REP(i, input.size()) {
			if(input[i] == '(')
				cnt += find(1, i);
			if(input[i] == '[')
				cnt += find(0, i);
		}
		cout << (cnt ? "no" : "yes") << endl;
	}
	return 0;
}