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;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

string s;

int check(string x, int lr) {
    int xlen = x.length();
    int now = 0;
    while(now < xlen) {
        // cout << "now " << now << endl;
        if(x[now] == '(' || x[now] == '[') {
            int ch = -1;
            if(x[now] == '(') ch = 0;
            else ch = 1;
            int res = check(x.substr(now+1, xlen-now+1), ch);
            if(res == -1) return -1;
            else now += (res+1);
        }else if(x[now] == ')' || x[now] == ']') {
            if(lr == 0) {
                if(x[now] == ')') return now;
                else return -1;
            }else if(lr == 1) {
                if(x[now] == ']') return now;
                else return -1;
            }else return -1;
        }
        now++;
    }
    if(lr == -1) return now;
    else return -1;
}

int main() {
    while(1) {
        getline(cin, s);
        if(s == ".") break;
        int ans = check(s, -1);
        if(ans == -1) cout << "no" << endl;
        else cout << "yes" << endl;
    }
}

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

bool balance(std::string &input) {
  std::stack<char> sc;
  for (auto ch : input) {
    if (ch == '[' || ch == '(') sc.push(ch);
    else if (ch == ']' || ch == ')') {
      if (!sc.empty()) {
        char p = sc.top();
        sc.pop();
        if ((ch == ']' && p != '[') || (ch == ')' && p != '(')) return false;
      } else return false;
    }
  }
  return sc.empty();
}

int main()
{
  std::string input;
  while (std::getline(std::cin, input) && input != ".") {
    if (balance(input)) std::cout << "yes";
    else std::cout << "no";
    std::cout << std::endl;
  }
  return 0;
}

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

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

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

std::string str;

bool calc(int p){
	for(int i=p+1;i<str.size();i++){
		if(str[i]=='('){
			if(calc(i))return true;
			else return false;
		}
		if(str[i]==')'){
			if(str[p]=='(')return true;
			else return false;
		}
		if(str[i]=='['){
			if(calc(i))return true;
			else return false;
		}
		if(str[i]==']'){
			if(str[p]=='[')return true;
			else return false;
		}
	}
	return false;
}

int main(){
	while(1){
		int l=0,l2=0;
		std::getline(std::cin,str);
		while(1){
			if(str[str.size()-1]=='.')break;
			else{
				std::string a;
				std::getline(std::cin,a);
				str=str+a;
			}
		}
		if(str==".")break;
		for(int i=0;i<str.size();i++){
			if(str[i]=='(')l++;
			if(str[i]==')')l--;
			if(str[i]=='[')l2++;
			if(str[i]==']')l2--;
			if(l<0||l2<0){
				std::cout<<"no"<<std::endl;
				goto end;
			}
			if(str[i]=='('||str[i]=='['){
				if(!calc(i)){
					std::cout<<"no"<<std::endl;
					goto end;
				}
			}
		}
		if(l==0&&l2==0)std::cout<<"yes"<<std::endl;
		else std::cout<<"no"<<std::endl;
		end:;
	}
	return 0;
}

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

int main() {
    string s;
    while (getline(cin, s) , s != ".") {
        stack<char> v;
        bool flag = true;
        for (int i = 0; i < s.size() && flag; i++) {
            if (s[i] == '(' || s[i] == '[') v.push(s[i]);
            else if (s[i] == ')' && v.size() && v.top() == '(') v.pop();
            else if (s[i] == ']' && v.size() &&  v.top() == '[') v.pop();
            else if (s[i] == ')' || s[i] == ']') flag = false;
        }

        if (flag && v.size() == 0) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}

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

using namespace std;

string s;
vector<bool> out;

int main(){
	do{
		s.clear();
		do{
			string temp;
			getline(cin,temp);
			s+=temp;
		}while(s[s.length()-1]!='.');
		if (s.length()!=1){
			stack<bool> st;	//(=0,[=1;
			int i=0,l=s.length();
			for (;i<l;i++){
				if (s[i]=='('){
					st.push(0);
				}
				else if (s[i]=='['){
					st.push(1);
				}
				else if (s[i]==')'){
					if (st.empty()){
						out.push_back(false);
						break;
					}
					int type=st.top();
					st.pop();
					if (type!=0){
						out.push_back(false);
						break;
					}
				}
				else if (s[i]==']'){
					if (st.empty()){
						out.push_back(false);
						break;
					}
					int type=st.top();
					st.pop();
					if (type!=1){
						out.push_back(false);
						break;
					}
				}
			}
			if (i==l){
				if (st.empty()){
					out.push_back(true);
				}
				else{
					out.push_back(false);
				}
			}
		}
	}while(s.length()!=1);
	for (int i=0;i<out.size();i++){
		printf("%s\n",out[i] ? "yes" : "no");
	}
	return 0;
}

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

void solve(string s){
    stack<char> stk;
    for(char c:s){
        if(c=='('){
            stk.push('(');
        }
        if(c=='['){
            stk.push('[');
        }
        if(c==')'){
            if(!stk.empty()&&stk.top()=='(')stk.pop();
            else {cout<<"no"<<endl;return;}
        }
        if(c==']'){
            if(!stk.empty()&&stk.top()=='[')stk.pop();
            else {cout<<"no"<<endl;return;}
        }
    }
    if(!stk.empty())cout<<"no"<<endl;
    else cout<<"yes"<<endl;
}

int main (){
    string s;
    while(getline(cin,s),s[0]!='.'&&s.size()!=1){
        solve(s);
    }
}