in reply to Tagging the last elements

$1,$2,$3,$4... are global variables. max/min can change their values, so you have to save them to an intermediate variables. Also, you input/output is identical.