no need to keep track of P separately, it's just S with the data replaced by ones. Also some optimizations.