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 <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

bool pair_parens(string line) {
    stack<char> st;
    REP(i, line.length()) {
        switch (line[i]) {
        case '(':
        case '[':
            st.push(line[i]);
            break;
        case ')':
        case ']':
            if (!st.empty()) {
                char paren = st.top(); st.pop();
                if (paren == '(' && line[i] == ')') {
                } else if (paren == '[' && line[i] == ']') {
                } else {
                    return false;
                }
            } else {
                return false;
            }
            break;
        }
    }
    return st.empty();
}

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

        if (pair_parens(line)) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
}

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

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

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

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

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<utility>
#include<set>
#include<stack>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX  999999
int main(){
    string s;
    while(getline(cin,s)){
        if(s.size()==1&&s[0]=='.') break;
        stack<char>st;
        bool check=true;
        rep(i,s.size()){
            if(s[i] =='(' || s[i] == '[')
                st.push(s[i]);
            if(s[i]==')'){
                if(st.empty()) check=false;
                else if(st.top()=='(') st.pop();
            }else if(s[i]==']'){
                if(st.empty())check=false;
                else if(st.top()=='[')st.pop();
            }
            if(check==false) break;
        }
        if(st.empty() &&check) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;

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

		if(flag&&st.empty()){
			p("yes");
		}else{
			p("no");
		}
	}

	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <stack>
#include <string>
using namespace std;

int main(){
	string str;
	while(1){
		getline(cin, str);
		if(str==".") break;
		stack<char> B;
		B.push(0);
		bool judge = false;

		for(int i=0;i<str.length();i++){
			if(str[i]=='(' | str[i]=='['){
				B.push(str[i]);
			} else if(str[i]==')'){
				if(B.top()=='(') B.pop();
				else break;
			} else if(str[i]==']'){
				if(B.top()=='[') B.pop();
				else break;
			}
			if(i==str.length()-1) judge = true;
		}
		cout<< ((judge) ? "yes" : "no" )<<endl;
	}

	return 0;
}