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;

#define INF 1e9

bool solve(char c1,char c2){
    if(c1=='(')return c2==')';
    else return c2==']';
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    while(1){
        string s;
        getline(cin,s);
        if(s==".")break;
        stack<char> st;
        bool ans=true;
        for(int i=0;i<s.size();i++){
            if(s[i]=='(' || s[i]=='[')st.push(s[i]);
            else if(s[i]==')' || s[i]==']'){
                if(st.empty())ans=false;
                else{
                    if(solve(st.top(),s[i])){
                        st.pop();
                    }
                    else{
                        ans=false;
                    }
                }
            }
        }
        if(ans)cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, 0};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin.ignore();
    while (true)
    {
        string s;
        getline(cin, s);
        if (s == ".")
        {
            break;
        }
        int n = s.size();
        stack<char> st;
        bool flg = true;

        for (int i = 0; i < n; i++)
        {
            if (s[i] == '(' || s[i] == '[')
            {
                st.push(s[i]);
            }
            if (s[i] == ')')
            {
                if (st.empty())
                {
                    flg = false;
                    break;
                }
                char tmp = st.top();
                st.pop();
                if (tmp != '(')
                {
                    flg = false;
                    break;
                }
            }
            if (s[i] == ']')
            {
                if (st.empty())
                {
                    flg = false;
                    break;
                }
                char tmp = st.top();
                st.pop();
                if (tmp != '[')
                {
                    flg = false;
                    break;
                }
            }
        }

        if (!st.empty())
        {
            flg = false;
        }

        if (flg)
        {
            cout << "yes" << endl;
        }
        else
        {
            cout << "no" << endl;
        }
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;

int main(void) {
	string str;
	while (getline(cin, str), str != ".") {
		bool hasBalance = true;
		stack<int> sKako;
		for (int i = 0; i < str.size(); i++) {
			if (str[i] == '(') {
				sKako.push(1);
			}else if (str[i] == ')') {
				if (sKako.empty()) {
					hasBalance = false;
					break;
				}
				if (sKako.top() != 1) {
					hasBalance = false;
					break;
				}
				sKako.pop();
			}else if( str[i] == '[') {
				sKako.push(2);
			}else if (str[i] == ']') {
				if (sKako.empty()) {
					hasBalance = false;
					break;
				}
				if (sKako.top() != 2) {
					hasBalance = false;
					break;
				}
				sKako.pop();
			}
		}

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

	return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

void solve(){
    string str;
    while(getline(cin,str)){
        if(str==".") break;
        stack<char> stk;
        bool ok=true;
        for(char ch:str){
            if(ch=='(') stk.push(ch);
            if(ch=='[') stk.push(ch);
            if(ch==')'){
                if(!stk.empty() and stk.top()=='(') stk.pop();
                else ok=false;
            }
            if(ch==']'){
                if(!stk.empty() and stk.top()=='[') stk.pop();
                else ok=false;
            }
            if(!ok) break;
        }
        if(!stk.empty()) ok=false;

        if(ok) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	solve();
	return 0;
}

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

using namespace std;

#define MAX 128

int main(void) {
	while(1) {
		string str;
		bool balance = true;
		stack<char> sbracket;

		getline(cin, str);
		if(str == ".") break;
		for(int i = 0; str[i] != '.'; i++) {
			if(str[i] == '(' || str[i] == '[') {
				sbracket.push(str[i]);
			}
			if(str[i] == ')') {
				if(sbracket.size() == 0 || sbracket.top() != '(') {
					balance = false;
					break;
				}
				sbracket.pop();
			}
			if(str[i] == ']') {
				if(sbracket.size() == 0 || sbracket.top() != '[') {
					balance = false;
					break;
				}
				sbracket.pop();
			}
		}
		if(sbracket.size() != 0) balance = false;
		printf(balance ? "Yes\n" : "No\n");
	}
	return 0;
}

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

const string C = "[]()";

int main() {
  for(string s; getline(cin, s) && s != ".";) {
    try {
      stack<int> stk;
      for(int i = 0; i < s.size(); ++i) {
        int p = C.find(s[i]);
        if(p == string::npos) continue;
        if(p % 2 == 0) {
          stk.push(p);
        } else {
          if(stk.empty() || stk.top() != p-1) {
            throw "no";
          }
          stk.pop();
        }
      }
      if(stk.size()) throw "no";
      throw "yes";
    } catch(const char *res) {
      cout << res << endl;
    }
  }
  return 0;
}