import java.io.*;
import java.util.*;

// The "Template" class.
public class AllIsBalanced
{
    public static void main (String[] args) throws IOException
    {
	// Open up the input and output file for IO purpose
	FileReader inFile = new FileReader ("DATA4.txt");
	FileWriter outFile = new FileWriter ("OUT4.txt");

	// Link the input and output file for
	BufferedReader in = new BufferedReader (inFile);
	BufferedWriter out = new BufferedWriter (outFile);

	int lefta = 0, leftb = 0, leftc = 0;
	int righta = 0, rightb = 0, rightc = 0;
	String input = "", line;
	String temp = "";


	// Keep reading as long as not end of file (eof)
	while ((line = in.readLine ()) != null)
	{
	    for (int i = 0 ; i != line.length () ; i++)
	    {
		String[] bracket = new String [line.length()];
		int[] place = new int [line.length()];

		temp = line.substring (i, i + 1);
 
		if (temp.equals ("("))
		    lefta += 1;
		else if (temp.equals (")"))
		    righta += 1;
		else if (temp.equals ("["))
		    leftb += 1;
		else if (temp.equals ("]"))
		    rightb += 1;
		else if (temp.equals ("{"))
		    leftc += 1;
		else if (temp.equals ("}"))
		    rightc += 1;
	    }
	    if (lefta == righta && leftb == rightb && leftc == rightc)
		out.write ("balanced");
	    else
		out.write ("not balanced");

	    lefta = 0;
	    leftb = 0;
	    leftc = 0;
	    righta = 0;
	    rightb = 0;
	    rightc = 0;

	    out.newLine ();
	}

	// Close input and output file
	in.close ();
	out.close ();

    } // main method
} // End of Class

