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 <stack>
#include <vector>
using namespace std;
int main()
{
	string str;
	while( getline(cin,str) && str != '.' ){
		string z;
		for(int i=0;i<str.size();i++)
			if(str[i] == '(' || str[i] == ')' || str[i] == '[' || str[i] == ']')
				z+=str[i];
		stack<char> s;
		bool f = true;
		for(int  i=0;i < z.length();i++){
			if( z.empty() || z[i] == '(' || z[i] == '[' ){
				s.push();
			}else if( (s.top() == '(' && z[i] == ')') || (s.top() == '[' && z[i] == ']') )
				s.pop();
			else{
				f = false;
				break;
			}
		}
		cout << (f && s.empty() ? "yes": "no")  << endl;
	}

	return 0;
}

C++: #include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	string s;
	while(getline(cin, s), s!="."){
		bool ok = true;
		int a = 0, b = 0;
		int state = 0;
		stack<char> st;
		rep(i,s.size()){
			if(s[i] == '('){
				st.push(s[i]);
			}
			else if(s[i] == ')'){
				if(st.empty() || st.top() != '('){
					ok=false;
				}
				else{
					st.pop();
				}
			}
			if(s[i] == '['){
				st.push(s[i]);
			}
			else if(s[i] == ']'){
				if(st.empty() || st.top() != '['){
					ok=false;
				}
				else{
					st.pop();
				}
			}
		}
		cout << (ok?"yes":"no") << endl;
	}
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

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

int main()
{
	string s;
	while (true)
	{
		getline(cin, s);
		if (s == ".")	break;

		stack<int> data, data2;
		
		for (auto && x : s)
		{
			if (x == '[')
				data.emplace(1);
			else if (x == ']')
			{
				if (data.empty())
				{
					cout << "no" << endl;
					goto END;
				}

				data.pop();
			}
			else if (x == '(')
				data2.emplace(data.size());
			else if (x == ')')
			{
				if (data2.empty())
				{
					cout << "no" << endl;
					goto END;
				}
				else if (data.size() != data2.top())
				{
					cout << "no" << endl;
					goto END;
				}
				data2.pop();
			}
		}

		if (data.empty() && data2.empty())
			cout << "yes" << endl;
		else
			cout << "no" << endl;

	END:;

	}

	return 0;
}

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


#define INPUT_MAX 101
#define KAKKO_MAX 49

using namespace std;

int main(void)
{
	int countMaru = 0;
	int countKaku = 0;
	int idx = 0;
	string stack(KAKKO_MAX, '\0');
	string dataset(INPUT_MAX, '\0');
	
	while(getline( cin, dataset))
	{
		if(dataset[0] == '.')
		{
			break;
		}
		for(int i = 0; i < INPUT_MAX; i++)
		{
			if(dataset[i] == '.')
			{
				if((countMaru == 0) && (countKaku == 0))
				{
					cout << "yes\n";
					break;
				}
				else
				{
					cout << "no\n";
					break;
				}
			}
			else if(dataset[i] == '(')
			{
				if(idx == KAKKO_MAX)
				{
					cout << "no\n";
					break;
				}
				countMaru++;
				stack[idx] = '(';
				idx++;
			}
			else if(dataset[i] == '[')
			{
				if(idx == KAKKO_MAX)
				{
					cout << "no\n";
					break;
				}
				countKaku++;
				stack[idx] = '[';
				idx++;
			}
			else if(dataset[i] == ')')
			{
				if(idx == 0)
				{
					cout << "no\n";
					break;
				}
				else if(stack[idx-1] == '[')
				{
					cout << "no\n";
					break;
				}
				else
				{
					idx--;
					stack[idx] = '\0';
					countMaru--;
				}
			}
			else if(dataset[i] == ']')
			{
				if(idx == 0)
				{
					cout << "no\n";
					break;
				}
				else if(stack[idx-1] == '(')
				{
					cout << "no\n";
					break;
				}
				else
				{
					idx--;
					stack[idx] = '\0';
					countKaku--;
				}
			}
			else
			{
				// 処理なし
			}
		}
		
		idx = 0;
		countMaru = 0;
		countKaku = 0;
	}
	
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){

  while(1){
	char hoge[200];
	int i = 0;
	while(1){
	  cin >> hoge[i];
	  if(hoge[i]=='.') break;
	  i++;
	}
	if(hoge[0]=='.') break;

	int mini = 0;
	int big = 0;

	REP(a,i){
	  if(hoge[a]=='('){
		mini++;
	  }else if(hoge[a]==')'){
		mini--;
	  }else if(hoge[a]=='['){
		big++;
	  }else if(hoge[a]==']'){
		big--;
	  }
	  if(mini < 0||big < 0) break;
	}

	if(mini==0&&big==0) cout << "yes" << endl;
	else cout << "no" << endl;
  }
}