/*(PARI) For significant speeding up please compile this program with GP2C. */ f(n)=for(k=2, n+1, if(n%k, return(k-1), n/=k)) \\ See program by Charles R Greathouse IV, May 28 2015 at A055881. nextperm(p,k)={my(x=f(k));concat(Vecrev(p[1..1+x]),p[2+x..#p])} \\ See comment by Joerg Arndt, Jul 16 2011 at A055881. isDerangement(v)={for(i=1,#v,if((v[i]==i),return(0)));1} isOnePeak(v)={my(t=0);for(i=2,#v-1,if((v[i]>v[i-1])&&(v[i]>v[i+1]),t++;if(t>1,return(0))));t==1} A301272(n)={my(c=0,v=vector(n,u,u));for(k=1,n!-1,v=nextperm(v,k);if(isDerangement(v),if(isOnePeak(v),c++)));c} \\ R. J. Cano, Apr 25 2018