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<cstdio>
#include<stack>
#include<string>
using namespace std;

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

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

C++: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <string>
#include <climits>

#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define PRINT(STR) cout << (STR) << endl

typedef long long ll;
using namespace std;

int main() {
	cin.tie(0); //?????±?????????????????????
	ios::sync_with_stdio(false); //printf??¨??±??????????????????
	string str;
	while (str = "", getline(cin, str), str != ".") {
		stack<char> s;
		while (!s.empty()) {
			s.pop();
		}
		
		REP(i, str.size()) {
			if (str[i] == '[' || str[i] == '(') {
				s.push(str[i]);
			} else if (str[i] == ']') {
				if (s.size() == 0 || s.top() != '[') {
					PRINT("no");
					break;
				}
				s.pop();
			} else if (str[i] == ')') {
				if (s.size() == 0 || s.top() != '(') {
					PRINT("no");
					break;
				}
				s.pop();
			}
			if (i == str.size() - 1) {
				PRINT("yes");
			}
		}
	}
	return 0;
}

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

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
int main(void){
  string s;
  while(getline(cin,s),s!="."){
    int c,b;
    c = b = 0;
   // cout<<s.size()<<" "<<s<<endl;
    string n = "";
    bool f = true;
    rep(i,s.size()){
     // cout<<s[i];
      if(s[i] == '(')c++;
      if(s[i] == ')'){
        c--;
        if(c<=b){
          f = false;
          break;
        }
        //cout<<"c"<<c<<" "<<b<<endl;
//        cout<<i<<" "<<s[i]<<" "<<c<<" "<<b<<endl;
      }
      if(s[i] == '[')b++;
      if(s[i] == ']'){
        b--;
        //cout<<"b"<<c<<" "<<b<<endl;
        
        
      }
      //cout<<b<<" "<<c<<endl;
      if(b<0 || c<0){
        f = false;
        break;
      }
    }
    cout<<(f?"yes":"no")<<endl;
    //cout<<s<<endl;
  }
}

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

int main()
{
	string str;
	while (getline(cin, str), str != "."){
		stack<char> st;
		bool res = true;
		for (int p = 0; p < str.size(); p++){
			if (str[p] == '(' || str[p] == '['){
				st.push(str[p]);
			}
			else if (str[p] == ')' || str[p] == ']'){
				if (st.empty()){
					res = false;
					break;
				}
				char c = st.top(); st.pop();
				if ((c == '(' && str[p] == ']') || 
				    (c == '[' && str[p] == ')')){
					res = false;
					break;
				}
			}
		}
		printf(res ? "yes\n" : "no\n");
	}
	
	return 0;
}

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

int main()
{
    while (true)
    {
        string S;
        getline(std::cin, S);
        if (S == ".")
            break;

        // 丸括弧、角括弧
        bool OK = true;
        int maru = 0, kaku = 0;
        // 直前の左括弧が何だったか
        enum
        {
            _maru,
            _kaku
        };
        stack<int> prev;

        for (char ch : S)
        {
            if (ch == '(')
            {
                ++maru;
                prev.push(_maru);
            }
            else if (ch == '[')
            {
                ++kaku;
                prev.push(_kaku);
            }
            else if (ch == ')')
            {
                --maru;
                if (prev.empty() || prev.top() != _maru)
                {
                    OK = false;
                    break;
                }
                prev.pop();
            }
            else if (ch == ']')
            {
                --kaku;
                if (prev.empty() || prev.top() != _kaku)
                {
                    OK = false;
                    break;
                }
                prev.pop();
            }

            if (maru < 0 || kaku < 0)
            {
                OK = false;
            }
        }
        if (!(maru == 0 && kaku == 0))
        {
            OK = false;
        }
        cout << (OK ? "yes" : "no") << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <bitset>
#include <stack>
#include <cstdlib>
#define REP(i,n) for(int i = 0; n > i; i++)
#define MOD 1000000007
using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;
typedef long long int ll;
char str[101];
map<char, char> kako = { {'(',')'},{'[',']'} };
int is_balanced(int s) {
	for (int i = s+1; strlen(str) > i; i++) {
		if (str[i] == '(' || str[i] == '[') {
			i = is_balanced(i)+1;
			if (i == 0) return -1;
		}
		if (str[i] == ')' || str[i] == ']') {
			if(str[i] != kako[str[s]])
				return -1;
			else {
				return i;
			}
		}
	}
	return -1;
}

int main() {
	while (fgets(str,101, stdin)) {
		if (!strcmp(str, "."))
			return 0;
		bool f = true;
		REP(i, strlen(str)) {
			if (str[i] == '(' || str[i] == '[') {
				i = is_balanced(i)+1;
				if (i == 0) {
					printf("no\n");
					f = false;
					break;
				}
			}
		}
		if (f) printf("yes\n");
	}

	return 0;
}