#include <iostream>
#include <fstream>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <string>
#include <iterator>
#include <algorithm>
#include <numeric>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <cctype>
#include <assert.h>
#include <list>
#include <ext/hash_set>
#include <ext/hash_map>

using namespace __gnu_cxx;
using namespace std;

#define MP(a,b) make_pair(a,b)
#define i64 long long
#define pb push_back
#define For(i,a,b) for(typeof(a) i=(a);i<(b);i++)
#define Rev(i,a,b) for(typeof(a) i=(a);i>=(b);i--)
#define FOREACH(V,it) for(typeof(V.begin()) it=V.begin();it!=V.end();it++)
#define CLR(a,x) memset(a,x,sizeof(a))
#define ALL(x) x.begin(),x.end()

/**********************************************************************************/


int main(){
	ifstream fin("DATA4.txt"); ofstream fout("OUT4.txt");	
	int t=5;
	string s; int sz; char stack[1000];
	while (t--){
		fin >> s;
		bool bad=0;sz=0;
		For(i,0,s.size()){
			//cout << sz << ' ' << stack[sz-1] << ' ' << s[i]  << ' ' << bad << endl;
			if (s[i]=='(' || s[i]=='[' || s[i]=='{'){
				stack[sz++]=s[i];
			}
			if (s[i]==')'){
				if (!sz || stack[sz-1]!='(') bad=1; else sz--;
			}
			if (s[i]==']'){
				if (!sz || stack[sz-1]!='[') bad=1; else sz--;
			}
			if (s[i]=='}'){
				if (!sz || stack[sz-1]!='{') bad=1; else sz--;
			}
		}
		//cout << endl;
		if (!bad){ fout << "balanced" << endl; }else{  fout << "not balanced" << endl;}

	}			
	return 0;
}
