#In this list of length 3, L123456 #L123456[(r+1)][n] is the number of permutations of length n with exactly r occurrences of the pattern 123456 L123456:= [ #0 occurrences [1, 2, 6, 24, 120, 719, 5003, 39429, 344837, 3291590, 33835114, 370531683, 4285711539, 51990339068, 657723056000, 8636422912277, 117241501095189, 1639974912709122, 23570308719710838, 347217077020664880], #1 occurrences [0, 0, 0, 0, 0, 1, 30 , 585, 9572, 144096, 2084558, 29662274, 420718378, 5994677242, 86204913122, 1254448945606, 18499816589580, 276683383575060, 4197568413984312, 64591694766182196], #2 occurrences [0, 0, 0, 0, 0, 0, 6, 225, 5317, 102869, 1794757, 29593801, 473258813, 7453189791, 116688121491, 1826993070090, 28715824819850, 454181870055115, 7239718429250651, 116411858778257595]]: # This took, 86558.610, seconds .