@x=("%d")x($n=pop);$"="";for(;;){printf"@x\n",map(int rand 10,1..$n);++$i%500 or$n-=$x[rand@x]=~s/../int rand 10/e or last;}