Proof with auto.
intros H.
induction H; intros.
inversion_clear H...
inversion_clear H...
inversion_clear H1.
apply IHmerges_spec1 in H2.
apply IHmerges_spec2 in H3.
congruence.
Qed.

Lemma length_merges (F: nat -> nat -> nat) a b r:
(forall n, F 0 n = 1) ->
(forall n, F n 0 = 1) ->
(forall n n', F n (S n') + F (S n) n' = F (S n) (S n')) ->
merges_spec a b r -> length r = F (length a) (length b).