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 # } class Integer def nCr(r); x = 1; (1..r).each { |i| x = x * (self + 1 - i) * i.pow(MOD - 2, MOD) }; x; end end # nCk[M + N - k, N - k + 1] x = (M + N - 1).nCr(N) # nCk(n, k) = n! / (k! * (n - k)!) # nCk(n - 1, k - 1) = nCk(n, k) / n / (n - k) * k ans = (1 .. N).sum { |k| y = x * A[k - 1] % MOD; x = x * (N - k + 1) * (M + N - k).pow(MOD - 2, MOD); y } % MOD puts ans