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 "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

string s;

string calc() {
	vector<char>v;
	REP(i, s.size()) {
		if (s[i] == '(')v.emplace_back('(');
		if (s[i] == '[')v.emplace_back('[');
		if (s[i] == ')') {
			if (v.size() == 0)return "no";
			else if (v[v.size()-1] == '(') {
				v.pop_back();
			}
			else {
				return "no";
			}
		}
		if (s[i] == ']') {
			if (v.size() == 0)return "no";
			else if (v[v.size()-1] == '[') {
				v.pop_back();
			}
			else {
				return "no";
			}
		}
	}
	return v.size() == 0 ? "yes" : "no";
}

int main() {
	while (getline(std::cin, s)) {
		if (s == ".")return 0;
		cout << calc() << endl;
	}
}

C++: #include<iostream>
#include<cstdio>
#include<stack>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
int main(){
    map<char,int>M;
    M['(']=M[')']=1;
    M['[']=M[']']=2;
    string str;
    while(getline(cin,str),str!="."){
        bool flag=true;
        stack<int>S;
        for(int i=0;i<str.length();i++){
            char c=str[i];
            if(c=='('||c=='['){
                S.push(M[c]);
            }
            if(c==')'||c==']'){
                if(S.size()==0){
                    flag=false;
                    break;
               }
                if(S.top()!=M[c]){
                    flag=false;
                    break;
                }
                S.pop();
            }
        }
        if(S.size())flag=false;
        puts(flag?"yes":"no");
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    while(getline(cin,s),s!="."){
        stack<char> w;
        int d=0;
        if(s==".")break;
        for(int i=0;i<s.size();i++){
            if(s[i]=='['||s[i]=='(')w.push(s[i]);
            else if(s[i]==']'){
                if(w.top()=='[')w.pop();
            }
            else if(s[i]==')'){
                if(w.top()=='(')w.pop();
            }
        }
        if(w.empty())cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(void) {
	string ch;
	char a[101] = {};
	getline(cin, ch);
	while (ch[0] != '.') {
		int i,j=0;
		for (i = 0; ch[i] != '.'; i++) {
			if (ch[i] == '(' || ch[i] == '[') {
				a[j] = ch[i];
				j++;
			}
			else if (ch[i] == ')' || ch[i] == ']') {
				j--;
				if (j == -1) break;
				if (a[j] != ch[i]) {
					cout << "no" << endl;
					j = -1;
					break;
				}
			}
		}
		if (j == 0) {
			cout << "yes" << endl;
		}
		else if(j != -1) {
			cout << "no" << endl;
		}
		getline(cin, ch);
	}
	return 0;
}

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

using namespace std;

int main(void){
  string s;
  stack<char> str;

  while(getline(cin,s) && s!="."){
    bool flag = true;
    string ch;
    for(int i=0;i<s.size();i++)
      if(s[i]=='{' || s[i]=='(' || s[i]=='}' || s[i]==')')ch+=s[i];

    for(int i=0;i<ch.length();i++){
      
      if(ch[i]=='(' || ch[i]=='{')str.push(ch[i]);
      else if(ch[i]==')' && str.top()=='(')str.pop();
      else if(ch[i]=='}' && str.top()=='}')str.pop();
      else {
	flag = false;
	break;
      }
    }

    cout << (flag && str.empty()?"YES":"NO") << endl;

  }

  return 0;
}

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

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

using namespace std;

int main(void){
	for(string in; getline(cin, in) && in != ".";){
		stack<char> table;
		string out = "yes";

		rep(i, in.length()){
			char curChar = in.at(i);
			if(curChar == '[' || curChar == '(') table.push(curChar);
			else if(curChar == ']'){
				if(!table.empty() && table.top() == '[') table.pop();
				else{ out = "no"; break; }
			}
			else if(curChar == ')'){
				if(!table.empty() && table.top() == '(') table.pop();
				else{ out = "no"; break; }
			}
		}
		if(!table.empty()) out = "no";
		cout << out << endl;
	}

	return 0;
}

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

int main(){
  char ch;
  int f1=0,f2=0;

  while(1){
    stack<int> S1,S2;
    f1=f2=0;
    scanf("%c",&ch);
    int i=0;
    bool flag1=0,flag2=0;
    if(ch=='.')break;
    while(1){
      if(i!=0) cin>>ch;

      if(ch=='.') break;
      if(ch=='('){
	S1.push(i);
	if(f1==0){
	  if(f2==1) f1=2;
	  else f1=1;
	}
      }
  
  
      if(ch==')'&&S1.size()>0&&f2!=2){
	S1.pop();
	f1=0;
      }else if(ch==')'&&f1==0)flag1=1;

      if(ch=='['){
	S2.push(i);
	if(f2==0){
	  if(f1==1)f2=2;
	  else f2=1;
	}
      }
      if(ch==']'&&S2.size()>0&&f1!=2){
	S2.pop();
	f2=0;
      }else if(ch==']'&&f2==0)flag2=1;
      i++;
    }

    if(S1.size()==0&&S2.size()==0&&flag1!=1&&flag2!=1) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    scanf("%c",&ch);
    //    cout<<flag1<<" "<<flag2<<endl;
  
  }
  
  return 0;
}