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 <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <iomanip>
#include <cassert>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true){
        char s[128];
        if(scanf("%[^.]", s) == EOF) break;
        int len = strlen(s);
        bool ok = true;
        stack<char> left_br;
        for(int i = 0; i < len; i++){
            if(s[i] == '('){
                left_br.push('(');
            }else if(s[i] == ')'){
                if(left_br.empty() || left_br.top() != '('){
                    ok = false;
                    break;
                }
                left_br.pop();
            }else if(s[i] == '['){
                left_br.push('[');
            }else if(s[i] == ']'){
                if(left_br.empty() || left_br.top() != '['){
                    ok = false;
                    break;
                }
                left_br.pop();
            }
        }
        if(ok){
            puts("yes");
        }else{
            puts("no");
        }
        scanf("%[\n.]");
    }
    return 0;
}

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

int main() {
	string a;
	while (getline(cin,a),a!=".") {
		vector<int>s;
		for (int b = 0; b < a.length(); b++) {
			if (a[b] == '(' || a[b] == '[') { s.push_back(a[b]); }
			else if (a[b] == ')') {
				if (s.size() == 0 || s[s.size() - 1] !='(') { goto l; }
				s.pop_back();
			}
			else if (a[b] == ']') {
				if (s.size() == 0 || s[s.size() - 1] != '[') { goto l; }
				s.pop_back();
			}
		}
		if (s.size() != 0)goto l;
		cout << "yes" << endl;
		goto r;
	l:;
		cout << "no" << endl;
	r:;
	}
}

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

using namespace std;

int main(){
  string str;
 
  while ( 1 ){
    string s = "yes";
    getline( cin, str );
    if ( str[0] == '.' ) break;
    stack<char> sta;
    for ( int i = 0; str[i] != '\0'; i++ ){
      if ( str[i] == '(' || str[i] == '[' ){
        sta.push( str[i] );
      }else if ( str[i] == ')' ){
        if ( sta.top() == '(' ){
          sta.pop();
	}else{
	  s = "no";
	  break;
	}
      }else if ( str[i] == ']' ){
        if ( sta.top() == '[' ){
          sta.pop();
        }else{
	  s = "no";
	  break;
	}
      }
    }
    if ( !sta.empty() ) s = "no";
    cout << s << endl;
  }
}

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

int main(){

  string str,z;

  while(1){

    stack < string > a;
    int count = -1;
    z = "0";

    getline(cin,str);

    if(str == ".") break;

    for(int i=0;i<str.size();i++){

      if((a.size() == 0 && str[i] == ')') || (a.size() == 0 && str[i] == ']')){
	count = 0;
        break;
      }
      if(str[i] == '('){
	a.push("1");
	z = a.top();
      }
      else if(str[i] == '['){
	a.push("2");
	z = a.top();
      }
      else if((z == "1" || z == "0") && str[i] == ')'){
	a.pop();
	z = "0";
      }
      else if((z == "2" || z == "0") && str[i] == ']'){
	a.pop();
	z = "0";
      }
      else if(z == "1" && str[i] == ']'){
	count = 0;
	break;
      }
      else if(z == "2" && str[i] == ')'){
	count = 0;
	break;
      }
      else if(str[i] == ')'){
	count = 0;
	break;
      }
      else if(str[i] == ']'){
	count = 0;
	break;
      }
   
    }
    

    if(count == 0) cout << "no" << endl;
    else cout << "yes" << endl;
  }
}

C++: #define _USE_MATH_DEFINES
#define INF 100000000

#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;

static const double EPS = 1e-8;

int main(){
	string str;
	while(getline(cin,str)){
		if(str==".") break;
		stack<char> stk;
		string res = "yes";
		for(int i=0;i<str.size();i++){
			if(str[i]=='(') stk.push('(');
			if(str[i]=='[') stk.push('[');

			if(str[i]==')'){
				if(!stk.empty() && stk.top() != '(') res = "no";
				else if(stk.empty()) res = "no";
				else stk.pop();
			}

			if(str[i]==']'){
				if(!stk.empty() && stk.top() != '[') res = "no";
				else if(stk.empty()) res = "no";
				else stk.pop();
			}

		}

		cout << res << endl;
	}
}

C++: #include<iostream>
#include<cstring>
#include<vector>
using namespace std;

int main()
{

  for(;;)
    {
      char n[200];
      cin.getline(n,sizeof(n));
      if(n[0]=='.')
	break;
      bool check=true;
      int cnt1=0;
      int cnt2=0;
      string buf;
      int in=0;
      for(int i=0;n[i]!='.';i++)
	{
	  if(n[i]=='(')
	    {
	      cnt1++;
	      buf[in]=n[i];
	      in++;
	    }
	  if(n[i]=='[')
	    {
	      cnt2++;
	      buf[in]=n[i];
	      in++;
	    }
	  if(n[i]==')')
	    {
	      cnt1--;
	      in--;
	      if(in<0||buf[in]!='(')
		check=false;
	    }
	  if(n[i]==']')
	    {
	      cnt2--;
	      in--;
	      if(in<0||buf[in]!='[')
		check=false;
	    }
	  
	  if(cnt1<0||cnt2<0)
	    check=false;
	}
      
      if(check)
	cout<<"yes"<<endl;
      else
	cout<<"no"<<endl;
    }
}

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 <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)


int main() {
	string s;
	while (cin >> s && s != ".") {
		using P = pair<char, int>;
		queue<P> que;
		que.emplace('a', -1);
		bool ok = true;
		for (char c : s) {
			if (c == '('){ if(que.front().first == '(') que.front().second++; else que.emplace('(', 1); }
			if (c == ')'){ if(que.front().first == ')') que.front().second--; else ok = false; }
			if (c == '{'){ if(que.front().first == '{') que.front().second++; else que.emplace('{', 1); }
			if (c == '}'){ if(que.front().first == '}') que.front().second--; else ok = false; }
			if (que.front().second == 0) que.pop();
		}
		cout << (ok && que.size() == 1 ? "yes" : "no") << endl;
	}
}