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<stdio.h>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <functional>
#include <stdio.h>
#include <array>
#include <algorithm>
#include <string>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <queue>
#include<iomanip>
#include<bitset>
#include<stack>
#include<set>
#include<limits>
#include <complex>
using namespace std;

const int mod = 1000000007;
struct Mod {
public:
	int num;
	Mod() : num(0) { ; }
	Mod(long long int n) : num((n % mod + mod) % mod) { ; }
	Mod(int n) : num((n % mod + mod) % mod) { ; }
	operator int() { return num; }
};

Mod operator+(const Mod a, const Mod b) { return Mod((a.num + b.num) % mod); }
Mod operator+(const long long int a, const Mod b) { return Mod(a) + b; }
Mod operator++(Mod &a) { return a + Mod(1); }
Mod operator-(const Mod a, const Mod b) { return Mod((mod + a.num - b.num) % mod); }
Mod operator-(const long long int a, const Mod b) { return Mod(a) - b; }
Mod operator--(Mod &a) { return a - Mod(1); }
Mod operator*(const Mod a, const Mod b) { return Mod(((long long)a.num * b.num) % mod); }
Mod operator*(const long long int a, const Mod b) { return Mod(a)*b; }
Mod operator+=(Mod &a, const Mod b) { return a = a + b; }
Mod operator+=(long long int &a, const Mod b) { return a = a + b; }
Mod operator-=(Mod &a, const Mod b) { return a = a - b; }
Mod operator-=(long long int &a, const Mod b) { return a = a - b; }
Mod operator*=(Mod &a, const Mod b) { return a = a * b; }
Mod operator*=(long long int &a, const Mod b) { return a = a * b; }
Mod operator^(const Mod a, const int n) {
	if (n == 0) return Mod(1);
	Mod res = (a * a) ^ (n / 2);
	if (n % 2) res = res * a;
	return res;
}
Mod inv(const Mod a) { return a ^ (mod - 2); }
Mod operator/(const Mod a, const Mod b) {
	assert(b.num != 0);
	return a * inv(b);
}
Mod operator/(const long long int a, const Mod b) {
	assert(b.num != 0);
	return Mod(a) * inv(b);
}
Mod operator/=(Mod &a, const Mod b) {
	assert(b.num != 0);
	return a = a * inv(b);
}

#define MAX_N 1024000

Mod fact[MAX_N], factinv[MAX_N];
void init() {
	fact[0] = Mod(1); factinv[0] = 1;
	for (int i = 0; i < MAX_N - 1; ++i) {
		fact[i + 1] = fact[i] * Mod(i + 1);
		factinv[i + 1] = factinv[i] / Mod(i + 1);
	}
}
Mod comb(const int a, const int b) {
	return fact[a] * factinv[b] * factinv[a - b];
}
template<typename T>
vector<vector<T>> keisann(const vector<vector<T>>l, const vector<vector<T>>r) {
	vector<vector<T>>ans(l.size(), vector<T>(r[0].size()));
	assert(l[0].size() == r.size());
	for (unsigned int h = 0; h < l.size(); ++h) {
		for (unsigned int i = 0; i < r.size(); ++i) {
			for (unsigned int w = 0; w < r[0].size(); ++w) {
			
				ans[h][w] +=l[h][i] * r[i][w];
			}
		}
	}
	return ans;
}
template<typename T>
vector<vector<T>>powgyou(vector<vector<T>>a, const long long int n) {
	assert(a.size() == a[0].size());
	if (!n) {
		vector<vector<T>>e(a.size(), vector<T>(a[0].size()));
		for (unsigned int i = 0; i < a.size(); ++i) {
			e[i][i] = 1;
		}
		return e;
	}
	if (n == 1)return a;
	else {
		vector<vector<T>>ans(a.size(), vector<T>(a[0].size(), 0));
		ans = powgyou(a, n / 2);
		ans = keisann(ans, ans);
		if (n % 2) {
			ans = keisann(ans, a);
		}
		return ans;
	}
}



long long int powint(long long int a, int b) {
	if (b == 0)return 1;
	if (b == 1)return a;
	else {
		long long int ans = 1;
		long long int c = powint(a, b / 2);
		ans *= c*c;
		ans *= (b % 2) ? a : 1;
		return ans;
	}
	
}


int N;

vector<complex<long double>>coms;

vector<complex<long double>>scoms;
long double dp[1 << 20][20];
bool aok[1 << 20][20];

long double getans(bitset<20>bs, const int now) {
	if (now!=-1&&dp[bs.to_ulong()][now] >-0.5)return dp[bs.to_ulong()][now];
	else {
		long  double amin = 1 << 20;
		bool ok = false;
		for (int i = 0; i < N+2; ++i) {
			if (!bs[i]) {
				assert(i != now);
				bs[i] = true;
				if (i >= N) {

					amin = min(amin, getans(bs, i));
				}
				else {

					amin = min(amin, abs(coms[now] - coms[i]) + getans(bs, i));
				}
				ok = true;
				bs[i] = false;
			}
		}
		if (!ok)return dp[bs.to_ulong()][now]=0;
		return dp[bs.to_ulong()][now]=amin;
	}
}


int main(void) {
	string st;
	while (getline(cin,st)) {
		if (st == ".")break;
		else {
			vector<char>astack;
			bool ok = true;
			for (int i = 0; i < st.size(); ++i) {
				if (st[i] == ')') {
					if (astack.size() && astack.back() == '(') {
						astack.pop_back();
					}
					else {
						ok = false;
						break;
					}
				}else if (st[i] == ']') {
					if (astack.size() && astack.back() == '[') {
						astack.pop_back();
					}
					else {
						ok = false;
						break;
					}
				}
				else if (st[i] == '(') {
					astack.push_back('(');
					
				}
				else if (st[i] == '[') {
					astack.push_back('[');
				}
				else {

				}
			}
			if (ok&&astack.empty()) {
				cout << "yes" << endl;
			}
			else {
				cout << "no" << endl;
			}
		}

	}
	return 0;
}

/*
4
0 4
7 12
6 8
4 6

*/

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

int main(void){
    int t;
    int n,m,p;
    int ans;
    string s;
    string str;
    string c;
    vector<int>x;
    while(true) {
        s="";
        while(true){
            getline(cin,str);
            s+=str;
            if(str.back()!='.')s.push_back(' ');
            else break;
        }
        if(s.front()=='.')break;
        t=0;n=0;m=0;p=0;
        for(int i=0;i<s.length();i++){
            if(s[i]=='('){t++;c.push_back(s[i]);}
            if(s[i]==')'){
                n++;
                if(c.back()=='['){cout<<"no"<<endl;goto invail;}
                else c.pop_back();
            }
            if(s[i]=='['){m++;c.push_back(s[i]);}
            if(s[i]==']'){
                p++;
                if(c.back()=='('){cout<<"no"<<endl;goto invail;}
                else c.pop_back();
            }
            if(t<n){cout<<"no"<<endl;goto invail;}
            if(m<p){cout<<"no"<<endl;goto invail;}
            //if(c.back()=='('&&s[i]==']'){cout<<"no"<<endl;goto invail;}
            //if(c.back()=='['&&s[i]==')'){cout<<"no"<<endl;goto invail;}
        }
        cout<<"yes"<<endl;
        invail:;
    }
    return 0;
}