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 lp(i,n) for(int i=1;i<n;i++)
#define lpin(a,i,n) for(int i=0;i<n;i++){cin>>a[i];}

int main(){
  while(1){
    char x;
    int a=0,b=0,de[150],ch=0,f=0,it=0;
    if(f=0){
      f=1;
    }
    else  scanf("%c",&x);
    scanf("%c",&x);
    if(x=='.') break;
    while(1){
      if(x=='(') {
	a++;
	
	it++;
	de[it]=1;
      }
      if(x==')') {
	if(de[it]==1){
	  a--;
	  it--;
	}
	else{ch=1;}
      }
      if(x=='['){
	b++;
	it++;
	de[it]=2;
      }
      if(x==']'){
	if(de[it]==2){
	  b--;
	  it--;
	}
	else{ch=1;}
      }
      if(a<0 || b<0){
	ch=1;
      }
      scanf("%c",&x);
      if(x=='.') break;
    }
    if(ch==0 &&a==0 && b==0) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <string>
#include <climits>

#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define PRINT(STR) cout << (STR) << endl

typedef long long ll;
using namespace std;

int main() {
	cin.tie(0); //対話型には使えない
	ios::sync_with_stdio(false); //printfと共には使えない
	string str;
	while (str = "", getline(cin, str), str != ".") {
		stack<char> s;
		while (!s.empty()) {
			s.pop();
		}
		
		REP(i, str.size()) {
			if (str[i] == '[' || str[i] == '(') {
				s.push(str[i]);
			} else if (str[i] == ']') {
				if (s.size() == 0 || s.top() != '[') {
					PRINT("no");
					break;
				}
				s.pop();
			} else if (str[i] == ')') {
				if (s.size() == 0 || s.top() != '(') {
					PRINT("no");
					break;
				}
				s.pop();
			}
			if (i == str.size() - 1) {
				PRINT("yes");
			}
		}
	}
	return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,a) for(int i = 0;i < (a); i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)
#define repd(i,a,b) for(int i = (a); i >= (b); i--)
#define repit(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())
#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

int main() {
    string s;
    while(getline(cin, s), s != "."){
	stack<int> stk;
	string ans = "yes";
	rep(i, s.size()){
	    if(s[i] == '(') stk.push(0);
	    else if(s[i] == ')'){
		if(stk.empty() || stk.top() != 0) ans = "no";
		else stk.pop();
	    }
	    if(s[i] == '[') stk.push(1);
	    else if(s[i] == ']'){
		if(stk.empty() || stk.top() != 1) ans = "no";
		else stk.pop();
	    }
	}
	if(!stk.empty()) ans = "no";
	cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

bool judge(string &str);

main(void) {
	string text;
	while(1) {
		
		getline(cin, text);
		if(text[0] == '.')		break;
		
		if( judge(text)) {
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}
}

bool judge(string &str) {
	stack<char> S;
	char c;
	for(unsigned int i = 0; i < str.size(); ++i) {
		
		if(str[i] == '(' || str[i] == '[') {
			S.push( str[i] );
		} else if(str[i] == ')' ) {
			//スタックが空の時だったらはじく
			if( S.empty() )					return false;
			//直前のかっこが[の時だったらはじく
			c = S.top();
			if( c != '(' )		return false;
			S.pop();
		} else if(str[i] == ']' ) {
			//スタックが空の時だったらはじく
			if( S.empty() )					return false;
			//直前のかっこが(の時だったらはじく
			c = S.top();
			if( c != '[' )		return false;
			S.pop();
		}
	}
		return S.empty();
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define PREP(i, m, n) for(int i = m; i < n; i++)
#define MREP(i, m, n) for(int i = m - 1; i >= n; i--)
using namespace std;

int main(){
	string input;
	while(getline(cin, input)){
		stack<char> bracket;
		if(input.size() == 1 && input[0] == '.') break;
		for(int i = 0; i < input.size(); i++){
			if(input[i] == '(' || input[i] == '[') bracket.push(input[i]);
			if(bracket.size() == 0){
				if(input[i] == ')' || input[i] == ']'){
					bracket.push(input[i]);
					break;
				}
				continue;
			}
			if(input[i] == ')'){
				if(bracket.top() == '(') bracket.pop();
				else break;
			}
			else if (input[i] == ']'){
				if(bracket.top() == '[') bracket.pop();
				else break;
			}
		}
		cout << (!bracket.size() ? "yes" : "no") << endl; 
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<stack>
using namespace std;
int main(){
	while(1){
		bool flag=true;
		string str;
		stack<int> num;
		getline(cin,str);
		if(str==".")	break;
		for(int i=0;i<str.size();i++){
			if(str[i]=='[')	num.push(1);
			else if(str[i]==']'){
				if(num.top()==1)	num.pop();
				else{
						flag=false;
						break;
				}
			}
			else if(str[i]==')'){
				if(num.top()==2)	num.pop();
				else{
						flag=false;
						break;
				}
			}
			else if(str[i]=='(')	num.push(2);
			
		}
		if(num.size()==0&&flag)	cout << "yes\n";
		else	cout << "no\n";
	}
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

string s;

int main(){
	while (getline(cin, s)){
		if (s == ".")break;
		bool f = 1, g = 0;
		vector<char> vc;
		vc.clear();
		REP(i, s.size()){
			if (s[i] == '('){
				vc.push_back(s[i]);
				g = 1;
			}
			if (s[i] == '['){
				vc.push_back(s[i]);
				g = 1;
			}
			if (s[i] == ')'){
				if (!vc.empty()){
					if (vc[vc.size() - 1] == '[')f = 0;
					else vc.pop_back();
				}
			}
			if (s[i] == ']'){
				if (!vc.empty()){
					if (vc[vc.size() - 1] == '(')f = 0;
					else vc.pop_back();
				}
			}
		}
		if (vc.empty() && f&&g)cout << "yes" << endl; 
		else cout << "no" << endl;
	}
}