N-wise reduce