generic algorithm: merge, mismatch, next_permutation, nth_element