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(void){
    string s;
    while(getline(cin,s),s!="."){
        stack<int> b;
        bool isBn=true;
        for(auto c : s){
            if(c=='(') b.push(1);
            if(c=='[') b.push(2);
            if(c==')'){
                if(!b.empty() && b.top()==1){
                    b.pop();
                }else{
                    isBn=false;
                    break;
                }
            }
            if(c==']'){
                if(!b.empty() && b.top()==2){
                    b.pop();
                }else{
                    isBn=false;
                    break;
                }
            }
        }
        if(isBn==false || !b.empty()){
            cout<<"no"<<endl;
        }else{
            cout<<"yes"<<endl;
        }
    }
}

C++: #include <bits/stdc++.h>
using namespace std;

bool solve(string S) {
    vector<char> v;
    for (auto c : S) {
        if (c == '(') {
            v.push_back('(');
        }
        if (c == '[') {
            v.push_back('[');
        }
        if (c == ')') {
            if (v.size() == 0) return false;
            if (v[v.size() - 1] != '(') {
                return false;
            }
            v.pop_back();
        }
        if (c == ']') {
            if (v.size() == 0) return false;
            if (v[v.size() - 1] != '[') {
                return false;
            }
            v.pop_back();
        }
    }
    if (v.size()) return false;
    return true;
}

int main() {
    while (true) {
        string S;
        getline(cin, S);
        if (S == ".") return 0;
        cout << (solve(S) ? "yes" : "no") << endl;
    }
}

C++: #include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

string solve(string s) {
    // queue<int> stack;
    stack<int> stack;
    bool flag = true;
    int check;

    for (int i = 0; i < s.length(); i++) {
        if (s[i] == '(')
            stack.push(1);
        else if (s[i] == '[')
            stack.push(2);
        if (s[i] == ')') {
            if (stack.empty()) return "no";
            check = stack.top();
            stack.pop();
            if (check != 1) {
                flag = false;
                break;
            }
        } else if (s[i] == ']' && !stack.empty()) {
            if (stack.empty()) return "no";
            check = stack.top();
            stack.pop();
            if (check != 2) {
                flag = false;
                break;
            }
        }
    }
    if (!stack.empty()) flag = false;
    if (flag) return "yes";
    return "no";
}

int main() {
    string st;
    vector<string> ans;
    while (1) {
        // cout << 1;
        getline(cin, st);
        // cout << 2;
        if (st == ".") break;
        // cout << 3;
        // cout << st << endl;
        ans.push_back(solve(st));
        // cout << 4;
    }
    for (auto k : ans) cout << k << endl;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

bool isLeap(int y);
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/



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


bool isLeap(int y)
{
	return y % 400 == 0
						? true : y % 100 == 0
						? false : y % 4 == 0
						? true : false;
}

ll gcd(ll a, ll b)
{
	return (b > 0) ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}

void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

C++: #include <iostream>
#include <string>
using namespace std;
int kakko(int ,string);
int main(){
  int n ,shou=0 ,chu=0;
  string s;
  while( 1 ){
    getline(cin ,s);
    n = s.size();
    if( s[0] == '.' ){
      break;
    }
    kakko(n ,s);
  }
}


int kakko(int n ,string s){
  int shou=0 ,chu=0;
  for( int i=0 ; i<n ; i++ ){
    switch(s[i]){ // ( ,[の数を求める
    case '(':
      shou++;
      break;
      
    case '[':
      chu++;
      break;

    case ')':
      shou--;
      break;
      
    case ']':
      chu--;
      break;
      
    default:
      continue;
      break;
    }
    
    if( shou < 0 || chu < 0 ){ 
      cout << "no" << endl;
      return 0;
    }
  }
  
  if( shou == 0 && chu == 0 ){ // 対応してたら
    cout << "yes" << endl;
  }
  else{ // 対応してなかったら
      cout << "no" << endl;
  }
  return 0;
}

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

bool iscollect(string str){
	string::iterator fwd,last;
	stack<bool> list;
	bool ret=true;
	fwd=str.begin();
	last=str.end();
	while(fwd!=last){
		if(*fwd=='('){
			list.push(true);
		}else if(*fwd=='['){
			list.push(false);
		}else if(*fwd==')'){
			if(list.empty()||list.top()==false){
				ret=false;
				break;
			}
			list.pop();
		}else if(*fwd==']'){
			if(list.empty()||list.top()==true){
				ret=false;
				break;
			}
			list.pop();
		}
		++fwd;
	}
	if(!list.empty())ret=false;
	return ret;
}

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