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 <string>

using namespace std;

template<typename Iter>
Iter ss( Iter it, Iter const end, typename Iter::value_type c )
{
    for( ; it<end; ++it ) {
        if ( *it == c )
            return it;
        if ( *it == '(' )
            if ( (it = ss( it+1, end, ')' )) == end )
                break;
        if ( *it == '[' )
            if ( (it = ss( it+1, end, ']' )) == end )
                break;
    }
    return end;
}

template<typename Range>
bool ff( Range const& r )
{
    for( auto it=r.begin(); it<r.end(); ++it ) {
        if ( *it == '(' )
            if ( ss( it+1, r.end(), ')' ) == r.end() )
                return false;
        if ( *it == '[' )
            if ( ss( it+1, r.end(), ']' ) == r.end() )
                return false;
    }
    return true;
}



int main()
{
    string s;
    while( getline( cin, s ) ) {
        if ( s == "." )
            break;
        cout << ( ff( s ) ? "yes" : "no" ) << endl;
    }
}

C++: //
//  main.cpp
//  The Balance of the World
//
//  Created by x15071xx on 2017/06/16.
//  Copyright ?? 2017??´ AIT. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <string>
using namespace std;
int main(int argc, const char * argv[]) {
    
    
    while(1){
        string yn = "yes";
        string str;
        vector<char> st;
        getline(cin, str);
        
        
        if (str == ".") {
            break;
        }
        
        for (int i = 0;  i < str.size(); i++) {
            
            if (str[i] == '(' || str[i] == '[') {
                st.push_back(str[i]);
            }
            
            
            if (str[i] == ')') {
                
                if (st.empty()) {
                    yn = "no";
                    break;
                }
                if ('(' != st.back()) {
                    yn = "no";
                    break;
                }
                
                st.pop_back();
                
            }
            
            if (str[i] == ']') {
                
                if (st.empty()) {
                    yn = "no";
                    break;
                }
                
                if ('[' != st.back()) {
                    yn = "no";
                    break;
                }
                
                st.pop_back();
                
            }
    
        

        }
        
        if (!st.empty()) {
            yn = "no";
        }
        
        cout << yn << endl;
    }
    return 0;
}

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

int main(){
	string s;
	while(getline(cin, s)) {
		if(s == ".") break;
		vector<int> v(2);
		vector<int> tmp[2];
		bool f = true;
		for(auto& c: s) {
			if(c == '(') {
				v[0]++;
				tmp[0].push_back(v[1]);
			}
			if(c == ')') {
				if(v[0] == 0 || tmp[0].back() != v[1]) {
					f = false;
					break;
				}
				else {
					v[0]--;
					tmp[0].pop_back();
				}
			}
			if(c == '[') {
				v[1]++;
				tmp[1].push_back(v[0]);
			}
			if(c == ']') {
				if(v[1] == 0 || tmp[1].back() != v[0]) {
					f = false;
					break;
				}
				else {
					v[1]--;
					tmp[1].pop_back();
				}
			}
		}
		cout << (f ? "yes" : "no") << endl;
	}
}

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

using namespace std;

bool check(string str_f)
{
	if (str_f.empty() == 1)return true;
	for (unsigned int i = 0; i<str_f.length() ; i++)
	{
		if ((str_f[i] == '(' && str_f[i + 1] == ')') || (str_f[i] == '[' && str_f[i + 1] == ']'))
		{
			str_f.erase(str_f.begin() + i);
			str_f.erase(str_f.begin() + i);
			return check(str_f);         
		}
	}
	return false;
}

int main()
{
	while (true)
	{
		string str = "";
		string str_f = "";
		getline(cin, str);
		if (str[0] == '.')break;
		for (unsigned int i = 0; i < str.length(); i++)
		{
			if (str[i] == '(' ||
				str[i] == '[' ||
				str[i] == ')' ||
				str[i] == ']') str_f += str[i];
		}
		int a = str_f.length();
		if (a % 2 == 1)							
		{
			cout << "no" << endl;
			continue;
		}
		if (check(str_f))cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

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

int main(){

  string str;

  while(1){
    getline(cin, str);
    if(str[0] == '.') break;
    int flag = 1;
    stack<int> s;
    for(int i = 0; i < str.size(); i++){
      if(str[i] == '('){
        s.push(1);
      }else if(str[i] == '['){
        s.push(2);
      }else if(str[i] == ']'){
        if(!s.empty() && s.top() == 2){
          s.pop();
        }else{
          flag = 0;
          break;
        }
      }else if(str[i] == ')'){
        if(!s.empty() && s.top() == 1){
          s.pop();
        }else{
          flag = 0;
          break;
        }
      }
    }
    if(flag && s.empty()){
      cout << "yes" << endl;
    }else{
      cout << "no" << endl;
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define LOOP(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) LOOP(i, 0, n)
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359

int main(void) {
  vector<string> ans;
  while (true) {
    string s;
    getline(cin, s);
    if (s == ".")
      break;
    stack<int> st;
    bool flag = true;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '(')
        st.push(1);
      else if (s[i] == '[')
        st.push(2);
      else if (s[i] == ')') {
        if (!st.empty() && st.top() == 1)
          st.pop();
        else {
          ans.push_back("no");
          flag = false;
          break;
        }
      } else if (s[i] == ']') {
        if (!st.empty() && st.top() == 2)
          st.pop();
        else {
          ans.push_back("no");
          flag = false;
          break;
        }
      }
    }
    if (flag)
      ans.push_back("yes");
  }

  for(int i=0; i<ans.size(); i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

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

bool isbracket(char c)
{
    return (c == '[' || c == ']' || c =='(' || c == ')');
}


string rem(string str)
{
    string res;

    for(int i=0; i<str.size(); i++)
	if(isbracket(str[i])) res += str[i];

    return res;
    
}

bool solve(string in)
{
    string s = rem(in);
    stack<char> brackets;
    brackets.push('!');
    
    for(int i=0; i<s.size(); i++) {
	char c = s[i];

	if( c == '(' || c == '[' )
	    brackets.push(c);
	else {
	    if ( c == ')' && (brackets.top() != '(') ) return false;
	    if ( c == ']' && (brackets.top() != '[') ) return false;

	    brackets.pop();
	}
    }

    if ( brackets.size() != 1 ) return false;

    return true;
}

int main()
{
    string str;
    
    while(1) {
	getline(cin, str);

	if ( str.size() == 1 ) break;

	bool res = solve(str);

	cout << (res ? "yes" : "no") << endl;
    }
    
}