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;

int main() {
	string s;
	while(getline(cin, s)) {
		stack<char> st;
		bool f = true;
		if(s == ".") {
			break;
		}
		for(auto &c : s){
			if(c == '(' || c == '[') {
				st.push(c);
			}
			else if(c == ')' || c == ']') {
				if(st.size() == 0) {
					f = false;
					break;
				}
				char t = st.top();
				if((t == '(' && c == ')') || (t == '[' && c == ']')) {
					st.pop();
				}
				else {
					f = false;
					break;
				}
			}
		}
		f = f && (st.size() == 0);
		cout << (f ? "yes" : "no") << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
char s[1000];
stack<int> last;
int main(){
	while(1) {
		fgets(s,500,stdin);
		int n = strlen(s);
		n--;
		if(n == 1 && s[0] == '.') {
			break;
		}



		bool f = true;int rb = 0,sb = 0;
		REP(i,n) {
			if(!last.empty() && last.top() == 0 && s[i] == ']') {
				f = false;
				break;
			}
			if(!last.empty() && last.top() == 1 && s[i] == ')') {
				f = false;
				break;
			}
			if(s[i] == ')') {
				rb--;
				last.pop();
				if(rb < 0) {
					f = false;
					break;
				}
			}
			if(s[i] == ']') {
				sb--;
				last.pop();
				if(sb < 0) {
					f = false;
					break;
				}
			}
			if(s[i] == '(')  {
				rb++;
				last.push(0);
			}
			if(s[i] == '[')  {
				sb++;
				last.push(1);
			}
		}
		if(f) {
			cout << "yes" << endl;
		}else {
			cout << "no" << endl;
		}
	}
	return 0;
}

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

using namespace std;

void solve()
{
	string temp;
	string str;
	while(getline(cin, temp))
	{
		str += temp;
		if(str.size() == 1 && str[0] == '.')
		{
			break;
		}
		if(str[str.size() - 1] == '.')
		{
			bool ok = true;
			stack<int> Stack;
			int n = str.size();
			for(int i = 0; i < n; ++i)
			{
				if(str[i] == '(')
				{
					Stack.push(1);
				}
				else if(str[i] == '[')
				{
					Stack.push(2);
				}
				else if(str[i] == ')')
				{
					if(Stack.empty() || Stack.top() == 2)
					{
						cout << "no" << endl;
						ok = false;
					}
					else if(Stack.top() == 1)
					{
						Stack.pop();
					}
				}
				else if(str[i] == ']')
				{
					if(Stack.empty() || Stack.top() == 1)
					{
						cout << "no" << endl;
						ok = false;
					}
					else if(Stack.top() == 2)
					{
						Stack.pop();
					}
				}
			}
			if(ok)
			{
				cout << "yes" << endl;
			}
			str.clear();
		}
END:
		;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <stack>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)

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

string solve(string str)
{
	stack<char> stk;
	char ascii[256];
	ascii[']'] = '[';
	ascii[')'] = '(';

	rep(i, str.size()) {
		if (str[i] == '[' || str[i] == '(')
			stk.push(str[i]);
		if (str[i] == ']' || str[i] == ')') {
			if (stk.size() == 0)
				return "no";
			char ch = stk.top(); stk.pop();
			if (ch != ascii[str[i]])
				return "no";
		}
	}

	return stk.size()==0?"yes":"no";
}

int main(void)
{
	string s;
	for (;;) {
		getline(cin, s);
		if (s[0] == '.') break;

		cout << solve(s) << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <cstdio>
#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
using namespace std;
int main()
{
	string str; while (getline(cin, str) && str[0] != '.' && str.size() != 1)
	{
		int id = 0;
		stack<int> stck;
		rep(i, (int)str.size())
		{
			switch (str[i])
			{
				case '(':	stck.push(1);	break;
				case '[': stck.push(2); break;
				case ')': 
					if (stck.size() == 0) { id = 1; }
					else if (stck.top() == 1) { stck.pop(); }
					else { id = 1; } break;
				case ']': 
					if (stck.size() == 0) { id = 1; }
					else if (stck.top() == 2) { stck.pop(); }
					else { id = 1; } break;
			}
		}
		if (id == 1) { printf("no\n"); }
		else { printf("yes\n"); }
	}
	return 0;
}

C++: 

#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <queue>
#include <map>
#include <stack>
using namespace std;
 
int dx[8]={1,-1,0,0,1,1,-1,-1};
int dy[8]={0,0,1,-1,-1,1,-1,1};
 
 
int main() {
string s;
	while(getline(cin,s)){
//		cout<<s<<endl;
		if(s==".") break;
	int ans=1;
	int l=s.length();
	stack<int> st; 
	for(int i=0;i<l;i++){
		if(s[i]=='(') st.push(1);
		else if(s[i]=='[') st.push(2);
		else if(s[i]==')'){
		if(st.empty()==true){
		ans=0;
		break;		
		}
		if (st.top()==1){
		st.pop();		
		}
		else{
		ans=0;
		break;
		}
		}

else if(s[i]==']'){
if(st.empty()==true){
		ans=0;
		break;		
		}
		if (st.top()==2){
		st.pop();		
		}
		else{
		ans=0;
		break;
		}
}
		}
	if(ans==1 && st.empty()==true) cout<<"yes"<<endl;
	else cout<<"no"<<endl;
	}


	return 0;
 
   }

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

using namespace std;

int main(void){
  char r[1000000];
  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;
    else if(s=='('){
      r[count++]=')';
      maru++;
    }
    else if(s=='['){
      r[count++]=']';
      shikaku++;
    }
    else if(s==')'){
  	maru=-111;

    }
    else if(s==']'){
      shikaku=-111;
    }
    //終了条件ではないとき
    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=-111;
      }
      else if(c==']'){
	if(r[count-1]==c){
	  count--;
	  shikaku--;
	}
	else shikaku=-111;
      }
    }
   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;
}