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<string>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#define rep(i,n) for(int i=0;i<n;i++)
#define foreach(r,n,p) for(r::iterator it=p.begin();it!=p.end();++it)
#define MARU 0
#define KAKU 1

using namespace std;
int main()
{
    while(1)
    {
        string s;
        string ans = "yes";
        getline(cin,s);
        if(cin.eof())break;
        int l = s.size();
        int maru =0, kaku = 0;
        int now=0;
        for(int i=0;i<l;i++)
        {
            if(s[i]=='('){maru++; now = MARU; continue;}
            if(s[i]=='['){kaku++; now = KAKU; continue;}
            if(s[i]==']')
            {
                if(now == MARU || (kaku==0) ){ans = "no"; break;}
                kaku--;
            }
            if(s[i]==')')
            {
                if(now == KAKU || (maru==0) ){ans = "no";break;}
                maru--;
            }
        }
        if((kaku!=0)||(maru!=0))ans= "no";
        
        cout << ans << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
void solve(int m,int n){
    //cout<<"$$"<<endl;
    vector<int> v;
    int j;
    v.push_back(m);
    for(int i=0;i<n;i++){
        for(j=v.back()+1;1;j++){
            bool s=true;
            //cout<<j<<endl;
            for(int x:v){
                if(!(j%x)){
                    //cout<<"?"<<endl;
                    s=false;
                    break;
                    
                }
                    
            }
            if(s){
                //cout<<"!"<<j<<endl;
                v.push_back(j);
                break;
            }
        }
        //cout<<"!"<<t<<endl;
        //    v.push_back(t);
    }
    cout<<v.back()<<endl;
    //cout<<endl;
    //for(int x:v){
    //            cout<<x<<" "<<endl;
    //        }
    //        cout<<endl;
    //cout << v.size();
}

int main(void){
    int m,n;
    while(cin>>m>>n,m){
        solve(m,n);
    }
    
}

C++: #ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

int main()
{
	string str;
	vector<char>a;
	while (1)
	{
		getline(cin, str);
		if (str == ".")break;
		a.clear();
		bool f = 1;
		for (auto x : str)
		{
			switch (x)
			{
				case '[':a.push_back('['); break;
				case '(':a.push_back('('); break;
				case ']':{
						if (!a.empty() && *a.rbegin() == '[')
						{
							a.pop_back();
						} else
						{
							f = 0;
						}
						break;
					}
				case ')':{
						if (!a.empty()&&*a.rbegin() == '(')
						{
							a.pop_back();
						} else
						{
							f = 0;
						}
						break;
					}
				default:
					break;
			}
		}
		if (!a.empty())
		{
			f = 0;
		}
		cout << (f ? "yes" : "no") << endl;
	}
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
 


int main(){
	string s;
	while(getline(cin,s)){
		int a = 0, b = 0;
		for(int i=0; i<s.size(); i++){
			if(s[i]=='(') a++;
			else if(s[i]==')') a--;
			else if(s[i]=='[') b++;
			else if(s[i]==']') b--;
		}
		if(a==0 && b==0) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
}

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

using namespace std;

int main() {
  while (true) {
    string s;
    getline(cin, s);
    if (s == ".") break;
    string ans = "yes";
    std::stack<char> st;
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] == '(') {
        st.push('(');
      } else if (s[i] == '[') {
        st.push('[');
      } else if (s[i] == ')') {
        if (st.empty() || st.top() != '(') {
          ans = "no";
        }
        if (!st.empty()) st.pop();
      } else if (s[i] == ']') {
        if (st.empty() || st.top() != '[') {
          ans = "no";
        }
        if (!st.empty()) st.pop();
      }
    }
    if (st.size() != 0) ans = "no";

    cout << ans << endl;
  }
}

C++: #include <iostream>

using namespace std;

int main()
{
	while(1){
		char input[128];
		int hmMaru = 0,hmKaku = 0;
		bool fAns = true;

		cin >> input;
		if(strcmp(input,".") == 0)
			break;

		for(int i = 0;i < strlen(input);i++)
		{
			bool fEnd = false;
			switch(input[i])
			{
				case '(':
					hmMaru++;
					break;
				case ')':
					hmMaru--;
					if(hmMaru != 0){
						fAns = false;
						fEnd = true;
					}
					break;
				case '[':
					hmKaku++;
					break;
				case ']':
					hmKaku--;
					if(hmKaku != 0){
						fAns = false;
						fEnd = true;
					}
					break;
				case '.':
					fEnd = true;
					break;
			}
			if(fEnd == true){
				if(fAns == true){
					cout << "yes" << endl;
				}else{
					cout << "no" << endl;
				}
			}
		}
	}
}