Definition me (ab: list T * list T): nat := length (fst ab) + length (snd ab).Program Fixpoint merges_ex (ab: list T * list T) {measure (me ab)}: sig (merges_spec (fst ab) (snd ab)) :=
    match ab with
    | (nil, x) => x :: nil
    | (x, nil) => x :: nil
    | (x :: y, h :: t) => map (cons x) (merges_ex (y, h :: t)) ++ map (cons h) (merges_ex (x :: y, t))
    end.Definition merges (a b: list T): list (list T) := proj1_sig (merges_ex (a, b)).

Lemma filter_merges p (x y: list T): (forall z, In z x -> p z = true) -> (forall z, In z y -> p z = false) -> forall r, In r (map (filter p) (merges x y)) -> r = x.