a) Place the elements of p along the real axis. Then Sp equals the length of the "walk", starting from a1, then reaching a2, then reaching a3 and so on until we end at a12. In such a walk, the segments:
1-2 and 11-12 appear at most twice (before and after 1; before and after 12);
2-3 and 10-11 appear at most 4 times (before and after 1, 2, 11, and 12);
3-4 and 9-10 appear at most 6 times (before and after 1, 2, 3, 10, 11, and 12);
4-5 and 8-9 appear at most 8 times (before and after 1, 2, 3, 4, 9, 10, 11, and 12);
5-6 and 7-8 appear at most 10 times (before and after 1, 2, 3, 4, 5, 8, 9, 10, 11, 12);
6-7 may appear in all 11 paths ai−ai+1.
Therefore, Sp≤2(2+4+6+8+10)+11=2⋅30+11=71. Furthermore Sp=71 iff all the inequalities above become equalities. This is possible only if {a1,a12}={6,7} (2 cases). For the case a1=6, (a2,a4,…,a10) must be a permutation of {8,9,…,12} (5! cases) and (a3,a5,…,a11) must be a permutation of {1,2,…,5} (5! cases), while in the case a1=7 it is vice versa. Therefore, the total number of permutations with Sp=71 is 2⋅5!⋅5!=28800.
b) In order for p to be an optimistic permutation, the number 1 should be at one of the end positions. Then, the number 2 should be at one of the end positions of the remaining p-sub-permutation of {2,3,…,12}, 3 should be at one of the end positions of the remaining p-sub-permutation of {3,…,12} and so on. It is easy to check that all such permutations are indeed optimistic. Therefore, their number is 211=2048.
c) Let p be an optimistic permutation and k∈{1,2,…,12} be the position of 12 in it (i.e., ak=12). Then, it is trivial to check that ai>ai−1, for all i=2,…,k, while aj>aj+1, for all j=k,…,11. Thus, Sp=12−a1+12−a12≤2⋅12−1−2=21. Equality is achieved iff {a1,a12}={1,2}. According to b), the total number of such permutations is 211/2=210=1024.