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<cstdio>
#include<vector>
using namespace std;
int main(){
  while(1){
    char t;
    vector<int> s;
    int b=0,f=0;
    while(1){
      scanf("%c",&t);
      if(t=='.')break;
      b=1;
      if((t!='('&&t!=')'&&t!='['&&t!=']')||f==1)continue;
      else if(t=='(')s.push_back(1);
      else if(t=='[')s.push_back(2);
      else if(!s.empty()){
	if(s.back()==1&&t==')')s.pop_back();
	else if(s.back()==2&&t==']')s.pop_back();
	else f=1;
      }
      else if(t==']'||t==')')f=1;
    }scanf("%c",&t);
    if(b==0)break;
    else if(f==0&&s.empty())printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

C++: #include <cstdio>
#include <utility>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() 
{

	while(true)
	{
		string s;
		getline(cin,s);
		if(s=="."){break;}
		
		//かっこ以外を消去
		int i=0;
		while(i<s.length()){
			if(s[i]!='[' && s[i]!=']' && s[i]!='(' && s[i]!=')')
			{	s.erase(s.begin() + i); i--;}
			i++;}
		
		int x = s.length()/2;
		REP(i,x)
		{
			REP(i,s.length()-1)
			{
				if(	(s[i]=='[' && s[i+1]==']') || (s[i]=='(' && s[i+1]==')')	)
				{s.erase(s.begin()+i);
				s.erase(s.begin()+i);
				break;}
			}
		}
		if(s.length()==0)cout << "yes" <<endl;
		else cout << "no" << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<list>
#include<stack>
#include<map>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;

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

int l;

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

        l = s.size();
        stack<char> bra;
        
        bool ans = true;
        REP(l)
        {

            if(s[i] == '('){ bra.push('(');continue; }
            if(s[i] == '['){ bra.push('[');continue; }

            if(s[i] == ')')
            {
                if(bra.empty() || bra.top() != '('){ans = false; break;}
                bra.pop();
            }
            if(s[i] == ']')
            {
                if(bra.empty() || bra.top() != '['){ans = false; break;}
                bra.pop();
            }
        }
        if(!bra.empty()) ans = false;

        if(ans) cout<< "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}

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

int main()
{
  string s;
  while(1){
    getline(cin,s);
    if(s == ".")
      break;
    stack<char> b;
    bool flag = true;
    for(int i = 0; i < s.size(); i++){
      if(s[i] == '('){
        b.push('(');
      }else if(s[i] == '['){
        b.push('[');
      }else if(s[i] == ')'){
        if(b.empty() || b.top() != '('){
          cout << "no" << endl;
          flag = false;
          break;
        }
        b.pop();
      }else if(s[i] == ']'){
        if(b.empty() || b.top() != '['){
          cout << "no" << endl;
          flag = false;
          break;
        }
        b.pop();
      }
    }
    if(b.empty() && flag)
      cout << "yes" << endl;
  }
}

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

#define int long long

char* Solve(string S)
{
    stack<char> s;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] == '(') s.push(')');
        else if (S[i] == '[') s.push(']');
        else if (S[i] == ')' || S[i]] == ']')
        {
            if (s.empty() || s.top() != S[i]) return "no";
        }
    }
    if (!s.empty()) return "no";
    return "yes";
}

signed main()
{
    string S;
    while (getline(cin, S), S != ".")
    {
        printf("%s\n", Solve(S));
    }
    return 0;
}

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

    stack<char> kakko;

int main() {
  string str;
  char x;
  while(getline(cin,str)) {
    if(str == ".") return 0;
    bool r = true;

    while(!kakko.empty()) {
      kakko.pop();
    }

    for(unsigned int i=0;i<str.size();i++) {
      x = *str.substr(i,1).c_str();
      if(x == '(' || x == '[') {
        kakko.push(x);
      }
      else if(x == ')') {
        if(!kakko.empty()) {
          if(kakko.top() == '(') {
            kakko.pop();
          }
          else {
            r = false;
          }
        }
        else {
          r = false;
        }
      }
      else if(x == ']') {
        if(!kakko.empty()) {
          if(kakko.top() == '[') {
            kakko.pop();
          }
          else {
            r = false;
          }
        }
        else {
          r = false;
        }
      }
    }
    if(r && kakko.empty()) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

C++: #include <iostream>
using namespace std;
bool r(int &i,string S);
bool a(int &i,string S);
bool r(int &i,string S){
    while(i<S.size()){
        switch(S[i]){
            case '(':
                i++;
                if(!r(i,S)) return false;
                break;
            case ')':
                return true;
            case '[':
                i++;
                if(!a(i,S)) return false;
                break;
            case ']':
                return false;
            default:
                break;
        }
        i++;
    }
    return false;
}

bool a(int &i,string S){
    while(i<S.size()){
        switch(S[i]){
            case '(':
                i++;
                if(!r(i,S)) return false;
                break;
            case ')':
                return false;
            case '[':
                i++;
                if(!a(i,S)) return false;
                break;
            case ']':
                return true;
            default:
                break;
        }
        i++;
    }
    return false;
}

int main(){
    string str;
    while(true){
        getline(cin,str);
        if(str==".") return 0;
        else str.push_back(']');
        int i=0;
        if(a(i,str)){
            cout<<"yes"<<endl;
        }else{
            cout<<"no"<<endl;
        }
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;

#define MAXI 1000000

int main() {

	string s;
	while(getline(cin, s), s != "."){
		stack<int> st;
		bool flag = true;
		rep(i, s.size()){
			if(s[i] == '(') st.push(1);
			if(s[i] == '[') st.push(2);
			if(s[i] == ')'){
				if(st.empty() || st.top() != 1){
					flag = false;
					break;
				}
				st.pop();
			}
			if(s[i] == ']'){
				if(st.empty() || st.top() != 2){
					flag = false;
					break;
				}
				st.pop();
			}
		}
		if(flag && st.empty()) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	

	return 0;
}