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

int main(void) {
    char str[105];
    while(1){
        
        cin.getline(str, sizeof(str));

        if(str[0] == '.') break;
        stack<char> s;
        s.push('0');
        int flag = 1;
        for(int i = 0; str[i] != '\0'; i++){
            if(str[i] == '(') s.push(')');
            if(str[i] == '[') s.push(']');
            if(str[i] == ')'){
                if(s.top() == ')'){
                    s.pop();
                }else{
                    cout << "no" << endl;
                    flag = 0;
                    break;
                }
            }
            if(str[i] == ']'){
                if(s.top() == ']'){
                    s.pop();
                }else{
                    cout << "no" << endl;
                    flag = 0;
                    break;
                }
            }
        }
        
        if(flag == 1 && s.top() == '0') cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;

}

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

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

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	string s;
	while (getline(cin,s),s!=".") {
		stack<char>S;
		for (int i = 0; i < s.length(); i++) {
			if (s[i] == '(' || s[i] == '[') {
				S.push(s[i]);
			}
			
			else switch (s[i]) {
			case ')':if (!S.empty()&&S.top() == '(')S.pop(); break;
			case ']':if (!S.empty()&&S.top() == '[')S.pop(); break;
			default: break;
			}
		}
		if (S.empty()) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<string>

std::string str;

bool calc(int p){
	for(int i=p+1;i<str.size();i++){
		if(str[i]=='('){
			if(calc(i))return true;
			else return false;
		}
		if(str[i]==')'){
			if(str[p]=='(')return true;
			else return false;
		}
		if(str[i]=='['){
			if(calc(i))return true;
			else return false;
		}
		if(str[i]==']'){
			if(str[p]=='[')return true;
			else return false;
		}
	}
	return false;
}

int main(){
	while(1){
		int l=0,l2=0;
		while(1){
			std::getline(std::cin,str);
			if(str[str.size()-1]=='.')break;
			else{
				std::string a;
				std::getline(std::cin,str);
				str=str+a;
			}
		}
		if(str==".")break;
		for(int i=0;i<str.size();i++){
			if(str[i]=='(')l++;
			if(str[i]==')')l--;
			if(str[i]=='[')l2++;
			if(str[i]==']')l2--;
			if(l<0||l2<0){
				puts("no");
				goto end;
			}
			if(str[i]=='('||str[i]=='['){
				if(!calc(i)){
					std::cout<<"no"<<std::endl;
					goto end;
				}
			}
		}
		if(l==0&&l2==0)std::cout<<"yes"<<std::endl;
		else std::cout<<"no"<<std::endl;
		end:;
	}
	return 0;
}

C++: #include <iostream>
#include <stack>
#include <stdio.h>
using namespace std;
int main(){
  
  int flag = 0;
  while(true){
    stack<char> st;
    char tmp;
    scanf("%c",&tmp);
    if(tmp == '.')return 0;
    if(tmp != '\n'){
      while(true){
	if(tmp == '(' || tmp == '['){
	  //cout << "入力" << tmp << endl;
	  st.push(tmp);
	}
	else if(tmp == ')' || tmp == ']'){
	  if(tmp == ')')tmp = '(';
	  if(tmp == ']')tmp = '[';
	  if(st.empty()){
	    flag = 1;
	    //break;
	  }
	  else if(st.top() != tmp){
	   
	    //  cout << tmp << endl;
	    flag = 1;
	  }
	  if(flag != 1)st.pop();
	}else if(tmp == '.'){
	  break;
	}
	scanf("%c",&tmp);
      }
    
      if(flag != 1){
	cout << "yes" << endl;
      }else cout << "no" << endl;
      flag = 0;
    }
  }
}

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

int main() {
	
	while(true){
		string str;
		getline( cin, str);
		if( str == "." ) break;
		stack<char> s;
		
		bool yes = true;
		for(char c : str){
			if( c=='(' || c=='['){
				s.push(c);
			}
			else if( c==')'){
				if( s.empty() || s.top() != '(' ){
					yes=false;
					break;
				}
				s.pop();
			}
			else if( c==']'){
				if( s.empty() || s.top() != '[' ){
					yes=false;
					break;
				}
				s.pop();
			}
		}
		cout << (yes?"yes":"no") << 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();
}

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

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

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	
	while(1){
		string str;
		getline(cin , str);
		stack<char> s;
		bool f=true;
		if(str=="."){
			break;
		}

		string ss;

		for(int i=0;i<str.size();i++){
			if(str[i]=='(' || str[i]==')' || str[i]=='[' || str[i]==']')
				ss+=str[i];
		}

		for(int i=0;i<ss.size();i++){
			if(ss.empty() || ss[i]=='(' || ss[i]=='[')
				s.push(ss[i]);

			else{
				if( (s.top()=='(' && ss[i]==')') || (s.top()=='[' && ss[i]==']') ){
					s.pop();
				}
				else{
					f=false;
					break;
				}
			}
		}
		if(f)
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	return 0;
}