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<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
using namespace std;

stack<char> st;

char str[514];
int slen;

int main() {
	int i;
	while( gets(str) ) {
		if ( str[0] == '.' && str[1] == '\0' )
			break;
		slen = strlen(str);
		for( i = 0; i < slen; i++ ) {
			if ( str[i] == '(' || str[i] == '[' )
				st.push(str[i]);
			if ( str[i] == ')' ) {
				if ( st.empty() || st.top() != '(' )
					break;
				st.pop();
			}
			if ( str[i] == ']' ) {
				if ( st.empty() || st.top() != '[' )
					break;
				st.pop();
			}
		}
		if ( i == slen )
			cout << "yes" << endl;
		else
			cout << "no" << endl;
		while(!st.empty())
			st.pop();
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <string>

using namespace std;

int main() {
  char buf[120];
  while (true) {
    fgets(buf, 120, stdin);
    if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0';
    if (buf[0] == '.' && buf[1] == '\0') break;
    string s = "";
    for (int i=0;buf[i]!='\0';i++) {
      if (buf[i] == '(' || buf[i] == ')'
        || buf[i] == '[' || buf[i] == ']') {
        s += buf[i];
      }
    }
    //printf("%s\n", s.c_str());
    bool yes = true;
    while (!s.empty()) {
      int n = s.find("()");
      if (n == string::npos) {
        n = s.find("[]");
        if (n == string::npos) {
          yes = false;
          break;
        }
      }
      s.erase(n, 2);
    }
    puts(yes ? "yes" : "no");
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
const int INF = 1<<28;

string input;

int find(int a, int p) {
	int btn[2] = {};
	FOR(i, p, input.size()) {
		if(a) {
			if(input[i] == '[')
				btn[0]++;
			if(input[i] == ']')
				btn[0]--;
				if(btn[0] < 0) return 1;
			if(input[i] == '(')
				btn[1]++;
			if(input[i] == ')') {
				btn[1]--;
				if(!btn[0] && !btn[1])
					return 0;
			}
		}
		else {
			if(input[i] == '(')
				btn[0]++;
			if(input[i] == ')')
				btn[0]--;
				if(btn[0] < 0) return 1;
			if(input[i] == '[')
				btn[1]++;
			if(input[i] == ']') {
				btn[1]--;
				if(!btn[0] && !btn[1])
					return 0;
			}
		}
	}
	return 1;
}


int main() {
	while(getline(cin, input)) {
		if(input == ".") break;
		int cnt = 0;
		int chk[2] = {};
		REP(i, input.size()) {
			if(input[i] == '(') {
				cnt += find(1, i);
				chk[1]++;
			}
			if(input[i] == '[') {
				cnt += find(0, i);
				chk[0]++;
			}
			if(input[i] == ')') {
				chk[1]--;
				if(chk[1] < 0) cnt++;
			}
			if(input[i] == ']') {
				chk[0]--;
				if(chk[0] < 0) cnt++;
			}
		}
		if(chk[0] || chk[1]) cnt++;
		cout << (cnt ? "no" : "yes") << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    while (getline(cin,s)) {
        if (s==".") {
            break;
        } else {
            int flag=0;
            std::deque<char> deq;
            for (int i=0;i<s.size();i++) {
                if (s.at(i)=='('||s.at(i)=='[') {
                    deq.emplace_back(s.at(i));
                } else if (s.at(i)==')') {
                    if (deq.empty()==true||deq.back()!='(') {
                        flag=1;
                        cout<<"no"<<endl;
                        break;
                    } else {
                        deq.pop_back();
                    }
                } else if (s.at(i)==']') {
                    if (deq.empty()==true||deq.back()!='[') {
                        flag=1;
                        cout<<"no"<<endl;
                        break;
                    } else {
                        deq.pop_back();
                    }
                }
            }
            if (flag==0&&deq.empty()==true) {
                cout<<"yes"<<endl;
            } else if (flag==0&&deq.empty()!=true) {
                cout<<"no"<<endl;
            }
        }
    }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  string a;
  while(getline(cin,a)){
    if(a[0]=='.')break;
    string b;
    int c[2]={},cnt=0;
    for(int i=0;i<a.size();i++){
      if(a[i]=='(')c[0]++,b+=a[i];
      if(a[i]==')')c[0]--,b+=a[i];
      if(a[i]=='[')c[1]++,b+=a[i];
      if(a[i]==']')c[1]--,b+=a[i];
      if(c[0]<0||c[1]<0)cnt++;
    }
    if(c[0]!=0||c[1]!=0)cout<<"no\n"<<endl;
    else{
      for(int i=1;i<b.size();i++){
	if((b[i-1]=='('&&b[i]==']')||(b[i-1]=='['&&b[i]==')'))cnt++;
      }
      if(cnt!=0)cout<<"no\n"<<endl;
      else cout<<"yes\n"<<endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int main(){
    
    string s;
    while(getline(cin,s)){
        stack<char> sta;
        REP(i,s.size()){
            if(s[i]=='('||s[i]==')'||s[i]=='['||s[i]==']'){
                if(sta.size()==0){
                    sta.push(s[i]);
                }else if((sta.top()=='('&&s[i]==')')||(sta.top()=='['&&s[i]==']')){
                    sta.pop();
                }else{
                    sta.push(s[i]);
                }
            }
        }
        if(sta.size()!=0)cout<<"no"<<endl;
        else cout<<"yes"<<endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(ll i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main() {
	string s;
	while (getline(cin, s), s != ".") {
		int a = 0, b = 0;
		bool m = false, k = false;
		for (char c : s) {
			if (c == '(') {
				a++; m = true; k = false;
			}
			if (c == '[') {
				b++; k = true; m = false;
			}
			if (c == ')') {
				a--;if (a < 0)break;
				if (k) {
					puts("no");
					goto p;
				}
				m = false; k = false;
			}
			if (c == ']') {
				b--; if (b < 0)break;
				if (m) {
					puts("no");
					goto p;
				}
				m = false; k = false;
			}
		}
		if (a || b)puts("no");
		else puts("yes");
	p:;
	}
}