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 <bits/stdc++.h>
using namespace std;

int main(){
  
  string str;

  while(1){

    getline(cin, str);
    if(str[0] == '.') break;

    vector<char> v;

    for(int i = 0; i < (int)str.size(); i++){
      if(str[i] == '[' || str[i] == '('){
	v.push_back(str[i]);
      }else if(str[i] == ')'){
	if(v.empty()){
	  v.push_back(str[i]);
	  break;
	}

	  if(v.back() == '('){
	    v.pop_back();
	  }
	
      }else if(str[i] == ']'){
	if(v.empty()){
	  v.push_back(str[i]);
	  break;
	}

	  if(v.back() == '['){
	    v.pop_back();
	  }
      }
    }
    if(v.empty()) cout << "yes" << endl;
    else cout << "no" << endl;

  }
  
  return 0;
}

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

int main() {
  string s;
  while(getline(cin, s)) {
    if(s[0] == '.') break;

    bool b = true;
    stack<char> sta;
    for(int i = 0; i < s.size(); i++) {
      char c = s[i];
      if((c == ')' || c == ']') && sta.empty()) {
	b = false;
	break;
      }

      if(c == '(' || c == '[') {
	sta.push(c);
      }
      else if(c == ')' || c == ']') {
	if(c == ')' && sta.top() != '(') b = false;
	if(c == ']' && sta.top() != '[') b = false;
	sta.pop();
      }
    }
    if(b) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    while(getline(cin,s)&&s!="."){
        string c;
        for(int i=0;i<s.size();i++)if(s[i]==')'||s[i]=='('||s[i]=='['||s[i]==']')c+=s[i];
        stack<char> s;
        int f=1;
        for(int i=0;i<c.size();i++){
            if(s.empty()||c[i]=='('||c[i]=='[')s.push(c[i]);
            else if((s.top()=='('&&c[i]==')')||(s.top()=='['&&c[i]==']'))s.pop();
            else {f=0;break;}
        }
        if(s.empty())cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}

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

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

using namespace std;

int main()
{
  int end;
  stack <char> sta;

  while(1){
    string v;
    string t;
    string g;
    end = 0;

    while(1){
      cin>>v;
      t = t+v;

      for(auto s : v){
        if(s == '.'){
          end = 1;
          break;
        }
      }

      if(end == 1){
        break;
      }
    }

    if(t == "."){
      break;
    }

    for(auto e : t){
      if(e == '(' || e == '['){
        sta.push(e);
      }
      else if(e == ')'){
        auto t = sta.top();
        sta.pop();
        if(t != '('){
          g = "no";
          break;
        }
      }
      else if(e == ']'){
        auto t = sta.top();
        sta.pop();
        if(t != '['){
          g = "no";
          break;
        }
      }
      else{
        continue;
      }
    }

    if(g != "no"){
      g = "yes";
    }

    cout<<g<<endl;
  }
  return 0;
}

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

int main(){
  while(1){
    int a,j=0;
    char ch[101]; 
    while(1){
      scanf("%c",&ch[j]);
      if(ch[j]=='.')break;
      j++; 
    }
    if(j==0)break;
    int count=0,count1=0;
    for(int i=0;i<j;i++){
      if(ch[i]=='[') count++; 
      else if(ch[i]=='{')count1++;
      else if(ch[i]=='}')count1--;
      else if(ch[i]==']')count--;
    }  
    if(count==0 && count1==0)cout<<"yes"<<endl;
    else cout<<"no"<<endl;  
    char b;
    scanf("%c",&b);
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){

  while(1){
	char hoge[200];
	int i = 0;

	//	getline(cin, hoge);

	while(1){
	  scanf("%c",&hoge[i]);
	  if(hoge[i]=='\n') continue;
	  if(hoge[i]=='.') break;
	  i++;
	}
	if(hoge[0]=='.') break;

	int mini = 0;
	int big = 0;
	bool now[200] = {};
	int b=0;
 //????????§??????????????????

	REP(a,i){
	  if(hoge[a]=='('){
		mini++;
		b++;
		now[b] = false;
	  }else if(hoge[a]==')'){
		if(now[b] == false) {
		  mini--;
		  b--;
		}else break;
	  }else if(hoge[a]=='['){
		big++;
		b++;
		now[b] = true;
	  }else if(hoge[a]==']'){
		if(now[b] == true){
		  big--;
		  b--;
		}else break;
	  }
	  if(mini < 0||big < 0) break;
	}

	if(mini==0&&big==0) cout << "yes" << endl;
	else cout << "no" << endl;
  }
}

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

using namespace std;

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

    return 0;
}