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 <stdio.h>
#include <vector>
#include <fstream>

using namespace std;

bool iskakko(char c)	{
	if (c == '[' || c == ']' || c == '(' || c == ')')	return true;
	else	return false;
}

int main()	{
	char c[110];
	char temp;
	std::vector<int> v;
	bool legal;
	// bool miss;
	
	/*
	char tehon[5];
	FILE* fp;
	FILE* fp2;
	fp = fopen("out1.txt", "r");
	fp2 = fopen("misslist.txt", "w");
	*/
	
	while (true)	{
		fgets(c, 110, stdin);
		if (c[0] == '.')	break;
		
		v.clear();
		legal = true;
		// miss = false;
		
		for (int i = 0; c[i] != '\n'; i++)	{
			
			if (c[i] == '(')	{
				//printf("'('found\n");
				v.push_back('(');
				
			} else if (c[i] == '[')	{
				//printf("'['found\n");
				v.push_back('[');
				
			} else if (c[i] == ')')	{
				//printf("')'found\n");
				if (v.empty() || v.back() != '(')	{
					legal = false;
					break;
				} else	{
					v.pop_back();
				}
				
			} else if (c[i] == ']')	{
				//printf("']'found\n");
				if (v.empty() || v.back() != '[')	{
					legal = false;
					break;
				} else	{
					v.pop_back();
				}
			}
		}
		
		// fgets(tehon, 5, fp);

		if (!v.empty())	{
			legal = false;
		}
		
		if (legal)	{
			printf("yes\n");
			/*
			if (tehon[0] != 'y')	{
				miss = true;
			}
			*/
		} else	{
			printf("no\n");
			/*
			if (tehon[0] != 'n')	{
				miss = true;
			}
			*/
		}
		/*
		
		miss = false;
		
		if (miss)	{
			ofstream outputfile("misslist.txt");
			outputfile << c;
			outputfile.close();
		}
		*/
	}
	
	return 0;
}

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

int main() {
	string s;
	while (getline(cin, s)) {
		if (s == ".")break;

		int flg = 1;
		stack<char>st;
		for (int i = 0;i < s.size();i++) {
			if (s[i] == '(') {
				st.push(s[i]);
			}
			else if (s[i] == '[') {
				st.push(s[i]);
			}
			else if (s[i] == ')') {
				if (!st.empty()&&st.top() == '(')st.pop();
				else {
					flg = 0;
					break;
				}
			}
			else if (s[i] == ']'){
				if(!st.empty()&&st.top()=='[') st.pop();
				else {
					flg = 0;
					break;
				}
			}
		}

		if (!st.empty())flg = 0;

		if (flg == 1)cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  string s;
  while (getline(cin, s), s != ".") {
    stack<char> t;
    rep(i, s.size()) {
      if (s[i] == '[' || s[i] == '(') t.push(s[i]);
      if (s[i] == ')') {
        if (t.size() && t.top() == '(') {
          t.pop();
        } else {
          cout << "no" << endl;
          goto next;
        }
      }
      if (s[i] == ']') {
        if (t.size() && t.top() == '[') {
          t.pop();
        } else {
          cout << "no" << endl;
          goto next;
        }
      }
    }
    cout << (t.size() ? "no" : "yes") << endl;
  next:;
  }
}

C++: #include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

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

C++: #include <cstdio>
#include <utility>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() 
{

	while(true)
	{
		string s;
		cin >> s;
		if(s=="."){break;}
		
		//かっこ以外を消去
		int i=0;
		while(i<s.length()){
			if(s[i]!='[' && s[i]!=']' && s[i]!='(' && s[i]!=')')
			{	s.erase(s.begin() + i); i--;}
			i++;}
		
		int x = s.length()/2;
		REP(i,x)
		{
			REP(i,s.length()-1)
			{
				if(	(s[i]=='[' && s[i+1]==']') || (s[i]=='(' && s[i+1]==')')	)
				{s.erase(s.begin()+i);
				s.erase(s.begin()+i);
				break;}
			}
		}
		if(s.length()==0)cout << "YES" <<endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for(int i=0; i<(n); ++i)

int main(void){
    string s;
    char brackets[] = {'(', ')', '[', ']'};
    while(getline(cin, s) && s!=".") {
        stack<char> stk;
        bool yes = true;
        rep(i, s.size()) {
            bool is_bracket = false;
            rep(j, 4) if(s[i] == brackets[j]) is_bracket = true;
            if(!is_bracket) continue;
            if(s[i] == '(' || s[i] == '[') stk.push(s[i]);
            else if( (stk.top() == '(' && s[i] == ')') ||
                     (stk.top() == '[' && s[i] == ']') ) stk.pop();
            else {
                yes = false;
                break;
            }
        }

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