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>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void solve(string s) {
	int len = s.length();
	int k1 = 0, k2 = 0;
	stack<char> last;
	bool f = true;
	FORE(c, s) {
		if (c == '(') {
			last.push(c);
			k1++;
		} else if(c == '[') {
			last.push(c);
			k2++;
		}else if (c == ')') {
			if (last.empty() || (!last.empty() && last.top() != '(') || k1 <= 0) f = false;
			if (!last.empty()) last.pop();
			k1--;
		} else if(c == ']') {
			if (last.empty() || (!last.empty() && last.top() != '[') || k2 <= 0) f = false;
			if (!last.empty()) last.pop();
			k2--;
		}
	}
	if (k1 || k2 || !f || !last.empty()) {
		cout << "no" << endl;
	} else {
		cout << "yes" << endl;
	}
}

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

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    string S;
    getline(cin, S);
    if (S == "."){
      break;
    }
    int N = S.size();
    bool ok = true;
    stack<char> st;
    st.push('@');
    for (int i = 0; i < N; i++){
      if (S[i] == '('){
        st.push('(');
      }
      if (S[i] == '['){
        st.push('[');
      }
      if (S[i] == ')'){
        if (st.top() != '('){
          ok = false;
          break;
        } else {
          st.pop();
        }
      }
      if (S[i] == ']'){
        if (st.top() != '['){
          ok = false;
          break;
        } else {
          st.pop();
        }
      }
    }
    if (st.size() != 1){
      ok = false;
    }
    if (ok){
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))
#define ALL(c) (c).begin(), (c).end()
// #define dump(a) cerr << #a << "=" << (a) << endl

using namespace std;

int main() {
	string line;
	char left_paren;
	bool is_yes;
	vector<char> left_parens;

	while(getline(cin,line)) {
		if (line[0] == '.') break;

		left_parens.clear();
		is_yes = true;

		rep(i,line.size()) {
			if (line[i] == '(') {
				left_parens.push_back(line[i]);
			}
			else if (line[i] == '[') {
				left_parens.push_back(line[i]);
			}
			else if (line[i] == ')') {
				left_paren = left_parens.back();
				left_parens.pop_back();
				if (left_paren != '(') {
					is_yes = false;
				}
			}
			else if (line[i] == ']') {
				left_paren = left_parens.back();
				left_parens.pop_back();
				if (left_paren != '[') {
					is_yes = false;
				}
			}
		}
		if (left_parens.size() > 0)
			is_yes = false;

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

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
void test(int );
int f,count,count1;
char ch[101]; 
int main(){
  while(1){
    int j=0;
    count=0,count1=0;
    while(1){
      scanf("%c",&ch[j]);
      if(ch[j]=='.')break;
      j++;
    }
    if(j==0)break;
    for(int i=0;i<j;i++){
      if(ch[i]=='[')count++;
      else if(ch[i]=='(')count1++;
      else if(ch[i]==']' || ch[i]==')')test(i);
      if(count1<0||count<0||f==1)break; 
    }
    if(count==0&&count1==0)cout<<"yes"<<endl;
    else cout<<"no"<<endl;  
    char a;
    scanf("%c",&a);
  }
  return 0;
}

void test(int x){
  f=0;
  int count2=0;
  if(ch[x]==')'){
    count1--;
    for(int i=x-1;i>=0;i--)
      if(ch[i]=='('){
	for(int j=x-1;j>i;j--)
	  if(ch[j]=='[')count2++;
	  else if(ch[j]==']')count2--;
	break;
      }
  }
  else if(ch[x]==']'){
    count--;
    for(int i=x-1;i>=0;i--)
      if(ch[i]=='['){
	for(int j=x-1;j>i;j--)
	  if(ch[j]=='(')count2++;
	  else if(ch[j]==')')count2--;
	break;
      }
  }
  if(count2>0)f=1;
}

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

int main(void){
	string s;
	while(getline(cin,s),s!="."){
		vector<int> cnt;
		cnt.clear();
		for(int i = 0 ; i < s.size() ; i ++){
				if(s[i] == '[')
					cnt.push_back(1);	
				if(s[i] == ']'){
					if(cnt.size()==0){
						cnt.push_back(1);
						break;
					}
					if(cnt[cnt.size()-1] == 1)
						cnt.pop_back();
					else break;
				}
				
				if(s[i] == '(')
					cnt.push_back(2);
				if(s[i] == ')'){
					if(cnt.size()==0){
						cnt.push_back(2);
						break;
					}
					if(cnt[cnt.size()-1] == 2)
						cnt.pop_back();
					else break;
				}
//				cout<<s[i]<<" "<<sika<<" "<<maru;
		}
		if(cnt.size())
			cout<<"no";
		else 
			cout<<"yes";
		cout<<endl;
	}
}