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 <deque>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

bool balance(string line) {
  deque<char> stack;
  for (auto c : line) {
    switch (c) {
      case '(':
      case '[':
        stack.push_back(c);
        break;
      case ')':
      case ']':
        if (stack.empty()) {
          return false;
        }

        if ((stack.back() == '(' && c == ')') ||
            (stack.back() == '[' && c == ']')) {
          stack.pop_back();
          break;
        } else {
          return false;
        }
      default:
        break;
    }
  }

  return 0 == stack.size();
}

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

    cout << (balance(line) ? "yes" : "no") << endl;
  }
  return 0;
}

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

using namespace std;

int main(){
  char r[105];
  int count = 0;
  char s;
  char c;
  int maru=0;
  int shikaku=0;
  while(true){
    cin>>s;
    if(s=='.')break;
    else if(s=='('){
      r[count++]=')';
      maru++;
    }
    else if(s=='['){
      r[count++]=']';
      shikaku++;
    }
    else if(s==')'){
      if(r[count--]==s){
	maru--;
      }
    }
    else if(s==']'){
      if(r[count--]==s){
	shikaku--;
      }
    }
    
    
    while(true){
      cin>>c;
      if(c=='.'||maru<0||shikaku<0)break;
      else if(c=='('){
	r[count++]=')';
	maru++;
      }
      else if(c=='['){
	r[count++]=']';
	shikaku++;
      }
      else if(c==')'){
	if(r[count-1]==c){
	  count--;
	  maru--;
	}
	else maru=-1111111;
      }
      else if(c==']'){
	if(r[count-1]==c){
	  count--;
	  shikaku--;
	}
	else shikaku=-111111;
      }
    }

    if(maru==0&&shikaku==0)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    if(c!='.'){
      while(true){
	cin>>c;
	if(c=='.')break;
      }
    }
    maru=0;
    shikaku=0;
  }
     if(maru==0&&shikaku==0)cout<<"yes"<<endl;
      else cout<<"no"<<endl;
  

  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

bool isLeap(int y);
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/



int main()
{
	string inp;
	
	while (getline(cin, inp), inp != ".")
	{
		stack<char> stk;
		
		rep(i, inp.length())
		{
			if (inp[i] == '(' || inp[i] == '[')
			{
				stk.push(inp[i]);
			} else if (inp[i] == ')') {
				if (stk.empty())
				{
					cout << "no" << endl;
					break;
				}
				char kakko = stk.top(); stk.pop();
				if (kakko != '(')
				{
					cout << "no" << endl;
					break;
				}
			} else if (inp[i] == ']') {
				if (stk.empty())
				{
					cout << "no" << endl;
					break;
				}
				char kakko = stk.top(); stk.pop();
				if (kakko != '[')
				{
					cout << "no" << endl;
					break;
				}
			}
			
			if (i == inp.length() - 1)
			{
				if (stk.empty())
				{
					cout << "yes" << endl;
					break;
				}
			}
		}
	}
	
	return 0;
}


bool isLeap(int y)
{
	return y % 400 == 0
						? true : y % 100 == 0
						? false : y % 4 == 0
						? true : false;
}

ll gcd(ll a, ll b)
{
	return (b > 0) ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}

void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>

using namespace std;


/*
 *
 *
 *   ~~~~Below My Answer~~~~
 *
 *
 **/

int main() {

    while (true) {
        string str;
        getline(cin, str);

        if (str.size() == 1 && str[0] == '.') break;

        int countCircle = 0;
        int countRect = 0;

        bool good = true;
        for (int i = 0; i < str.size(); i++) {
            if (str[i] == '(')countCircle++;
            if (str[i] == ')')countCircle--;
            if (countCircle < 0) good = false;
        }
        for (int i = 0; i < str.size(); i++) {
            if (str[i] == '[')countRect++;
            if (str[i] == ']')countRect--;
            if (countRect < 0)good = false;
        }

        if (countCircle != 0) good = false;
        if (countRect != 0)good = false;

        if (good) {
            stack<int> S;
            for (int i = 0; i < str.size(); i++) {
                if (str[i] == '(') S.push(0);
                if (str[i] == '[') S.push(1);
                if (str[i] == ')') {
                    int top = S.top();
                    S.pop();
                    if (top != 0) good = false;
                }
                if (str[i] == ']') {
                    int top = S.top();
                    S.pop();
                    if (top != 1) good = false;
                }
            }
        }

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

    }

    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define all(c) (c).begin(), (c).end()

char buf[1<<16];

bool solve(string& s){
    s.erase(remove_if(all(s), [](char c){return string("()[]").find(c) == string::npos;}), s.end());
    vector<char> st;
    for(auto c: s){
        if(c == '(' || c == '[')st.push_back(c);
        else if(st.empty() || st.back() != (c == ')'? '(': '['))return false;
        else st.pop_back();
    }
    return st.empty();
}

vector<string> split(const string& in, char delim){
    istringstream stream(in);
    string field;
    vector<string> res;
    while(getline(stream, field, delim) && !field.empty())res.push_back(field);
    return res;
}

int main(){
    cin.read(buf, sizeof(buf));
    string in(buf);
    in.erase(remove(all(in), '\n'), in.end());
    for(auto s: split(in, '.'))cout << (solve(s)? "yes\n": "no\n");
    return 0;
}