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 <stack>
using namespace std;

string::size_type find(char ch) {
  string sch; sch.push_back(ch);
  string tgt = "()[]";
  return tgt.find(sch);
}

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

    string s;

    for(unsigned i=0; i<str.size(); i++) {
      if(find(str[i]) != string::npos) {
	s.push_back(str[i]);
      }
    }
    
    int len = s.size();
    char ch;
    stack<char> st;
    
    bool ok = 1;
    for(int i=0; i<len; i++) {
      if(s[i] == '(') st.push(s[i]);
      if(s[i] == '[') st.push(s[i]);
      
      if(s[i] == ')') {
	if(st.empty()) {
	  ok = 0;
	  break;
	}

	ch = st.top();
	if(ch != '(') {
	  ok = 0;
	  break;
	}
	st.pop();
      }
      
      if(s[i] == ']') {
	if(st.empty()) {
	  ok = 0;
	  break;
	}

	ch = st.top();
	if(ch != '[') {
	  ok = 0;
	  break;
	}
	st.pop();
      }

    }
    cout << ( ok && st.empty() ? "yes" : "no" ) << endl;
  }
  
  return 0;
}

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

int main()
{
	char ch;
	while (ch = getchar(), ch != '.') {
		stack<int> st;
		bool flag = true;
		while (ch != '\n') {
			if (ch == '[') {
				st.push(1);
			} else if(ch == '(') {
				st.push(2);
			} else if(ch == ']') {
				if (!st.empty() && st.top() == 1)
					st.pop();
				else
					flag = false;
			} else if(ch == ')') {
				if (!st.empty() && st.top() == 2)
					st.pop();
				else
					flag = false;
			}
			ch = getchar();
		}
		if (!st.empty())
			flag = false;
		if (flag)
			printf("yes\n");
		else
			printf("no\n");
	}
	return 0;
}

C++: #include<iostream>
#include<stack>
#include<string>
using namespace std;
int main() {
	string s;
	while (getline(cin, s)) {
		if (s == ".")return 0;
		bool b = true;
		stack<char>l;
		for (int i = 0; i != s.size(); i++) {
			if (s[i] == '(' || s[i] == '[') {
				l.push(s[i]);
			}
			else if (s[i] == ')') {
				if (l.size() == 0)b = false;
				else if (l.top() == '(') {
					l.pop();
				}
				else b = false;
			}
			else if (s[i] == ']') {
				if (l.size() == 0)b = false;
				else if (l.top() == '[') {
					l.pop();
				}
				else b = false;
			}
		}
		if (l.size() != 0)b = false;
		if (b)cout << "yes\n";
		else cout << "no\n";
	}
}

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

int main(){

    while(1){
        stack<char> s;
        bool isBalance = true;
        string input;

        getline(cin, input);

        if(input[0] == '.' && input[1] == '\0') break;

        for(int i=0;i < input.length() ;i++){
            if(input[i] == '.') break;
            switch(input[i]){
                case '[': s.push(input[i]);
                          break;
                case '(': s.push(input[i]);
                          break;
                case ']':
                          if(s.empty()){ isBalance = false; break;}
                          else if(s.top() != '['){isBalance = false; break;}
                          else s.pop();
                          break;
                case ')':
                          if(s.empty()){ isBalance = false; break;}
                          else if(s.top() != '('){isBalance = false; break;}
                          else s.pop();
                          break;
            }
            if(!isBalance) break;
        }
        if(!isBalance) cout << "no" << endl;
        else cout << "yes" << endl;

    }
    return 0;
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
const int dx[] = {0,0,1,1,1,-1,-1,-1};
const int dy[] = {1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

void dfs(int ci, int cj, VVI& board, VVI& visited, int h,int w){
  visited[ci][cj] = 1;
  rep(dir,8){
    if((ci + dy[dir]) < h && (cj + dx[dir]) < w &&
       (ci + dy[dir]) >= 0 && (cj + dx[dir]) >= 0  &&
       visited[(ci + dy[dir])][(cj + dx[dir])] == 0 &&
       board[(ci + dy[dir])][(cj + dx[dir])] == 1){
      dfs((ci + dy[dir]),(cj + dx[dir]),board,visited,h,w);
    }
  }
}

bool solve(string s){
  deque<int> que;
  int n = s.size();
  rep(i,n-1){
    if(s[i] == '('){
      que.push_back(0);
    }
    else if(s[i] == ')'){
      if(que.empty()) return false;
      int x = que.back();
      que.pop_back();
      if(x == 1) return false;
    }
    else if(s[i] == '['){
      que.push_back(1);
    }
    else if(s[i] == ']'){
      if(que.empty()) return false;
      int x = que.back();
      que.pop_back();
      if(x == 0) return false;
    }
  }
  if(que.empty()) return true;
  else return false;

}
int main(){
  string s;
  while(true){
    getline(cin,s);
    if(s.size() == 1 && s[0] == '.') break;
    bool ans = solve(s);
    cout << (ans?"yes":"no") << endl;
  }
  return 0;
}

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

int main(){
	stack<int>st;
	string s;
	while(1){
		getline(cin,s);
		if(s==".") return 0;
		for(int i=0;i<s.size();i++){
			if(s[i]=='(') st.push(0);
			if(s[i]=='[') st.push(1);
			if(s[i]==')'){
				if(st.empty()){
					cout<<"no"<<endl;
				}
				int num=st.top();
				if(num==0){
					st.pop();
				}
				else{
					cout<<"no"<<endl;
				}
			}
			if(s[i]==']'){
				if(st.empty()){
					cout<<"no"<<endl;
				}
				int num=st.top();
				if(num==1){
					st.pop();
				}
				else{
					cout<<"no"<<endl;
				}
			}
		}
		if(st.empty()) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

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



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

        stack<char> st;
        bool flag = true;
        for(char c : s) {
            if(c == '(' || c == '[') {
                st.push((c=='('? ')':']'));
            } else if(c == ')' || c == ']') {
                if(st.empty() || st.top() != c) {
                    flag = false;
                    break;
                }
                st.pop();
            }
        }
        
        cout << (flag? "yes":"no") << endl;
    }
}