the algorithm of k-merge write by python