new implementation for N partitions