type a = record a, b : integer; end; type b = array[0..10000] of integer; var int : array[1..10000] of a; lit : array[1..10000] of boolean; x, treba : ^b; i, j, n, lst, prvi, drugi, prvitaj, drugitaj, total : integer; f : text; procedure solve; begin i:=1; while i<=n do begin while not lit[i] do inc (i); if treba^[i]<2 then begin prvi:=0; drugi:=0; for j:=int[i].a to int[i].b do begin if prvi<=x^[j] then begin drugi:=prvi; drugitaj:=prvitaj; prvi:=x^[j]; prvitaj:=j; end else if drugi=drugitaj) or (not lit[j]) do begin inc (treba^[j]); inc (j); end; end; inc (total); x^[prvitaj]:=0; j:=i+1; while (int[j].a<=prvitaj) and (int[j].b>=prvitaj) or (not lit[j]) do begin inc (treba^[j]); inc (j); end; end; inc (i); end; end; procedure shellsort; var h : integer; tmp : a; label out; begin h:=1; repeat; h:=3*h+1; until h>n; repeat; h:=h div 3; for i:=h+1 to n do begin tmp:=int[i]; j:=i; while (int[j-h].a>tmp.a) or (int[j-h].a=tmp.a) and (int[j-h].b