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 <string.h>
int kakko(char *c,char tmp,int count){
	int flag = 0;
	char wtmp,retmp;
	*c = getchar();
	count++;
	if(tmp == ')')
		wtmp = ']';
	else
		wtmp = ')';
	while(*c != '.' && *c != tmp && *c != wtmp){
		if(*c == '(' || *c == '['){
			if(*c == '(')
				retmp = ')';
			else
				retmp = ']';
			flag = kakko(c,retmp,count);
		}
		if(*c != '.' && *c != tmp && *c != wtmp){
			*c = getchar();
			count++;
		}
	}
	if(*c == '.' || *c == wtmp)
		flag = 1;
	return flag;
}

int main(void){
	int count = 0, flag = 0;
	char c, tmp;
	c = getchar();
	while(c != '.' || count != 0){
		if(c == '(' || c == '['){
			if(c == '(')
				tmp = ')';
			else
				tmp = ']';
			flag = kakko(&c,tmp,count);
		}
		if(c == '.'){
			if(flag == 0)
				printf("yes\n");
			else
				printf("no\n");
			flag = 0;
			count = 0;
			getchar(); //改行読取ばs
			c = getchar();
		}
		else{
			c = getchar();
			count++;
		}
	}
	return 0;
}

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

typedef vector<int> vi;
typedef vector<vi> vvi;
#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)
typedef unsigned long long ull;

string s;

bool solve(){
    stack<char> st;
    for (int i = 0; i < s.size(); i++){
        //cout << s[i];
        if (s[i] == '(' || s[i] == '['){
            st.push(s[i]);
        }
        else if (s[i] == ')' || s[i] == ']'){
            if (st.size() == 0){
                return false;
            }
            if (s[i] == ')'){
                if (st.top() != '(') return false;
            }
            if (s[i] == ']'){
                if (st.top() != '[') return false;
            }
            st.pop();
        }
    }
    //cout << endl;
    return st.size() == 0;
}

int main(){
    while (getline(cin, s) && s!="."){
        if (solve()){
            cout << "yes";
        }
        else {
            cout << "no";
        }
        cout << endl;
    }
}

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

int main() {
    string str, brackets = "()[]";
    while (getline(cin, str) && str != ".") {
        stack<char> s;
        bool flag = true;
        for (int i = 0; i < str.length(); i++) {
            if (brackets.find(str[i]) != string::npos) {
                if (str[i] == '(' || str[i] == '[') s.push(str[i]);
                if (str[i] == ')') {
                    if (s.empty()) { flag = false; break; }
                    char ch = s.top(); s.pop();
                    if (ch == '[') { flag = false; break; }
                }
                if (str[i] == ']') {
                    if (s.empty()) { flag = false; break; }
                    char ch = s.top(); s.pop();
                    if (ch == '(') { flag = false; break; }
                }
            }
        }
        if (!s.empty()) flag = false;
        cout << (flag ? "yes" : "no") << endl;
    }
    return 0;
}

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

using namespace std;

stack<char> stk;

char s[101];

int main(void){
	int i;
	
	while(1) {
		fgets(s,100,stdin);
		if(s[0] == '.' && s[1] == '\n') break;

		while(!stk.empty())
			stk.pop();
		int flag = 0;
		int l = strlen(s);
		int m = 0, k = 0;
		char past = '\0';

		for(i = 0; i < l && flag == 0; i++) {
			if( s[i] == '(' ) {
				stk.push('(');
			}
			if( s[i] == ')' ) {
				if(stk.empty()){
					flag=1;
					break;
				}
				if(stk.top() == '(') stk.pop();
				else flag = 1;
			}
			if( s[i] == '[' ) {
				stk.push('[');
			}
			if( s[i] == ']' ) {
				if(stk.empty()){
					flag=1;
					break;
				}
				if(stk.top() == '[') stk.pop();
				else flag = 1;
			}

		}

		if( !stk.empty() ) flag = 1;

		if( flag == 0 ) printf("yes\n");
		else printf("no\n");

	}

	return 0;
}

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

using namespace std;

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

        bool b = true;
        stack<char> t;
        t.push( '\0' );
        for( auto c : string( s.cbegin(), s.cbegin() + s.find_last_of( '.' ) ) ) {
            b = [&]() mutable -> bool {
                if ( c == '(' || c == '[' )
                    t.push( c );
                else if ( c == ')' )
                    if ( t.top() == '(' )
                        t.pop();
                    else
                        return false;
                else if ( c == ']' )
                    if ( t.top() == '[' )
                        t.pop();
                    else
                        return false;
                return true;
            }();
            if ( !b )
                break;

        }
        cout << ( b && t.size() == 1 ? "yes" : "no" ) << endl;
    }
}

C++: #include <iostream>
#include <string>
#include <stack>
using namespace std;
string s;
bool solve() {
  stack<char> st;
  for(int i = 0; i < (int)s.length(); ++i) {
    if(s[i] == '[' || s[i] == '(') st.push(s[i]);
    else if(s[i] == ']') {
      if(st.empty() || st.top() != '[') return 0;
      st.pop();
    }
    else if(s[i] == ')') {
      if(st.empty() || st.top() != ')') return 0;
      st.pop();
    }
  }
  return st.empty();
}

int main() {
  while(getline(cin, s)) {
    if(s == ".") break;
    cout << (solve() ? "yes" : "no") << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<stack>
#include <cmath>
using namespace std;
bool paren(char a,char b){
	return (a=='('&&b==')')||(a=='['&&b==']');
}
int main(){
	string str;
	while(getline(cin,str)&&str!="."){
		int flg=1;
		stack<char> stk;
		for(unsigned i=0;i<str.size()&&flg==1;i++){
			switch(str[i]){
			case '(':
			case '[':
				stk.push(str[i]);
				break;
			case ']':
			case ')':
				if(stk.empty()||!paren(stk.top(),str[i])){
					flg=0;
				}
				if(flg)stk.pop();
			}
		}
		if(!stk.empty())flg=0;
		cout<<(flg==1?"yes":"no")<<endl;
	}
}

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

bool check(string s) {
  stack<int> st;
  for (auto&& c : s) {
    if (c == '(' || c == '[') st.push(c);
    if (c == ')' || c == ']') {
      if (st.empty()) {
        return false;
      } else {
        char t = st.top();
        st.pop();
        if (c == ')' && t != '(') return false;
        if (c == ']' && t != '[') return false;
      }
    }
  }
  return (st.size() == 0);
}

int main() {
  string s;
  while (getline(cin, s), !(s.length() == 1 && s[0] == '.')) {
    cout << (check(s) ? "yes" : "no") << endl;
  }
}