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

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}

signed main() 
{
  string s;
  while(getline(cin,s),s!=".")
  {
    stack<char> t;
    bool judge=true;
    rep(i,s.size())
    {
      if(s[i]=='('||s[i]=='[') t.push(s[i]);
      else if((s[i]==')'||s[i]==']'))
      {
        if(t.empty())
        {
          judge=false;
          break;
        }
        else if(s[i]==')'&&t.top()=='(') t.pop();
        else if(s[i]==']'&&t.top()=='[') t.pop();
      } 
    }
    if(!t.empty()) judge=false;
    if(judge) print("yes");
    else print("no");

  }

  return 0;
}

C++: #include <bits/stdc++.h>
#define REP(a,b,c) for(int a=b; a<(int)c; a++)
#define REPE(a,b,c) for(int a=b; a<=(int)c; a++)
#define REPD(a,b,c) for(int a=b; a>=(int)c; a--)
#define rep(a,b) REP(a,0,b)
#define repd(a,b) REPD(a,b,0)
typedef long long int ll;
using namespace std;
string str;
int pos;
bool DFS(char c){
  // cout << endl << endl;
  //cout << pos << " " << c << endl;
  while(true){
    if(pos >= str.size()){
      return c==' ';
    }
    char ch = str[pos];
    //cout << ch;
    switch(ch){
    case  '[':
    case  '(':
      pos++;
      if(!DFS(ch)) return false;
      break;
    case  ']':
      // cout << endl;
      //cout <<pos<<":"<< c << ch << endl;
      return c=='[';
      break;
    case  ')':
      //cout << endl;
      //cout <<pos<<":"<< c << ch << endl;
      return c=='(';
      break;
    }
    pos++;
  }
  return true;
}

int main(){
  while(true){
    getline(cin,str);
    if(str == ".") break;
    pos = 0;
    if(DFS(' ')){
      cout << "yes" << endl;
    }else{
      cout << "no" << endl;
    }
  }
  return 0;
}

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


int main(){
	string str;
	while(getline(cin,str)&& str!="."){
		string z;
		for(int i=0;i<str.size();i++)
			if(str[i]=='(' || str[i]==')' || str[i]=='[' || str[i]==']')
				z+=str[i];
		stack<char> s;
		bool f=true;
		for(int i=0;i<z.length();i++){
			if(z.empty() || z[i] == '(' || z[i] == '[')
				s.push(z[i]);
			else if( (s.top() == '(' && z[i] == ')') || (s.top() == '[' && z[i] == ']') )
				s.pop();
			else{
				f=false; 
				break;
			}
		}
		cout << (f && s.empty()?"yes":"no") << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)


int main() {
	string s;
	while (cin >> s) {
		using P = pair<char, int>;
		queue<P> que;
		que.emplace('a', -1);
		bool ok = true;
		for (char c : s) {
			if (c == '('){ if(que.front().first == '(') que.front().second++; else que.emplace('(', 1); }
			if (c == ')'){ if(que.front().first == ')') que.front().second--; else ok = false; }
			if (c == '{'){ if(que.front().first == '{') que.front().second++; else que.emplace('{', 1); }
			if (c == '}'){ if(que.front().first == '}') que.front().second--; else ok = false; }
			if (que.front().second == 0) que.pop();
		}
		cout << (ok && que.size() == 1 ? "yes" : "no");
	}
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
	string s;
	while(getline(cin,s)){
		if(s==".") break;
		int a[100][100],k1=0,k2=0,b=0,c1=0,c2=0,c3=0,c4=0;
		for(int i=0;i<100;i++){
			for(int j=0;j<100;j++){
				a[i][j]=0;
			}
		}
		a[50][50]=1;
		int len=s.size();
		for(int i=0;i<len;i++){
			if(s[i]=='('){
				k1++;
				a[50+k1][50+k2]++;
				c1++;
			}
			else if(s[i]==')'){
				a[50+k1][50+k2]=0;
				k1--;
				if(a[50+k1][50+k2]==0){
					b++;
				}
				c2++;
			}
			else if(s[i]=='['){
				k2++;
				a[50+k1][50+k2]++;
				c3++;
			}
			else if(s[i]==']'){
				a[50+k1][50+k2]=0;
				k2--;
				if(a[50+k1][50+k2]==0){
					b++;
				}
				c4++;
			}
		}
		if(b==0&&c1==c2&&c3==c4){
			cout<<"yes"<<endl;
		}
		else{
			cout<<"no"<<endl;
		}
		string s(100,'a');
	}
    return 0;
}