For each positive integer n≥1, we denote sn as the number of permutations of the first n positive integers that satisfy the condition
ai+1−ai≤1,i=1,2,…,n−1.
We call these permutations "nice".
First, we shall prove that sn=2n−1 for all n≥1.
Let k be the index such that ak=n. We have ak−1≥ak−1=n−1 which implies that ak−1=n−1, and so on, we have a1=n−k+1.
All numbers after ak are 1,2,3,…,n−k forming a nice permutation, so in case ak=n, the number of nice permutations is sn−k.
Note that if k=n, we have only 1 nice permutation: 1,2,3,…,n.
Therefore, we get the following formula:
sn=1+k=1∑n−1sn−k=s1+s2+…+sn−1+1
It is easy to compute s1=1, s2=2, then by induction, we have sn=2n−1 for all n≥1.
Back to the original problem, we suppose that ai=i and aj=j. Thus,
ai+1≤ai+1=i+1,ai+2≤ai+1+1≤i+2
and so on, then we have aj≤j. But in fact, aj=j which implies that the equality must occur.
So ak=k for all k=i,i+1,i+2,…,j. But there are only 2 indices i,j like that so we have j=i+1.
Continue, ai−1≥ai−1=i−1, but ai=i, ai+1=i+1 so ai−1≥i+2. Then,
ai−2≥ai−1−1≥i+1 or ai−2≥i+2.
By the same way, it is clear to check that a1,a2,…,ai−1≥i+2. Similarly, we also have ai+2,ai+3,…,a2016≤i−1.
Therefore, the lengths of the two sequences a1,a2,…,ai−1 and ai+2,ai+3,…,a2016 are the same. Hence,
i−1=2015−i⇔i=1008.
So the given nice permutation looks like
(a1,a2,…,a1007,1008,1009,a1010,a1011,…,a2016).
Clearly, the subsequence (a1010,a1011,…,a2016) forms a nice permutation of length 1007 and the same with the subsequence
(a1−1009,a2−1009,…,a1007−1009).
Therefore, the number of permutations satisfying the given condition is
s1007⋅s1007=(21006)2=22012. □