/PLOI - Phạm lỗi

<Problem>

http://ntucoder.net/Problem/Details/3330
              Uses Crt;
        Type    Pnode=^Tnode;
                Tnode=record
                        info:byte;
                        link:Pnode;
                end;
        Var     n:^integer;
                first,last,newp,f,l:Pnode;
                count:array[1..11] of byte = (0,0,0,0,0,0,0,0,0,0,0);
                d:integer;
        Begin
                new(n);
                readln(n^);
                First:=nil;
                Last:=nil;
                while n^<>0 do
                begin
                        new(newp);
                        read(newp^.info);
                        newp^.link:=nil;
                        if first=nil then
                                first:=newp
                        else
                                last^.link:=newp;
                        last:=newp;
                        inc(count[last^.info]);
                        if (count[last^.info]=3) then
                        begin
                                if (f=nil) then
                                        f:=Last
                                else
                                        l^.link:=last;
                                l:=last;
                                inc(d);
                                count[last^.info]:=0; 
                        end;
                        n^:=n^-1;
                end;
                writeln(d);
                newp:=f; l^.link:=nil;
                while newp<>nil do
                begin
                        write(newp^.info,' ');
                        newp:=newp^.link;
                end;
                readln;
        End.