#!/bin/bash                                                                                                                           
export LC_ALL=C

echo '                                                                                                                                
{                                                                                                                                     
        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]                                                                                                       
                                                                                                                                      
}                                                                                                                                     
' >./arc061_d.f

_awk(){ awk -v w=$w -v h=$h -f arc061_d.f  ;}
read w h n
((--w));((--h))
rm -rf ./pipe*
mkfifo pipe{0..9}

echo |tee pipe{0..9} >/dev/null &
cat|awk '{print >> "./pipe"NR%8}' &
eval 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\<pipe{0..9}\)
wait
