#include #include #include #include #include #include #include using namespace std; using ll = long long; constexpr int P = 1000000007; int inv(int n) { int m = P, y = 0, v = 1; while (1) { int q = m / n; int r = m % n; if (r == 0) return v < 0 ? v + P : v; y -= v * q; swap(y, v); m = n; n = r; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int m = n - 1; ll s = 0, t = 1; for (int i = 0; i <= m; i++) { int a; cin >> a; s += a * t; s %= P; t = t * (m - i) % P * inv(i + 1) % P; } cout << s << endl; return 0; }