read n read a read B read c read D for i in $B;{ y[i]+=\ $i;};B=(${y[@]}) for i in $D;{ z[i]+=\ $i;};D=(${z[@]}) for((;n--;r+=k,k=0)){ ((${#b[@]}))||b=(${B[@]}) ((${#d[@]}))||d=(${D[@]}) (((nb=${#b[@]})<(nd=${#d[@]})))&&{ x=${b[-1]} b=(${b[@]::nb-1}) for((j=nd-1,i=0;id[i]&&(k=1,j=i))) } d=(${d[@]::j} ${d[@]:j+1}) }||{ x=${d[0]} d=(${d[@]:1}) for((j=0,i=nb;i--;)){ ((x