I think you need something like this Total[#1 - #2] & @@ Partition[#, Length[#]/2] &[ Times @@ MapIndexed[Subscript[x, #2[[1]]]^# &, Boole[MCSs], {2}]] ![enter image description here][1] [1]: https://i.sstatic.net/EcVwu.png