#In the list of length 3 below (called L12345) the #L12345[r+1][n] (0<=r<=2, 1<=n<=20) is the number #of permutations of length n with exactly r occurrences of #the pattern 12345 L12345:= [ #0 occurrences [1, 2, 6, 24, 119, 694, 4582, 33324, 261808, 2190688, 19318688, 178108704, 1705985883, 16891621166, 172188608886, 1801013405436, 19274897768196, 210573149141896, 2343553478425816, 26525044132374656], #1 occurrences [0, 0, 0, 0, 1, 20, 270, 3142, 34291, 364462, 3844051, 40632886, 432715409, 4655417038, 50667480496, 558143676522, 6223527776874, 70228214538096, 801705888742781, 9254554670121572] #2 occurrences , [0, 0, 0, 0, 0, 5, 128, 2124, 29445, 373379, 4517921, 53342405, 622358262, 7229196009, 83984283157, 978558652802, 11455522117193, 134879815196252, 1598299236441571, 19067702481168369]]: # This took, 8344.234, seconds .