#!/bin/bash                                                                                                                           
export LC_ALL=C

cat <<EOF >arc061_d.f                                                                                                                 
{                                                                                                                                     
        s=\$1<3?2:\$1-1                                                                                                               
        t=w<\$1+1?w:\$1+1                                                                                                             
        u=\$2<3?2:\$2-1                                                                                                               
        v=h<\$2+1?h:\$2+1                                                                                                             
        for(i=s;i<=t;i++)for(j=u;j<=v;j++)a[i,j]++                                                                                    
}                                                                                                                                     
END{                                                                                                                                  
        for(i in a)print i,a[i]                                                                                                       
}                                                                                                                                     
EOF                                                                                                                                   

read w h n
((--w));((--h))
mkfifo pipe{0,1}

echo|tee >pipe1 >pipe0 &
cat|awk '{print > "./pipe"NR%2}' &
awk -v w=$w -v h=$h '{a[$1]+=$2}END{for(i in a)b[a[i]]++;for(i=1;i<=9;i++)printf "%d\n",b[i] |"cat";for(i=1;i<=9;i++)printf "-%d",b[i\
] |"eval echo \$\(\("(w-1)"*"(h-1)"\`cat\`\)\)"}' <(awk -v w=$w -v h=$h -f arc061_d.f ./pipe1) <(awk -v w=$w -v h=$h -f arc061_d.f ./\
pipe0)

wait
exit