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<cstdio>
using namespace std;

int main(){
  char w;
  int c[2];  // (  ) [ ]

  while(1){
    cin>>w;
      if(w=='.') break;
    for(int i=0;i<2;i++){
      c[i]=0;    
    }
    while(1){
      if(w=='.') break;

      switch(w){
      case '(':
	c[0]++;
	break;
	
      case ')':
	c[0]--;	
	break;
	
      case '{':
	c[1]++;
      break;
      
      case '}':
	c[1]--;
	break;
      }
      if(c[1]<0||c[0]<0){ c[0]=1;break;}
      scanf("%c",&w);
     
    }
    if((c[0]==0) && (c[1]==0) ) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  } 
  
  return 0;
}

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

using namespace std;

int main(void){
  string s;
  stack<char> str;

  while(getline(cin,s) && s!="."){

    string ch;
    for(int i=0;i<s.size();i++)
      if(s[i]=='{' || s[i]=='(' || s[i]=='}' || s[i]==')')ch+=s[i];

    for(int i=0;i<ch.length();i++){
      
      if(ch[i]=='(' || ch[i]=='{')str.push(s[i]);
      if(ch[i]==')' && str.top()=='(')str.pop();
      if(ch[i]=='}' && str.top()=='}')str.pop();
    }

    cout << (str.empty()?"YES":"NO") << endl;

  }

  return 0;
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
int t[17][17];
int dp[64 * 1024];
int main() {
	string buf;
	while (getline(cin, buf), buf != ".") {
		vector<char> s;
		bool f = true;
		for (auto a : buf) {
			switch (a) {
			case '(':
			case '[':
				s.push_back(a);
				break;
			case ')':
				if (s.empty() || s.back() != '(') {
					f = false;
					break;
				}
				s.pop_back();
				break;
			case ']':
				if (s.empty() || s.back() != '[') {
					f = false;
					break;
				}
				s.pop_back();
				break;
			}
		}
		if (!s.empty())f = false;
		cout << (f ? "yes" : "no") << endl;
	}
	return 0;
}

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

using namespace std;

int main(int argc, char *argv[])
{
  for(;;) {
    string str;
    getline(cin, str);
    int l = str.length();
    if(l == 1) break;
    auto check = [l, &str]() {
      vector<char> st;
      for(int i = 0; i < l; i++) {
        char c = str[i];
        if(c == '(' || c == '[') {
          st.push_back(c);
        } else if(c == ')') {
          if(st.size() == 0) return false;
          if(st.back() == '(') {
            st.pop_back();
          } else {
            return false;
          }
        } else if(c == ']') {
          if(st.size() == 0) return false;
          if(st.back() == '[') {
            st.pop_back();
          } else {
            return false;
          }
        }
      }
      return st.size() == 0;
    };
    cout << (check() ? "yes" : "no") << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

struct edge{__int128 from, to, cost;};

int main(void) {
	while(true) {
		string s;
		getline(cin, s);
		if(s.size() == 1 && s[0] == '.')break;
		bool d = true;
		stack<ll> r;
		stack<ll> b;
		REP(i, s.size()) {
			if(s[i] == '(') r.push(b.size());
			if(s[i] == ')') {
				if(r.size() == 0) {
					d = false;
					break;
				}
				ll hoge = r.top();
				r.pop();
				if(hoge != b.size()) {
					d = false;
					break;
				}
			}
			if(s[i] == '[') b.push(r.size());
			if(s[i] == ']') {
				if(b.size() == 0) {
					d = false;
					break;
				}
				ll hoge = b.top();
				b.pop();
				if(hoge != r.size()) {
					d = false;
					break;
				}
			}
		}
		if(d && b.size() == 0 && r.size() == 0) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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 dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

string s;
stack<char> q;
vector<string> ans;

int main(){
	while(1){
		while(q.size())q.pop();
		getline(cin,s);
		if(s==".")break;
		for(int i=0;i<s.size();i++){
			if(s[i]=='['||s[i]=='('){
				q.push(s[i]);
			}else if(s[i]==')'){
				if(q.size()&&q.top()=='('){
					q.pop();
				}else{
					ans.push_back("no");
					
					goto A;
				}
			}else if(s[i]==']'){
				if(q.size()&&q.top()=='['){
					q.pop();
				}else{
					
					ans.push_back("no");
					goto A;
				}
			}
		}
		if(q.empty()){
		ans.push_back("yes");
		}else{
			ans.push_back("no");
		}
		A:;
	}
	while(ans.size()){
		cout<<ans.front()<<endl;
		ans.erase(ans.begin());
	}
	return 0;
}

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;
		
		for(int i=0;i<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()){
					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;
		}
	}
}