in reply to reducing the number of lines
I need to rewrite this in a more simpler form
$k-2>0 $l-2>0 [download]
Same as:
$k>2 $l>2 [download]
And you can save one line here
$h=0; $c=0; [download]
same as:
Updated: the tobyink's solution is more elegant