{
TASK:HTML
LANG:PASCAL
}
program HTML;
  { 15 olimpiada, III etapo I dalis, Vyresniøjø grupë }
  const PRAD = 'html.dat';
        REZ = 'html.rez';
        MAX = 1000; { maksimalus þymø skaièius }
   type deklas = array[0..MAX] of string[6];

  procedure sutrumpinti (zyma: string; var zm: string);
  { paðalinami skliaustai ir savybës }
    var tarpas: integer;
  begin
    tarpas := pos(' ', zyma);
    if tarpas > 0
       then zm := copy (zyma, 2, tarpas-2)
       else zm := copy (zyma, 2, length(zyma)-2);
  end; { sutrumpinti }

  procedure HTML_analize (var f: text; N: integer; var rz: string);
    var pab, i: integer;
        d: deklas;
        gerai: boolean;
        zyma, zm: string;
  begin
    pab := 0; d[0] := '';
    i := 1; gerai := true;
    while (i <= N) and gerai do
      begin
        i := i + 1;
        readln (f, zyma);
        sutrumpinti (zyma, zm);
        if zm[1] = '/' { jei uþdaranti zyma }
           then if '/'+ d[pab] = zm { jei blokas uþdaromas }
                   then pab := pab - 1 { iðimama ið dëklo }
                   else begin
                          gerai := false;
                          rz := zyma;
                        end
           else begin { jei atidaranti þyma }
                  pab := pab + 1;
                  d[pab] := zm;
                end;
      end;
    if gerai
       then if pab <> 0 { jei dëklas netuðèias }
               then rz := 'NEGERAI'
               else rz := 'GERAI'
  end; { tikrinti }

  procedure spausdinti (rz: string);
    var f: text;
  begin
    assign (f, REZ);
    rewrite (f);
    writeln (f,rz);
    close (f);
  end; { spausdinti }

  var f: text;
      rz: string;
      N: integer;
begin
  assign (f, PRAD);
  reset (f);
  readln (f, N);
  HTML_analize (f, N, rz);
  close (f);
  spausdinti (rz);
end.