read while read do read m s read t for w in $t do((x$w+=s)) done done for w in ${!x*} do a[4**8-w]+=\ $w done for w in ${a[@]} do ((k++>9))||echo ${w/x} $[w] done