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 <cctype>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

string solve(string s) {
    // queue<int> stack;
    stack<int> stack;
    bool flag = true;
    int check;

    for (int i = 0; i < s.length(); i++) {
        if (s[i] == '(')
            stack.push(1);
        else if (s[i] == '[')
            stack.push(2);
        if (s[i] == ')') {
            if (stack.empty()) return "no";
            check = stack.top();
            stack.pop();
            if (check != 1) {
                return "no";
            }
        } else if (s[i] == ']') {
            if (stack.empty()) return "no";
            check = stack.top();
            stack.pop();
            if (check != 2) {
                return "no";
            }
        }
    }
    // if (!stack.empty()) flag = false;
    // if (flag) return "yes";
    // return "no";
    return stack.empty() ? "yes" : "no";
}

int main() {
    string st;
    vector<string> ans;
    while (1) {
        // cout << 1;
        getline(cin, st);
        // cout << 2;
        if (st == ".") break;
        // cout << 3;
        // cout << st << endl;
        ans.push_back(solve(st));
        // cout << 4;
    }
    for (auto k : ans) cout << k << endl;
}

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

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

C++: #include<iostream>
#include<strstream>
#include<stack>
#include<utility>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<climits>
#include<map>
#include<string>
#include<sstream>

using namespace std;

#define mp make_pair
#define rep(i,n) for( int i = 0; i < n; i++ )
typedef vector<int,int> v;
typedef long long int ll;

int main()
{
	string str;
	while( getline( cin,str ) )
	{
		stack<char> stc;
		if( str[0] == '.' ) break;
		rep( i,str.size() )
		{
			if( str[i] == '(' || str[i] == '[' )
				stc.push( str[i] );
			if( str[i] == ')' || str[i] == ']' )
			{
                if ( stc.empty() ) {
                    goto owari;
                }
                if( stc.top() == '(' && str[i] == ')' ){
					stc.pop();}
				else if( stc.top() == '[' && str[i] == ']' )
					stc.pop();
				else
					goto owari;
                
			}
		}
		if( stc.empty() )
			puts("yes");
		else{
        owari:
			puts("no");
		}
	}
    
	return 0;
}

C++: #include "limits"
#include "algorithm"
#include "iostream"
#include "cmath"
#include "string"
#include "map"
#include "iomanip"
#include "stack"
using namespace std;

int main(){
  char S[110];
  bool FLAG;
  stack<char> temp;
  while(1){
    FLAG=true;
    gets(S);
    if(S[0]=='.')break;
    for(int i=0;S[i]!='.';++i){
      if(S[i]=='(' || S[i]=='[')temp.push(S[i]);
      if(S[i]==')'){
        if(temp.empty()){
          FLAG=false;
          break;
        }
        char a=temp.top();
        temp.pop();
        if(a!='('){
          FLAG=false;
          break;
        }

      }
      if(S[i]==']'){
        if(temp.empty()){
          FLAG=false;
          break;
        }
        char a=temp.top();
        temp.pop();
        if(a!='['){
          FLAG=false;
          break;
        }
      }
    }
    if(FLAG)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
}

C++: // Tenbin_1173.cpp
#include <iostream>
#include <string>
using namespace std;
string lol(string str){
	string r;
	int cbcount,sbcount;
	int charcount = 0;
	cbcount = 0;
	sbcount = 0;
	while(true){
		if(str[charcount] == '('){
			cbcount++;
		}else if(str[charcount] == ')'){
			cbcount--;
		}else if(str[charcount] == '['){
			sbcount++;
		}else if(str[charcount] == ']'){
			sbcount--;
		}else if(str[charcount] == '.'){
			break;
		}
		if(cbcount<0||sbcount<0){
			r = "no";
		return r;
	}
		charcount ++;
	}
	if(cbcount=0&&sbcount==0){
		r = "yes";
		return r;
	}
	return "no";
}
int main()
{
	string str;
	while(getline(cin,str)){
		if(str=="."){
			break;
		}else{
		//	cout << endl;
		}
		cout << lol(str)<<endl;
	}
	return 0;
}

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

bool solve(string str) {
  stack<char> stk;
  for (char c : str) {
    if (c == '[') {
      stk.push(c);
    } else if (c == '(') {
      stk.push(c);
    } else if (c == ']') {
      if (stk.empty() or stk.top() != '[') {
        return false;
      }
      stk.pop();
    } else if (c == ')') {
      if (stk.empty() or stk.top() != '(') {
        return false;
      }
      stk.pop();
    }
  }
  return stk.empty();
}

int main() {
  string query;
  while (getline(cin, query) and query != ".") {
    cout << (solve(query) ? "yes" : "no" ) << endl;
  }
}

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

using namespace std;

int main(void){
	string str;

	while(getline(cin,str)){
		
		stack<char> st;
		bool flag=true;
		
		if(str[0]=='.'){
			break;
		}
		
		for(int i=0;i<str.size();i++){
			
			if(str[i]=='('|| str[i]=='['){
				st.push(str[i]);
			}
						
			else if(str[i]==')'){
				if(st.empty()){
					flag=false;
				}
				else if('('==st.top()){
					st.pop();
				}
			}
			
			else if(str[i]==']'){
				if(st.empty()){
					flag=false;
				}
				else if('['==st.top()){
					st.pop();
				}
			}
		}
		
		if(flag && st.empty()){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}

		
	}
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>

using namespace std;

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