Fixpoint upd (i : nat) {A} new (l : list A) : option (list A) :=
match i, l with
| O, _ :: l => Some (new :: l)
| _, nil => None
| S i, x :: l =>
match upd i new l with
| Some l' => Some (x :: l')
| None => None
end
end.

Lemma upd_app_None {A} i x (l1 l2 : list A) :
upd i x l1 = None ->
upd i x (l1 ++ l2) =
option_map (app l1) (upd (i - length l1) x l2).