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<map>
#include<vector>
#include<list>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))
#define ALL(c) (c).begin(), (c).end()
#define dump(a) cerr << #a << "=" << (a) << endl

using namespace std;

int main() {
	string line;
	char left_paren;
	bool is_yes;
	vector<char> left_parens;

	while(getline(cin,line)) {
		if (line[0] == '.') break;

		left_parens.clear();
		is_yes = true;

		rep(i,line.size()) {
			if (line[i] == '(') {
				left_parens.push_back(line[i]);
			}
			else if (line[i] == '[') {
				left_parens.push_back(line[i]);
			}
			else if (line[i] == ')') {
				left_paren = left_parens.back();
				left_parens.pop_back();
				if (left_paren != '(') {
					is_yes = false;
				}
			}
			else if (line[i] == ']') {
				left_paren = left_parens.back();
				left_parens.pop_back();
				if (left_paren != '[') {
					is_yes = false;
				}
			}
			else if(line[i] == '.') 
				break;
		}
		if (left_parens.size() > 0)
			is_yes = false;

		if (is_yes) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	

	return 0;
}

C++: #include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

bool check(string s){
	bool res=true;
	rep(i,s.size()){
		if(s[i]=='('){
			int cnt[2]={0,0};
			bool con=false;
			loop(j,i+1,s.size()){
				if(cnt[0]==0 && cnt[1]==0 && s[j]==')'){
					string next=s.substr(i+1,j-i-1);
					i=j;
					if(!check(next))return false;
					con=true;
				}else if(s[j]=='(')cnt[0]++;
				else if(s[j]==')')cnt[0]--;
				else if(s[j]=='[')cnt[1]++;
				else if(s[j]==']')cnt[1]--;
			}
			res&=con;
		}else if(s[i]=='['){
			int cnt[2]={0,0};
			bool con=false;
			loop(j,i+1,s.size()){
				if(cnt[0]==0 && cnt[1]==0 && s[j]==']'){
					string next=s.substr(i+1,j-i-1);
					i=j;
					if(!check(next))return false;
					con=true;
				}else if(s[j]=='(')cnt[0]++;
				else if(s[j]==')')cnt[0]--;
				else if(s[j]=='[')cnt[1]++;
				else if(s[j]==']')cnt[1]--;
			}
			res&=con;
		}else if(s[i]==')')return false;
		else if(s[i]==']')return false;
	}
	return res;
}

int main(){
	string s;
	while(1){
		getline(cin,s);
		if(s==".")break;
		if(check(s))cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}	
	return 0;
}

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,105)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 <string>
#include <stack>

using namespace std;

int main(){
	int maru=0,kaku=0;

	string str;
	while(getline(cin,str)){
		if(str.at(0)=='.')break;
		maru=0;
		kaku=0;
		stack<int> s;

		for(int i=0;i<str.size();i++){
			if(str.at(i)=='('){
				maru++;
				s.push(1);
			}
			else if(str.at(i)==')' && maru>0){
				if(s.top()==1){
					maru--;
					s.pop();
				}
			}
			if(str.at(i)=='['){
				kaku++;
				s.push(2);
			}
			else if(str.at(i) ==']' &&kaku>0){
				if(s.top()==2){
					kaku--;
					s.pop();
				}
			}
		}

		if(maru==0&&kaku==0){
			cout<<"yes"<<endl;
		}
		else{
			cout<<"no"<<endl;
		}
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
typedef pair<int,int> P;

int main() {
  string t,s="";
  bool ck=false;
  while(getline(cin,t)) {
    if(t==".") break;
    rep(i,t.size()) {
      if(t[i]=='(' || t[i]==')' || t[i]=='[' || t[i]==']') s+=t[i];
      if(t[i]=='.') ck=true;
    }
    if(ck) {
      stack<char> a;
      rep(i,s.size()) {
	if(a.size()) {
	  if((a.top()=='(' && s[i]==')') || (a.top()=='[' && s[i]==']')) a.pop();
	  else a.push(s[i]);
	} else a.push(s[i]);
      }
      if(!a.size()) pr("yes");
      else pr("no");
      ck=false;
      s="";
    }
  }
  return 0;
}

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

using namespace std;
int main(){
  string hoge,hogehoge;
  stack<char> foo;

  while(1){

    while(!(foo.empty()))foo.pop();
    hogehoge = "\0";
    getline(cin,hoge);
    if(hoge == ".")break;

    for(int i = 0 ; i < (int)hoge.size(); i++ ){
      if(hoge[i] == '[' ||hoge[i] == '(' ||hoge[i] == ')' ||hoge[i] == ']' ){
	hogehoge+=hoge[i];
      }
    }

    for(int i = 0 ; i < (int)hogehoge.size() ; i++ ){
      if(hogehoge[i] == '['||hogehoge[i] == '('){
	foo.push(hogehoge[i]);
      }else if(hogehoge[i] == ']' && !(foo.empty()) && foo.top() == '['){
	foo.pop();
      }else if(hogehoge[i] == ')' && !(foo.empty()) && foo.top() == '('){
	foo.pop();
      }else goto bad;
    }
    if(foo.empty()){cout << "yes" << endl;continue;}
  bad: cout << "no" << endl; 
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<algorithm>
using namespace std;
string s;
bool input(){
  if(getline(cin,s)){
    if(s==".")return false;
    return true;
  }
  return false;
}
bool solve(){
  stack<char> st;
  for(int i=0;i<s.size();i++){
    if(s[i]=='('||s[i]=='['){
      st.push(s[i]);
    }else if(s[i]==')'||s[i]==']'){
      if(st.empty())return false;
      char tmp = st.top();st.pop();
      if(s[i]==')'){
        if(tmp != '(')return false;
      }else{
        if(tmp != '[')return false;
      }
    }
  }
  if(st.empty()){
    return true;
  }else{
    return false;
  }
}

int main(){
  while(input()){
    if(solve()){
      cout<<"yes"<<endl;
    }else{
      cout<<"no"<<endl;
    }
  }
}