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 <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
 

int main(){
	string s;
	while(getline(cin,s)){
		if(s==".") break;
		stack<char> st;
		bool flag = true;
		for(char c : s){
			if(c == '(' || c == '[') st.push(c);
			else if(c ==')' || c == ']') {
				if(st.empty() || (c != st.top() + (c == '('?1:2))){
					flag =false;
					break;
				}
				st.pop();
			} 
		}
		cout<<(flag?"yes":"no")<<endl;
	}
}

C++: #include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1
#define pb push_back

using namespace std;

int main() {
  string s;
  bool flag;
  while (getline(cin, s), s != ".") {
    flag = true;
    stack<char> kakko;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '(' || s[i] == '[') {
        kakko.push(s[i]);
      }
      if (s[i] == ')') {
        if (kakko.empty() || kakko.top() != '(') {
          flag = false;
          break;
        }
        kakko.pop();
      }
      if (s[i] == ']') {
        if (kakko.empty() || kakko.top() != '[') {
          flag = false;
          break;
        }
        kakko.pop();
      }
    }
    if (!kakko.empty()) flag = false;
    if (flag) cout << "yes" << el;
    else cout << "no" << el;
  }
}

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

using namespace std;

bool solve(string S)
{
	stack<char> s;

	for (int i = 0; i < S.size(); i++)
	{
		if (S[i] == '(' || S[i] == '[')
		{
			s.push(S[i]);
		}

		if (S[i] == ')' || S[i] == ']')
		{
			if (s.top() != (S[i] == ')' ? '(' : '['))
			{
				return false;
			}
			
			s.pop();
		}
	}

	return s.empty();
}

int main()
{
	string S;

	while (true)
	{
		cin >> S;

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

		cout << (solve(S) ? "yes" : "no") << endl;
	}
	
	return 0;
}

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

int main(){
  char ch;
  int f1=0,f2=0;

  while(1){
    stack<int> S1,S2;
    f1=f2=0;
    scanf("%c",&ch);
    int i=0;
    bool flag1=0,flag2=0;
    if(ch=='.')break;
    while(1){
      if(i!=0) cin>>ch;

      if(ch=='.') break;
      if(ch=='('){
	S1.push(i);
	if(f2==1) f1=2;
	else f1=1;
      }else if(ch==')'&&f1==0&&S1.size()<=0) flag1==1;
      else if(ch==']'&&f2==0&&S2.size()<=0)flag2==1;    
      else if(ch==')'&&S1.size()>0&&f2!=2){
	S1.pop();
	f1=0;
      }else if(ch=='['){
	S2.push(i);
	if(f1==1)f2=2;
	else f2=1;
      }else if(ch==']'&&S2.size()>0&&f1!=2){
	S2.pop();
	f2=0;
      }
      i++;
    }
    if(S1.size()==0&&S2.size()==0&&flag1!=1&&flag2!=1) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    scanf("%c",&ch);
  }
  
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <fstream>
#include <set>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>
#include <sstream>
#include <list>
#include <map>
#include <functional>
#include <iterator>

#define rep(i,p,n) for(int i=(int)p;i<(int)n;i++)
#define repp(i,p,n) for(int i=(int)p;i>=(int)n;i--)
#define Sort(x) sort(x.begin(),x.end())
#define PSort(x) sort(begin(x), end(x), pairCompare)
#define ll long long
#define INF 2000000000
#define pb push_back
#define mp make_pair
#define PI 3.14159265358979

using namespace std;

int main() {
	while (1) {
		stack<char> st;
		string s;
		getline(cin, s);

		bool start = true;
		bool f = false;
		if (s == ".") {
			break;
		}

		bool judge = true;
		rep(i, 0, s.length()) {
			if (s[i] == '(' || s[i] == '[' || s[i] == ']' || s[i] == ')') {
				judge = false;
			}
		}
		if (judge) {
			cout << "yes" << endl;
			continue;
		}
		rep(i, 0, s.length()) {
			if (s[i] == '(') {
				if (start) {
					start = false;
				}
				st.push('(');
			}
			else if (s[i] == '[') {
				if (start) {
					start = false;
				}
				st.push('[');
			}
			else if (s[i] == ')') {
				if (!st.empty()) {
					if (st.top() != '(') {
						break;
					}
					else st.pop();
				}
				else {
					f = true;
					break;
				}
			}
			else if (s[i] == ']') {
				if (!st.empty()) {
					if (st.top() != '[') {
						break;
					}
					else st.pop();
				}
				else {
					f = true;
					break;
				}
			}
		}
		if (st.empty() && !f)cout << "yes" << endl;
		else cout << "no" << endl;
	}

	

	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
 
using namespace std;
 
#define ll long long
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pii pair<int,pi>
#define X first
#define Y second
#define pb push_back
#define ab(x) ((x)<0?(-(x)):(x))
#define xx(x) ((x)*(x))
#define mp make_pair
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vpi vector<pi>
#define vpll vector<pll>
#define ALL(x) (x).begin(),(x).end()
#define Max (1<<30)
#define LLMax (1ll<<60)
template<class T>string ToString(T t){stringstream s;s<<t;return s.str();}
template<class T>void ToOther(T&t,string a){stringstream s(a);s>>t;}
 
char a[10005];
int main(){
	while(1){
		gets(a);
		string t=a;
		if(t==".")break;

		bool no=0;
		stack<char> st;
		for(int i=0;i<t.size();i++){
			if(t[i]=='('){
				st.push(')');
			}
			if(t[i]=='['){
				st.push(']');
			}

			if(t[i]==')'){
				if(st.size()==0 || st.top()!=t[i]){
					no=1;break;
				}
				st.pop();
			}
			if(t[i]==']'){
				if(st.size()==0 || st.top()!=t[i]){
					no=1;break;
				}st.pop();
			}
		}
		if(st.size())no=1;
		cout<<(no?"no":"yes")<<endl;
	}
}