MOD = 10**9 + 7 def main(): import sys input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 M = int(input[ptr]) ptr += 1 A = list(map(int, input[ptr:ptr + (N - 1)])) r = M % MOD t_max = N - 2 # Compute prefix_products required_i = (MOD - r) % MOD prefix_products = [] current_product = 1 for t in range(t_max + 1): if required_i <= t: current_product = 0 else: term = (r + t) % MOD current_product = (current_product * term) % MOD prefix_products.append(current_product) # Precompute factorial and inverse factorial up to t_max + 1 max_fact = t_max + 1 fact = [1] * (max_fact + 2) for i in range(1, max_fact + 1): fact[i] = (fact[i-1] * i) % MOD inv_fact = [1] * (max_fact + 2) 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 sum_total = 0 for k in range(2, N + 1): idx = k - 2 # A's index for A_2, A_3, ..., A_N a_k = A[idx] t = N - k if t < 0 or t > t_max: continue # Shouldn't happen as k ranges from 2 to N product_contrib = prefix_products[t] if product_contrib == 0: continue inv = inv_fact[t + 1] contribution = (a_k * product_contrib) % MOD contribution = (contribution * inv) % MOD sum_total = (sum_total + contribution) % MOD print(sum_total % MOD) if __name__ == '__main__': main()