#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define max 100
int ismatching(char open,char close)
{
    return (open=='('&&close==')')||(open=='{'&&close=='}')||(open=='['&&close==']');
}
int main()
{
    char s[max];
    scanf("%s",s);
    int size=strlen(s);
    if(size<1||size>100)
    {
        printf("Invalid input");
        return 0;
        
    }
    char stack[max];
    int top=-1;
    for(int i=0;i<size;i++)
    {
        char ch=s[i];
        if(isalnum(s[0])||)
        {
            printf("Invalid input");
            return 0;
        }
        if(ch=='('||ch=='{'||ch=='[')
        {
            stack[++top]=ch;
            
        }
        else if(ch==')'||ch=='}'||ch==']')
        {
            if(top==-1||!ismatching(stack[top],ch))
            {
                printf("Not Balanced");
                return 0;
            }
            top--;
        }
    }
    if(top==-1)
    {
        printf("Balanced\n");
    }
    else
    {
        printf("Not Balanced\n");
    }
}