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++: // TheBalanceOfTheWorld.cpp
#include <iostream>
using namespace std;

bool isYes(char input[]);

int main()
{
	char Input[100][101];
	int i=0;
	while(true){
		cin.getline(Input[i], sizeof(Input[i]));
		if(Input[i][0] == '.') break;
		i++;
	}
	for(int j=0; j<i; j++){
		if(isYes(Input[j])){
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}
	return 0;
}

bool isYes(char Input[])
{
	enum __FLAG{NONE, PARE, BLAC};
	int prep[50], prepnum=0, p=NONE;
	for(int i=0; Input[i]!='.'; i++){
		if(Input[i] == '('){
			if(p != NONE){
				prep[prepnum] = p;
				prepnum++;
			}
			p=PARE;
		} else if(Input[i] == '['){
			if(p != NONE){
				prep[prepnum] = p;
				prepnum++;
			}
			p=BLAC;
		} else if(Input[i] == ')'){
			if(p!=PARE){
				return false;
			} else {
				if(prepnum==0) p=NONE;
				else {
					p = prep[prepnum-1];
					prepnum--;
				}
			}
		} else if(Input[i] == ']'){
			if(p!=BLAC){
				return false;
			} else {
				if(prepnum==0) p=NONE;
				else {
					p = prep[prepnum-1];
					prepnum--;
				}
			}
		}
	}
	return true;
}

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

int main() {
	string s;
	while (getline(cin, s)) {
		if (s == ".")break;

		int flg = 1;
		stack<char>st;
		for (int i = 0;i < s.size();i++) {
			if (s[i] == '(') {
				st.push(s[i]);
			}
			else if (s[i] == '[') {
				st.push(s[i]);
			}
			else if (s[i] == ')') {
				if (!st.empty()&&st.top() == '(')st.pop();
				else {
					flg = 0;
					break;
				}
			}
			else if (s[i] == ']'){
				if(!st.empty()&&st.top()=='[') st.pop();
				else {
					flg = 0;
					break;
				}
			}
		}

		if (flg == 1)cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

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

int main()
{
	string str;
	while (getline(cin, str), str != "."){
		stack<char> st;
		bool res = true;
		for (int p = 0; p < str.size(); p++){
			if (str[p] == '(' || str[p] == '['){
				st.push(str[p]);
			}
			else if (str[p] == ')' || str[p] == ']'){
				if (st.empty()){
					res = false;
					break;
				}
				char c = st.top(); st.pop();
				if ((c == '(' && str[p] == ']') || 
				    (c == '[' && str[p] == ')')){
					res = false;
					break;
				}
				
			}
		}
		printf(res && st.empty() ? "yes\n" : "no\n");
	}
	
	return 0;
}

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

using namespace std;

int main(){
	int maru=0,kaku=0;

	string str;
	while(getline(cin,str)){
		if(str.at(0)=='.')break;
		maru=0;
		kaku=0;
		int flag=0;
		stack<int> s;

		for(int i=0;i<str.size();i++){
			if(str.at(i)=='('){
				maru++;
				s.push(1);
			}
			else if(str.at(i)==')' && maru>0){
				if(s.top()==1){
					maru--;
					s.pop();
				}
				else{
					cout<<"no"<<endl;
					flag=1;
				}
			}
			if(str.at(i)=='['){
				kaku++;
				s.push(2);
			}
			else if(str.at(i) ==']' &&kaku>0){
				if(s.top()==2){
					kaku--;
					s.pop();
				}
				else{
					cout<<"no"<<endl;
					flag=1;
				}
			}
			if(flag==1)break;
		}
		if(flag==1)continue;

		if(s.size()==0){
			cout<<"yes"<<endl;
		}
		else{
			cout<<"no"<<endl;
		}
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n,m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

int main()
{
	while (1) {
		getline(cin, s);
		if (s.size() == 1 && s[0] == '.') {
			return 0;
		} else {
		NEXT:
			stack<char> v;
			REP(i, s.size())
			{
				if (s[i] == '(') {
					v.push(s[i]);
				}

				if (s[i] == ')') {
					if (v.empty() || v.top() != '(') {
						cout << "no" << endl;
						while (!v.empty()) {
							v.pop();
						}
						goto NEXT;
					} else {
						v.pop();
					}
				}

				if (s[i] == '[') {
					v.push(s[i]);
				}

				if (s[i] == ']') {
					if (v.empty() || v.top() != '[') {
						cout << "no" << endl;
						while (!v.empty()) {
							v.pop();
						}
						goto NEXT;
					} else {
						v.pop();
					}
				}
			}

			if (v.empty()) {
				cout << "yes" << endl;
			} else {
				cout << "no" << endl;
			}

			while (!v.empty()) {
				v.pop();
			}
		}
	}
}

C++: #include <iostream>
#include <stdio.h>
#include <stack>
using namespace std;
void empty(){
  while(getchar()!='.');
   
}
int main(){
  char i;
  char* tmp;
  int flag;
  stack<char> s;
  i=getchar();
  s.push(0);
  if(i=='.') return 0;
  do{

    if(i=='\n') continue;
    if(i!='.') flag=0;
    
    if(i=='['|| i=='(' ){

      s.push(i);

    }

    if(i==']'){

      if(s.top()=='[') {
	
	s.pop();
	continue;
      }
      else {
	cout <<"no\n";
	empty();
	s.empty();
	s.push(0);
      }
    }
    if(i==')')
      if(s.top()=='('){
	s.pop();
	continue;
      }
      else {
	cout <<"no\n";
	empty();
	s.empty();
	s.push(0);  
    }

    if(i=='.'){
      if(flag) return 0;
      if(s.top()){

	cout <<"no\n";
	s.empty();
	s.push(0);  

      }
      else {
	cout <<"yes\n";
	flag=1;	
      }
    }

  } while(i=getchar());
}

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;
		
		if(str[0]=='.'){
			break;
		}
		
		for(int i=0;i<str.size();i++){
			
			if(str[i]=='.'){
                           break;          
                        }                        

                        if(str[i]=='('|| 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;
		}

		
	}
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>
#include <stack>

using namespace std;

int main() {
  while( true ) {
	string input;
	getline( cin, input );
	if ( input == "." ) break;

	bool success = true;
	stack<char> s;
	for ( char ch : input ) {
	  if ( ch == '[' or ch == '(' ) {
		s.push( ch );
	  } else if ( ch == ']' ) {
		if ( s.empty() or s.top() != '[' ) {
		  success = false;
		  break;
		}
		s.pop();
	  } else if( ch == ')' ) {
		if ( s.empty() or s.top() != '(' ) {
		  success = false;
		  break;
		}
		s.pop();
	  }
	}
	if ( not s.empty() ) success = false;
	
	if ( success ) {
	  cout << "yes" << endl;
	} else {
	  cout << "no" << endl;
	}
  }
}