read n m while read i j s do t[i*n+j]=$s done for((;++b<2**n;)){ for((j=0;j>i&1)*t[i*n+j]] $[d[b]