global values for pre computation
var nCr = Array . from ( Array ( 1003 ) , ( ) => Array ( 1003 ) ) ; function preComputeCoeff ( ) { for ( var i = 0 ; i < max ; i ++ ) { for ( var j = 0 ; j <= i ; j ++ ) { if ( j == 0 j == i ) nCr [ i ] [ j ] = 1 ; else nCr [ i ] [ j ] = ( nCr [ i - 1 ] [ j - 1 ] + nCr [ i - 1 ] [ j ] ) % mod ; } } }