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() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  while (true) {
    getline(cin, s);
    if (s == ".") {
      break;
    }
    bool b = [&] {
      string t;
      for (char c : s) {
        if (c == '(' or c == '[') {
          t += c;
        }
        if (c == ')') {
          if (t.empty() or t.back() != '(') {
            return false;
          }
          t.pop_back();
        }
        if (c == ']') {
          if (t.empty() or t.back() != '[') {
            return false;
          }
          t.pop_back();
        }
      }
      return t.empty();
    }();
    cout << (b ? "yes\n" : "no\n");
  }
}

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

int main(){
  char c[101];
  while(cin.getline(c, sizeof(c))&&c[0]!='.'){
    char a[101];
    int j=0;
    for(int i=0;i<102;i++){
      if(c[i]=='('||c[i]==')'||c[i]=='['||c[i]==']'){
        a[j]=c[i];
        if((a[j-1]=='('&&a[j]==')')||(a[j-1]=='['&&a[j]==']')){
          a[j-1] = '\0';
          a[j] = '\0';
          j--;
        }else{
          j++;
        }
      }
    }

    //  cout << a << endl;
    if(j==0) cout << "yes" << endl;
    else cout << "no" << endl;
    // initialize
    for(int i=0;i<102;i++){
      a[i] = '\0';
      c[i] = '\0';
    }
  }

  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==')'&S1.size()<=0) flag1==1;
      else if(ch==']'&&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++: #include <bits/stdc++.h>
using namespace std;

int main(){
	stack<int>st;
	string s;
	while(1){
		cin>>s;
		if(s==".") return 0;
		for(int i=0;i<s.size();i++){
			if(s[i]=='(') st.push(0);
			if(s[i]=='[') st.push(1);
			if(s[i]=='('){
				int num=st.top();
				if(num==0){
					st.pop();
				}
			}
			if(s[i]==']'){
				int num=st.top();
				if(num==1){
					st.pop();
				}
			}
		}
		if(st.empty()) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}

C++: //
//  main.cpp
//  AOJ1173
//
//  Created by aki33524 on 2014/07/09.
//  Copyright (c) 2014年 aki33524. All rights reserved.
//

#include <iostream>
#include <string>
#include <stack>
using namespace std;

string S;

void solve(){
    stack<char> st;
    for(int i=0; i<S.size(); i++){
        char c = S[i];
        if(c != '(' && c != ')' && c != '[' && c != ']')
            continue;
        
        if(c == '(' || c == '[')
            st.push(c);
        else if(c == ')' || c == ']'){
            if(st.empty()){
                cout << "no" << endl;
                return;
            }else if((st.top() == '(' && c == ']') || (st.top() == '[' && c == ')')){
                cout << "no" << endl;
                return;
            }
            st.pop();
        }
    }
    cout << (st.empty() ? "yes" : "no") << endl;
}

int main(int argc, const char * argv[])
{
    while(getline(cin, S), S!="."){
        solve();
    }
    return 0;
}

C++: // AOJ 1173

#include <iostream>
#include <string>
#include <stack>
using namespace std;

int main(void)
{
	while (1){
		string str;
		getline(cin, str);
		if (str == "."){
			break;
		}
		
		stack <char> st;
		bool flag = true;
		for (int i = 0; i < str.length(); i++){
			if (str[i] == '(' || str[i] == '['){
				st.push(str[i]);
			}
			if (str[i] == ')'){
				if (st.size() == 0 || st.top == '['){
					flag = false;
				}
				else if (st.top() == '('){
					st.pop();
				}
			}
			if (str[i] == ']'){
				if (st.size() == 0 || st.top == '('){
					flag = false;
				}
				else if (st.top() == '['){
					st.pop();
				}
			}
		}
		if (st.size() == 0 && flag){
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
	
	return 0;
}

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

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

C++: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void load(vector<string>& datas){
    while(1){
        string str;
        while(1){
            char word;
            if(!cin){
                datas.pop_back();
                return;
            }
            cin >> word;
            str += word;
            if(word == '.') break;
        }
        datas.push_back(str);
    }
}



int main()
{
    vector<string> datas;
    
    load(datas);
    
    for(auto data: datas){
        vector<bool> brackets;
        
        for(auto itr = data.begin(); itr != data.end(); itr++){
            if(*itr == '[') brackets.push_back(true);
            else if(*itr == '(') brackets.push_back(false);
            else if(*itr == ']' && brackets.size()) {
                if(brackets.back() == true) 
                    brackets.pop_back();
            }
            else if(*itr == ')' && brackets.size()) {
                if(brackets.back() == false) 
                    brackets.pop_back();
            }
        }
        if(brackets.size()) cout << "no" << endl;
        else cout << "yes" << endl;
    }
    
    return 0;
}