#include <iostream>
#include <bits/stdc++.h>
using namespace std;
bool isbracketbalanced( string expr )
{
stack<char> s;
char x;
for( int i = 0; i < expr.length() ; i++ )
{
if( expr[i] == '(' || expr[i] == '[' || expr[i] == '{' )
{
s.push(expr[i]);
continue;
}
if(s.empty())
{
return false;
}
switch( expr[i] )
{
case ')':
x = s.top();
if( x == '(' )
s.pop();
else
return false;
break;
case '}':
x = s.top();
if( x == '{')
s.pop();
else
return false;
break;
case ']':
x = s.top();
if( x == '[' )
s.pop();
else
return false;
break;
}
}
if(s.empty())
{
return true;
}
else
{
return false;
}
}
int main() {
// your code goes here
string test1 = "({[]})";
string test2 = "({[]}])";
string test3 = "({[]}))";
if(isbracketbalanced(test3))
cout << "bracket balanced";
else
cout << "bracket not balanced";
return 0;
}