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>

// Shrotening
#define fst first
#define snd second
#define pb push_back
#define mp std::make_pair

// Loop
#define FOR(i,a,b) for(auto i=(a);i<(b);++i)
#define RFOR(i,a,b) for(auto i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::pair<int,int> PII;

typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;
typedef std::vector<PII> VPII;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

std::string s;
int main() {
    while(std::getline(std::cin, s)) {
        if(s == ".") break;
        
        std::stack<char> stack;
        bool f = true;
        for(auto c: s) {
            if(c == '(' || c == '[') {
                stack.push(c);
            } else if(c == ')' || c == ']') {
                if(stack.empty()) {
                    f = false;
                    break;
                }

                char left = stack.top();
                stack.pop();
                if( (left == '(' && c == ')') || (left == '[' && c == ']') ) {
                    continue;
                } else {
                    f = false;
                    break;
                }
            }
        }

        std::cout << ( (f && stack.empty()) ? "yes" : "no") << std::endl;
    }
}

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();
                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;
}

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

int main()
{
    for(;;){
        string s;
        getline(cin, s);
        if(s == ".")
            return 0;

        int n = s.size();
        stack<char> stk;
        bool ng = false;
        for(int i=0; i<n; ++i){
            if(s[i] == '(')
                stk.push(s[i]);
            if(s[i] == '[')
                stk.push(s[i]);
            if(s[i] == ')'){
                if(stk.size() == 0 || stk.top() != '('){
                    ng = true;
                    break;
                }
                stk.pop();
            }
            if(s[i] == ']'){
                if(stk.size() == 0 || stk.top() != '['){
                    ng = true;
                    break;
                }
                stk.pop();
            }
        }

        if(!ng && stk.empty())
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
}

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

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back


int main(){
    string s;
    while(getline(cin,s)){
        stack<char> data;
        while(data.size())data.pop();
        if(s==".")break;

        rep(i,s.size()){
            if(s[i]=='[')data.push('[');
            if(s[i]=='(')data.push('(');
            if(s[i]==']'){
                if(data.size() && data.top()=='[')data.pop();
                else{
                    cout<<"no"<<endl;
                    break;
                }
            }
            if(s[i]==')'){
                if(data.size() && data.top()=='(')data.pop();
                else{
                    cout<<"no"<<endl;
                    break;
                }
            }
            if(i==s.size()-1)
                if(data.empty()) cout<<"yes"<<endl;
                else cout<<"no"<<endl;
        }
    }
    return 0;
}