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;

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;
    else if(!b.empty() && (b.top() == '(' || b.top() == '[') && flag)
      cout << "no" << endl;
  }
}

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

int main(void){
  string str;

  while(getline(cin,str) && str!="."){
    string c;
    for(int i=0;i<str.size();i++)
      if(str[i]==')' ||str[i]=='(' ||str[i]=='[' ||str[i]==']')
	c += str[i];

  stack<char> s;
  bool flag=false;
    for(int i=0;i<c.length();i++){
      if(s.empty() || c[i]=='(' || c[i]=='[')s.push(c[i]);
      else if((s.top()=='(' && c[i]==')' )||(s.top()=='[' && c[i]==']'))s.pop();
      else {flag=true;break;}
    }
    cout << (flag==false&&s.empty()?"YES":"NO") << endl;
  }
  return 0;
}

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

bool isYes(char input[]);

int main()
{
	char Input[101];
	int i=0;
	while(true){
		cin.getline(Input, sizeof(Input));
		if(Input[0] == '.') break;
		if(isYes(Input)){
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}
	return 0;
}

bool isYes(char Input[])
{
	enum __FLAG{NONE, PARE, BLAC};
	int prep[50], prepnum=0, p=NONE;
	for(int i=0; Input[i]!='.'; i++){
		if(Input[i] == '('){
			if(p != NONE){
				prep[prepnum] = p;
				prepnum++;
			}
			p=PARE;
		} else if(Input[i] == '['){
			if(p != NONE){
				prep[prepnum] = p;
				prepnum++;
			}
			p=BLAC;
		} else if(Input[i] == ')'){
			if(p!=PARE){
				return false;
			} else {
				if(prepnum==0) p=NONE;
				else {
					p = prep[prepnum-1];
					prepnum--;
				}
			}
		} else if(Input[i] == ']'){
			if(p!=BLAC){
				return false;
			} else {
				if(prepnum==0) p=NONE;
				else {
					p = prep[prepnum-1];
					prepnum--;
				}
			}
		}
	}
	return true;
}

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

int main()
{
	string C;
	while (1)
	{
		stack<char>S;
		getline(cin, C);
		if (C[0] == '.')
			break;
		else
		{
			int ant = 0;
			for (int i = 0; i < C.length(); ++i)
			{
				if (C[i] == '(' || C[i] == '[')
					S.push(C[i]);
				else if (C[i] == ')')
				{
					if (!S.empty() && S.top() == '(')
						S.pop();
					else 
						ant = 1;
				}
				else if (C[i] == ']')
				{
					if (!S.empty() && S.top() == '[')
						S.pop();
					else
						ant = 1;
				}
				if (ant)
					break;
			}
			if (!ant && S.empty())
				cout << "yes" << endl;
			else
				cout << "no" << endl;
		}
	}
	return 0;
}

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

#define int long long

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

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

using namespace std;



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

C++: #include <iostream>
using namespace std;
int main(){
    char buf[110],stack[110]={0},*sp,*p;
    while(fgets(buf,103, stdin),*buf!='.'){
        sp=stack+1;
        p=buf;
        for(;*p!='.';p++){
            if(*p == '(' || *p == '['){
                *sp++ = *p;
            }else if(*p == ')' || *p == ']'){
                sp--;
                if(!((*sp =='(' && *p == ')') || (*sp =='[' && *p == ']'))){
                    puts("no");
                    break;
                }
            }
        }
        if(*p=='.')puts(sp==stack+1?"yes":"no");
    }
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)

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