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 <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main(){
	string s;
	while(getline(cin, s)){
		int ao=0, ac=0, bo=0, bc=0;	
		bool ans=true;
		
		for(int i=0; i<s.size(); ++i){
			if(s[i]=='(') ao++;	
			else if(s[i]==')') ac++;
			else if(s[i]=='[') bo++;
			else if(s[i]==']') bc++;
			
			if(ac>ao) ans=false;
			if(bc>bo) ans=false;
			if(!ans) break;
		}
		
		if(ac!=ao || bc!=bo) ans=false;
		
		if(ans) printf("yes\n");
		else printf("no\n");
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define PR pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;

#define int ll

// the balance of the world

signed main(){
  while(1){
    stack<char> s;
    string str;
    getline(cin, str);
    if(str==".") break;
    
    bool ans=1;
    for(int i=0; i<str.size(); i++){
      if(str[i]=='('||str[i]=='['){
        s.push(str[i]);
      }else if(str[i]==')'||str[i]==']'){
        if(s.empty()) ans=0;
        else if(str[i]==']'&&s.top()=='['){
          s.pop();
        }else if(str[i]==')'&&s.top()=='('){
          s.pop();
        }else{
          ans=0;
        }
      }else if(str[i]=='.'){
        if(ans) cout<<"yes"<<en
        else cout<<"no"<<en
          break;
      }
    }
  }
  RE
}

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{
                    flag = 0;
                    break;
                }
            }

            if(str[i] == ']'){
                if(s.top() == ']'){
                    s.pop();
                }else{
                    flag = 0;
                    break;
                }
            }
        }
        
        if(flag == 1 && s.top() == '0') cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;

}

C++: #include <stdio.h>

int closejudge(char tmp,char *c){
	int flag = 0;
	char wtmp, retmp;
	if(tmp == ')')
		wtmp = ']';
	else
		wtmp = ')';
	*c = getchar();
	while(*c != tmp && flag == 0){
		if(*c == '.' || *c == wtmp)
			flag = 1;
		else if(*c == '(' || *c == '['){
			if(*c == '(')
				retmp = ')';
			else
				retmp = ']';
			flag = closejudge(retmp,c);
		}
		if(*c != '.')
			*c = getchar();
	}
	return flag;
}
int main(void){
	char c,tmp;
	int flag;
	c = getchar();
	while(c != '.'){
		flag = 0;
		while(c != '.' && flag == 0){
			if(c == ')' || c == ']')
				flag = 1;
			if(c == '(' || c == '['){
				if(c == '(')
					tmp = ')';
				else
					tmp = ']';
				flag = closejudge(tmp,&c);
			}
			if(c != '.')
				c = getchar();
		}
		while(c != '\n')
			c = getchar();
		if(flag == 0)
			printf("yes\n");
		else
			printf("no\n");
		c = getchar();
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <stack>
using namespace std;
string s;
bool solve() {
  stack<char> st;
  for(int i = 0; i < (int)s.length(); ++i) {
    if(s[i] == '[') st.push(s[i]);
    if(s[i] == ']') {
      if(st.empty() || st.top() != '[') return 0;
      st.pop();
    }
    if(s[i] == ')') {
      if(st.empty() || st.top() != ')') return 0;
      st.pop();
    }
  }
  return st.empty();
}

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

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

using namespace std;

bool solve(string S)
{
	stack<char> s;

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

		if (s.empty()) { return false; }

		if (S[i] == ')' || S[i] == ']')
		{
			if (s.top() != (S[i] == ')' ? '(' : '['))
			{
				return false;
			}
			
			s.pop();
		}
	}

	return s.empty();
}

int main()
{
	string S;

	while (true)
	{
		S = "";

		while (S == "")
		{
			getline(cin, S);
		}

		if (S == ".") { break; }

		cout << (solve(S) ? "yes" : "no") << endl;
	}
	
	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 goto fail;
            }
            else if(s[i]==')'){
                if(w.top()=='(')w.pop();
                else goto fail;
            }
            if(d)break;
        }
        if(w.empty())cout<<"yes"<<endl;
        else fail:cout<<"no"<<endl;
    }
    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	string s;
	while(getline(cin,s),s!="."){
		stack<char> t;
		bool flag=true;
		for(char c:s){
			if(c=='['||c=='(')t.push(c);
			if(c==']'){
				if(t.empty()||t.top()!='['){
					flag=false;
					break;
				}else t.pop();
			}
			if(c==')'){
				if(t.empty()||t.top()!='('){
					flag=false;
					break;
				}else t.pop();
			}
			if(c=='.'&&!t.empty())flag=false;
		}
		// reverse(all(s));
		// while(!t.empty())t.pop();
		// for(char c:s){
		// 	if(c==']'||c==')')t.push(c);
		// 	if(c=='['){
		// 		if(t.empty()||t.top()!=']'){
		// 			flag=false;
		// 			break;
		// 		}else t.pop();
		// 	}
		// 	if(c=='('){
		// 		if(t.empty()||t.top()!=')'){
		// 			flag=false;
		// 			break;
		// 		}else t.pop();
		// 	}
		// }
		cout<<(flag?"yes":"no")<<endl;
	}
	return 0;
}