private static int calculateValue(int n, int k)
    {

        if (matrix[n][k] != 0) {
            return matrix[n][k];
        }

        for (int i = 0; i <= n; i++) {
            if (matrix[i][k] == 0) {
                for (int j = 0; j <= k; j++) {
                    if (matrix[i][j] == 0) {
                        if (j == 0 || i == 0 || i == j) {
                            matrix[i][j] = 1;
                        } else {
                            matrix[i][j] = (int) (matrix[i - 1][j - 1] + (long) matrix[i - 1][j]) % MOD;
                        }
                    }
                }
            }
        }
        return matrix[n][k];
    }