MOD = 10**9 + 7 max_fact = 10**6 # Since M can be up to 1e6, and n = D +k can be up to 1e6 # Precompute factorial and inverse factorial modulo MOD fact = [1] * (max_fact + 1) for i in range(1, max_fact + 1): fact[i] = fact[i-1] * i % MOD inv_fact = [1] * (max_fact + 1) inv_fact[max_fact] = pow(fact[max_fact], MOD-2, MOD) for i in range(max_fact - 1, -1, -1): inv_fact[i] = inv_fact[i + 1] * (i + 1) % MOD def main(): import sys input = sys.stdin.read().split() M = int(input[0]) H = list(map(int, input[1:])) if len(H) == 1 and H[0] == 0: print(1) return if any(h <= 0 for h in H): print("NA") return sum_h = sum(H) k = len(H) required = sum_h + (k - 1) if required > M: print("NA") return D = M - required n = D + k if n > max_fact: print("NA") return comb = fact[n] * inv_fact[k] % MOD comb = comb * inv_fact[n - k] % MOD print(comb) if __name__ == "__main__": main()