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;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define all(x) begin(x),end(x)

#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld EPS = 1e-9;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    vi ns;

    for (;;) {
        string s; getline(cin,s);
        if (s == ".") break;

        bool valid = 1;
        stack<char> stk;
        for (char c : s) {
            if (c == '(' or c == '[') stk.push(c);
            else if (c == ')') {
                if (stk.empty() or stk.top() != '(') {
                    valid = false;
                    break;
                }
                stk.pop();
            }
            else if (c == ']') {
                if (stk.empty() or stk.top() != '[') {
                    valid = false;
                    break;
                }
                stk.pop();
            }
        }

        cout << (valid and stk.size() == 0 ? "yes" : "no") << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(void) {
	string ch;
	getline(cin, ch);
	while (ch[0] != '.') {
		int i,ci = 0,cj=0;
		for (i = 0; ch[i] != '.'; i++) {
			if (ch[i] == '(') ci++;
			else if (ch[i] == ')') ci--;
			else if (ch[i] == '[') cj++;
			else if (ch[i] == ']') cj--;
			if (ci < 0 || cj < 0) break;
		}
		if (ci || cj) {
			cout << "no" << endl;
		}
		else {
			cout << "yes" << endl;
		}
		getline(cin, ch);
	}
	return 0;
}

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

int main(){
  char ch;
  int f1=0,f2=0;

  while(1){
    stack<int> S1,S2;
    f1=f2=0;
    scanf("%c",&ch);
    int i=0;
    if(ch=='.')break;
    while(1){
      if(i!=0) cin>>ch;
      
      if(ch=='.') break;
      if(ch=='('){
	S1.push(i);
	if(f2==1) f1=2;
	else f1=1;
      }
      else if(ch==')'&&S1.size()>0&&f2!=2){
	S1.pop();
	f1=0;
      }else if(ch=='['){
	S2.push(i);
	if(f1==1)f2=2;
	else f2=1;
      }else if(ch==']'&&S2.size()>0&&f1!=2){
	S2.pop();
	f2=0;
      }
      i++;
    }
    if(S1.size()==0&&S2.size()==0) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    scanf("%c",&ch);
  }
  
  return 0;
}

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

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

C++: #include<iostream>
#include<cstring>
#include<vector>
#include<string>
using namespace std;
string ca;
vector<int> v1;
int main(){
	int a,b,c;
	int i,j,k;
	bool flag;
	while(getline(cin,ca)){
		if(ca[0]=='.')break;
		flag=true;
		v1.clear();
		for(i=0;i<ca.size();i++){
			if(ca[i]=='(')v1.push_back(1);
			if(ca[i]=='[')v1.push_back(2);
			if(ca[i]==')'){
				if(v1.empty() || v1.back()!=1){
					flag=false;
					break;
				}
				v1.pop_back();
			}
			if(ca[i]==']'){
				if(v1.empty() || v1.back()!=2){
					flag=false;
					break;
				}
				v1.pop_back();
			}
		}
		if(!v1.empty())flag=false;
		if(flag)cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
}

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

#define INF INT_MAX
#define ll long long

using namespace std;

int main(){
	string str;
	while(true){
		getline(cin, str);
		if(str == "."){
			break;
		}
		vector<char> v;	//0:( 1:[
		bool flag = true;
		for(int i = 0;i < str.length();i++){
			if(str[i] == '('){
				v.push_back('(');
			}else if(str[i] == '['){
				v.push_back('[');
			}else if(str[i] == ')'){
				if(v.size() > 0 && v[v.size() - 1] == '('){
					v.pop_back();
				}else{
					flag = false;
					break;
				}
			}else if(str[i] == ']'){
				if(v.size() > 0 && v[v.size() - 1] == '['){
					v.pop_back();
				}else{
					flag = false;
					break;
				}
			}
		}
		if(v.size() > 0){
			flag = false;
		}

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

	return 0;
}

C++: 

#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <queue>
#include <map>
#include <stack>
using namespace std;
 
int dx[8]={1,-1,0,0,1,1,-1,-1};
int dy[8]={0,0,1,-1,-1,1,-1,1};
 
 
int main() {
string s;
	while(getline(cin,s)){
		cout<<s<<endl;
		if(s==".") break;
	int ans=1;
	int l=s.length();
	stack<int> st; 
	for(int i=0;i<l;i++){
		if(s[i]=='(') st.push(1);
		else if(s[i]=='[') st.push(2);
		else if(s[i]==')'){
		if(st.empty()==true){
		ans=0;
		break;		
		}
		if (st.top()==1){
		st.pop();		
		}
		else{
		ans=0;
		break;
		}
		}

else if(s[i]==']'){
if(st.empty()==true){
		ans=0;
		break;		
		}
		if (st.top()==2){
		st.pop();		
		}
		else{
		ans=0;
		break;
		}
}
		}
	if(ans==1 && st.empty()==true) cout<<"yes"<<endl;
	else cout<<"no"<<endl;
	}


	return 0;
 
   }