p0() {
  (($1==0)) && return
  eval "printf \"0 \"'%.s' {1..$1}"
}
p() {
  printf "$(($1/2+$1%2+$2/2)) "
}
e() {
  while read m n
  do
    p0 $((m-1))
    p m n
    p n m
    p0 $((n-1))
  done < <(fold -s1 | uniq -c | sed 'N;s/\n//' | awk '{print $1,$3}')
}
e | sed 's/ $//g'