#include <iostream>
#include <fstream>
using namespace std;

int main()
{
fstream infile;
fstream outfile;
int i,si;
int k;

char c[255];

infile.open("DATA4.txt",ios::in);
if (!infile){cout<<"Fail to open DATA4.txt";}
outfile.open("OUT4.txt",ios::out|ios::trunc);
if (!outfile){cout<<"Fail to open Out4.txt";}
for(i=0;i<5;i++)
{       
infile.getline(c,255);
k=0; 
for(si=0;si<=255;si++)
{
if(c[si]=='('){

k=k+1;
}else if (c[si]==')'){

k=k-1;
}
if (c[si]==' '){break;}
continue;
}
if (k==0){
outfile<<"balanced"<<endl;
}
else{
outfile<<"not balanced"<<endl;
}
}

infile.close();
outfile.close();
return 0;
}

