program Project2;
{$APPTYPE CONSOLE}
uses SysUtils;
const
max_refs = 255;
max_str_len = 255;
max_files = 100;
doc_begin = '<html>';
doc_end = '<end>';
doc_href_start = '<a href=';
doc_href_end = '>';
type
stateT = (filename,
doc
);
docT = record
name : string;
refs : array[1..max_refs] of string;
available : boolean;
end;
var
input, output : text;
str : string;
ret_code : integer;
n : integer; // -
state : stateT;
files : array[1..max_files] of docT;
i,j : integer;
function delete_whitespaces(x : string) : string;
var
k : integer;
begin
for k := 1 to length(x) do
if x[k] = ' ' then
while x[k+1] = ' ' do
delete(x, k+1, 1);
delete_whitespaces := x;
end;
procedure check_line_for_refs(x : string);
var
href_start : integer;
href_end : integer;
begin
href_start := pos(doc_href_start, x);
href_end := pos(doc_href_end, x);
while href_start <> 0 do
begin
files[i].refs[j] := copy(x, href_start+length(doc_href_start)+3, href_end - href_start - length(doc_href_start) - length(doc_href_end) - 5);
delete(x, 1, href_start);
j := j + 1;
href_start := pos(doc_href_start, x);
href_end := pos(doc_href_end, x);
end
end;
function count_invalid_refs : integer;
var
k,l,m : integer;
res : integer;
is_valid : boolean;
begin
res := 0;
for k := 1 to n do
begin
l := 1;
while files[k].refs[l] <> '' do
begin
is_valid := false;
for m := 1 to n do
begin
if compareText(files[m].name, files[k].refs[l]) = 0 then
is_valid := true;
end;
if not(is_valid) then
begin
res := res + 1;
end;
l := l + 1;
end;
end;
count_invalid_refs := res;
end;
begin
assign(input,'input.txt');
reset(input);
assign(output,'output.txt');
rewrite(output);
// -
readln(input, str);
val(str, n, ret_code);
writeln('n = ', n);
files[1].available := true;
for i:=2 to max_files do
files[i].available := false;
i := 1;
j := 1;
state := filename; //
while not EOF(input) do
begin
readln(input, str);
str := delete_whitespaces(trim(lowercase(str)));
case state of
filename : begin
files[i].name := str;
readln(input,str);
if compareText(str, doc_begin) <> 0 then
halt(1);
state := doc;
end;
doc : begin
if str = doc_end then
begin
i := i + 1;
j := 1;
state := filename;
end
else
check_line_for_refs(str);
end;
end;
end;
writeln(output, count_invalid_refs);
{ for i := 1 to n do }
{ begin }
{ writeln('file: ', files[i].name); }
{ j := 1; }
{ while files[i].refs[j] <> '' do }
{ begin }
{ writeln(files[i].refs[j]); }
{ j := j + 1; }
{ end; }
{ end; }
close(input);
close(output);
end.