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

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

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

bool solve(string &s) {
  stack<int> st;
  for(int i = 0; i < (int)s.length(); ++i) {
    if(s[i] == '[') {
      st.push(1);
    }
    if(s[i] == '(') {
      st.push(2);
    }
    if(s[i] == ']') {
      if (st.top() != 1) return 0;
      st.pop();
    }
    if(s[i] == ')') {
      if(st.top() != 2) return 0;
      st.pop();
    }
  }
  return (st.empty() ? 1 : 0);
}

int main() {
  string s;
  while(getline(cin, s)) {
    if(s != ".") break;
    cout << (solve(s) ? "yes" : "no") << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{

    while (true) {
        string str;
        getline(cin, str);
        if (str == ".") {
            break;
        }
        stack<char> kakko;
        bool ok = true;
        for (const char c : str) {
            if (c == '.') {
                break;
            }
            if (c == '[') {
                kakko.push('[');
            } else if (c == ']') {
                if (not kakko.empty() and kakko.top() == '[') {
                    kakko.pop();
                } else {
                    ok = false;
                }
            } else if (c == '(') {
                kakko.push('(');
            } else if (c == ')') {
                if (not kakko.empty() and kakko.top() == '(') {
                    kakko.pop();
                } else {
                    ok = false;
                }
            }
        }
        if (ok and kakko.empty()) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;

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

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

using namespace std;

int main(){
    string s;
    while(getline(cin,s)){
        stack<char> st;
        bool flag=true;
        if(s==".")break;

        for(int i=0;i<s.size();i++){
            char ch=s[i];
            
            if(ch=='('||ch=='['){
                st.push(ch);
            }else if(ch==')'||ch==']'){
                if(st.empty()){
                    flag=false;
                    break;
                }else if(ch==')'&&st.top()=='('){
                    st.pop();
                }else if(ch==']'&&st.top()=='['){
                    st.pop();
                }else{
                    flag=false;
                    break;
                }
            }


        }

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

C++: #include<iostream>
#include<stack>
using namespace std;
string str;
int main(){
  while(1){
    getline(cin,str);
    if(str==".")break;
    bool flg=true;
    stack<char> st;
    for(int i=0;i<(int)str.size();i++){
      if(str[i]=='(')st.push(str[i]);
      else if(str[i]=='[')st.push(str[i]);
      else if(str[i]==')'){
	if(st.empty()||st.top()!='(')flg=false;
	else st.pop();
      }else if(str[i]==']'){
	if(st.empty()||st.top()!='[')flg=false;
	st.pop();
      }
    }
    if(st.empty()&&flg)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  string s;
  while (getline(cin, s), s != ".") {
    stack<char> t;
    rep(i, s.size()) {
      if (s[i] == '[' || s[i] == '(') t.push(s[i]);
      if (s[i] == ')') {
        if (t.size() && t.top() == '(') {
          t.pop();
        } else {
          cout << "no" << endl;
          goto next;
        }
      }
      if (s[i] == ']') {
        if (t.size() && t.top() == '[') {
          t.pop();
        } else {
          cout << "no" << endl;
          goto next;
        }
      }
    }
    cout << (t.size() ? "no" : "yes") << endl;
  next:;
  }
}