#include using namespace std; constexpr int M = 1000000007; long long modinv(long long a, long long m) { long long x = m, y = a, p = 1, q = 0, r = 0, s = 1; while (y != 0) { long long u = x / y; long long x0 = y; y = x - y * u; x = x0; long long r0 = p - r * u, s0 = q - s * u; p = r; r = r0; q = s; s = s0; } return q < 0 ? q + m : q; } int main() { long long n, m; cin >> n >> m; int a[n-1]; for (int i = 0; i < n-1; i++) cin >> a[i]; long long ans = 0, c = m % M; for (int i = n-2; i >= 0; i--) { ans += a[i] * c % M; cerr << ans << ' ' << c << endl; c = (n + m - i - 1) % M * modinv(n - i, M) % M * c % M; } cout << ans % M << endl; }