program Comparethem;
uses crt,dos;
type filet=record
      path:string;
      name:string[12];
      time,size:longint;
      gr:word;
     end;
     pfilet=^filet;
const maxngroups=500;
      maxnfiles=7000;
      ftsize=sizeof(filet);
var grsym:array[1..maxngroups]of char;
    grsize:array[1..maxngroups]of longint;
    fingr:array[1..maxngroups]of word;
    newest:array[1..maxngroups]of word;
    curf:searchrec;
    farr,tarr:array[1..maxnfiles]of pfilet;
    nfiles,ngroups:word;
    chosendir,olddir:string;
    done:boolean;
procedure getfilenames;
var fullpath:string;
begin
 getdir(0,fullpath);
 findfirst('*.*',archive or directory,curf);
 while doserror=0 do begin
  if (curf.name<>'.')and(curf.name<>'..') then begin
   if curf.attr=directory then begin
    chdir(curf.name);
    getfilenames;
    chdir('..');
   end;
   inc(nfiles);
   getmem(farr[nfiles],ftsize);
   with farr[nfiles]^ do begin
    name:=curf.name;
    path:=fullpath;
    size:=curf.size;
    time:=curf.time;
   end;
  end;
  findnext(curf);
 end;
end;
procedure freeallmem;
var i:word;
begin
 for i:=1 to nfiles do freemem(farr[i],ftsize);
end;
procedure comparefiles;
begin

end;
procedure sortbysize;
var i,j:word;
begin
 ngroups:=1;
 grsize[1]:=farr[1]^.size;
 farr[1]^.gr:=1;
 for i:=2 to nfiles do begin
  j:=1;
  while (farr[i]^.size<>grsize[j])and(j<=ngroups) do inc(j);
  if j>ngroups then begin
   if ngroups>=maxngroups then write('Error:too many different files'){exit now}else begin
    inc(ngroups);
    farr[i]^.gr:=ngroups;
    grsize[ngroups]:=farr[i]^.size;
   end;
  end else begin
   farr[i]^.gr:=j;
  end;
 end;
end;
var i:word;
procedure filesingr;
var i:word;
begin
 for i:=1 to ngroups do fingr[i]:=0;
 for i:=1 to nfiles do inc(fingr[farr[i]^.gr]);
end;
procedure lessengr;
var i,j:word;
begin
 for i:=1 to ngroups do
  if fingr[i]=1 then begin
   dec(ngroups);
   for j:=i to ngroups do begin
    fingr[j]:=fingr[j+1];
    grsize[j]:=grsize[j+1];
   end;
   for j:=1 to nfiles do if farr[j]^.gr>i then dec(farr[j]^.gr)else
    if farr[j]^.gr=i then farr[i]^.gr:=ngroups+1;
  end;
end;
procedure findnewest;
begin
end;
procedure autoquiz;
begin
end;
begin
 nfiles:=0;
 write('Write the path to search: ');
 readln(chosendir);
 getdir(0,olddir);
 chdir(chosendir);
 getfilenames;
 chdir(olddir);
 for i:=1 to nfiles do getmem(tarr[i],ftsize);
 ngroups:=1;
 {end of init}
 sortbysize;
 filesingr;
 lessengr;
 writeln(ngroups,' groups found.');
 {comparefiles}
 {user interface}
 autoquiz;
 done:=false;
 freeallmem;
end.