program huffman;
{$APPTYPE CONSOLE}
uses
SysUtils;
const n1=32676;
m1=2*n1-1;
maxint=32767;
type nodetype=record
weight:integer;
parent,lch,rch:0..m1
end;
bit=0..1;
codetype=record
bits:array [1..n1] of bit;
start:1..n1
end;
huftree=array [1..m1] of nodetype;
hufcode=array [1..n1] of codetype;
var
w:array [1..n1] of integer;
k,d,a:integer;
ht:huftree;
hcd:hufcode;
procedure huffman_code(var ht:huftree; var hcd:hufcode;k1:integer);
var
i,j,x,y,m,n,c,f,temp:integer;
cd:codetype;
begin
for i:=1 to 2*k1-1 do
begin
ht[i].parent:=0;
ht[i].lch:=0;
ht[i].rch:=0
end;
for i:=1 to k1 do
ht[i].weight: