program CheckBrackets1;
const
  n = 40;
var
  st: array[1..n] of char;
  i, count, len: integer;
begin
  writeln('Enter a string (up to 40 chars):');
  i := 1;
  repeat
    read(st[i]);
    i := i + 1;
  until (eoln) or (i > n);
  len := i - 1;

  count := 0;
  for i := 1 to len do
  begin
    if st[i] = '(' then
      count := count + 1
    else if st[i] = ')' then
      count := count - 1;

    if count < 0 then break;
  end;

  if count = 0 then
    writeln('Brackets are balanced.')
  else
    writeln('Brackets are NOT balanced.');
end.