program dem_so_doi_xung;
var
n, i, j, count: longint;
s: string;
function doi_xung(s: string): boolean;
var
i: longint;
begin
for i := 1 to length(s) div 2 do
if s[i] <> s[length(s) - i + 1] then
begin
doi_xung := false;
exit;
end;
doi_xung := true;
end;
function doi_xung_dang_non(s: string): boolean;
var
i: longint;
begin
for i := 1 to length(s) div 2 do
if not((s[i] = '1') or (s[i] = '0') or (s[i] = '8')) or (s[length(s) - i + 1] <> s[i]) then
begin
doi_xung_dang_non := false;
exit;
end;
doi_xung_dang_non := true;
end;
begin
write('Nhap n: ');
readln(n);
count := 0;
for i := 1 to n do
begin
str(i, s);
if doi_xung(s) and doi_xung_dang_non(s) then
inc(count);
end;
writeln('So luong so doi xung dang non la: ', count);
readln;
end.