program check_a;

uses
  testlib;

var
  n, i, j, pa, pr, ja: longint;
  s, z: array [0..100] of string;
  f: boolean;

begin
  n := inf.readlongint;
  for i := 1 to n do
  begin
    inf.seekeof;
    s[i] := inf.readstring;
  end;

  ja := ans.readlongint;
  pa := ouf.readlongint;
  if ja <> pa then
    quit(_wa, 'expected: ');

  for i := 1 to n do
  begin
    ouf.seekeof;
    z[i] := ouf.readstring;
    for j := 1 to length(z[i]) do
      if not (z[i][j] in ['a'..'z']) then
        quit(_pe, 'invalid character in output');

    f := false;
    for j := 1 to n do
      if z[i] = s[j] then
      begin
        s[j] := '$';
        f := true;
        break;
      end;
    if not f then
      quit(_wa, 'unknown or duplicate string: `' + z[i] + '`');
  end;

  pr := length(z[1]);
  for i := 2 to n do
  begin
    j := 1;
    while (length(z[i]) >= j) and (length(z[i-1]) >= j) and
            (z[i][j] = z[i-1][j]) do inc(j);
    pr := pr + length(z[i]) - j + 1;
  end;
  if pr <> pa then
    quit(_wa, 'results mismatch - declared: ..., calculated: ...');

  quit(_ok, '');
end.
