const maxFileN=4;
FileNm='c:\DISKI_ZX\sys0218';
FileEx='drv';

var f_array:array[0..maxFileN]of file;
f_outpit:file of byte;
i,j:integer;
end_file,finds:boolean;
b_dat:array[0..maxFileN]of byte;
b_tmp:record
       alls:byte;
       data:array[0..maxFileN]of record dats,kolwo:byte;end;
      end;
b_out:byte;

type t_buffer=array[0..$3FFF]of byte;
var
buf_ofset:array[0..maxFileN]of longint;
Buffer:array[0..maxFileN]of record d:^t_buffer;s:word end;

function nextByte(_i:byte):byte;
var _w:word;
begin
if buf_ofset[_i]>=buffer[_i].s then
 begin
  buf_ofset[_i]:=0;
  blockread(f_array[_i],buffer[_i].d^,sizeof(buffer[_i].d^),_w);
  buffer[_i].s:=_w;
  if _w=0 then end_file:=true;
 end;
nextByte:=buffer[_i].d^[buf_ofset[_i]];
inc(buf_ofset[_i]);
end;

begin
writeln;writeln;
end_file:=false;
for i:=0 to maxFileN do
 begin
 assign(f_array[i],FileNm+chr(i+$30)+'.'+FileEx);
 reset(f_array[i],1);
 buf_ofset[i]:=$FFFF;
 buffer[i].s:=0;
 new(buffer[i].d);
 end;
assign(f_outpit,FileNm+'.'+FileEx);
rewrite(f_outpit);
repeat
for i:=0 to maxFileN do b_dat[i]:=nextByte(i);
b_tmp.alls:=0;
for i:=0 to maxFileN do
begin
 b_tmp.data[i].kolwo:=0;
 b_tmp.data[i].dats:=0;
end;

for i:=0 to maxFileN do
 begin
finds:=false;
 for j:=0 to b_tmp.alls-1 do
  if b_dat[i]=b_tmp.data[j].dats then
   begin
   finds:=true;
   break;
   end;
  if not(finds) then
   begin
   inc(b_tmp.alls);
   b_tmp.data[b_tmp.alls-1].dats:=b_dat[i];
   end else inc(b_tmp.data[j].kolwo);
 end;

b_out:=b_tmp.data[0].kolwo;
j:=0;
for i:=0 to maxFileN do if b_tmp.data[i].kolwo>b_out then
 begin
 b_out:=b_tmp.data[i].kolwo;
 j:=i;
 end;
if b_out<=maxFileN-2 then
 begin writeln('мало совпадений ',filepos(f_array[0])-buffer[0].s+buf_ofset[0]);end;
b_out:=b_tmp.data[j].dats;
write(f_outpit,b_out);
until end_file;

for i:=0 to maxFileN do
 begin
 close(f_array[i]);
 dispose(buffer[i].d);
 end;
seek(f_outpit,filepos(f_outpit)-1);
truncate(f_outpit);
close(f_outpit);

end.