MOD = 10**9 + 7 N, M = gets.split.map(&:to_i) A = gets.split.map(&:to_i) A.unshift 0 fac = [1, 1] fin = [1, 1] inv = [0, 1] (2 .. N + M + 10).each do |i| inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD fac[i] = fac[i - 1] * i % MOD fin[i] = fin[i - 1] * inv[i] % MOD end nCk = ->(n, k) { return 0 if n < k or n < 0 or k < 0 fac[n] * (fin[k] * fin[n - k] % MOD) % MOD } ans = (1 .. N).sum { |k| nCk[M + N - k, N - k + 1] * A[k - 1] % MOD } % MOD puts ans