A beautiful problem

Let pn denote a permutation of [0,1,..,n]. define f(pn,v)=pi:pi=pi+1 if piv else pi. We claim that f is a bijection from {pn} to perm({0..n}v) where v[0,n+1].

it is important to note that if f:AB is biijective, then f:Uf(U) is also bijective whenever U A.

We say that pn is c valid (where c=c0,c1,cn1 and ci{,}) if for every i ci=↑pi<pi+1, ci=↓pi>pi+1.

Now, let Pn denote the set of all permutations of [0,1,..,n] that are c valid for a given c.
define a partition Pn|k={p:pPn,pn=k} of those permutations in Pn that end with k, for k[0,n].
The following is a theorem: for c++cn valid permutations Pn+1.

Pn+1|v={kvf(Pn|k,v) ++v   if cn=↓k<vf(Pn|k,v) ++v   if cn=↑

where ++ means concatenation, (which when applied on a set means concatenation on each element, and also f is applied elementwise to a set).
To prove the theorem, at least we know that the right hand side are permutations, as f(p,v) does not contain v, and is a permutation, so the right hand side definitely contains permutations of [0,..n+1] that end in v.

Now we need to show that these permutations are c++cn valid.