#include using namespace std; using ll = long long; const int mod = 1000000007; struct mint { ll x; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint &operator+=(const mint m) { if((x += m.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint m) { if(x += mod - m.x >= mod) x -= mod; return *this; } mint &operator*=(const mint m) { (x *= m.x) %= mod; return *this; } mint operator+(const mint m) const { return mint(*this) += m; } mint operator-(const mint m) const { return mint(*this) -= m; } mint operator*(const mint m) const { return mint(*this) *= m; } mint pow(ll n) const { if(!n) return 1; mint m = pow(n>>1); m *= m; if(n & 1) m *= *this; return m; } mint inv() const { return pow(mod-2);} mint &operator/=(const mint m) { return *this *= m.inv();} mint operator/(const mint m) const { return mint(*this) /= m;} }; istream &operator>>(istream &is, const mint &m) { return is >> m.x;} ostream &operator<<(ostream &os, const mint &m) { return os << m.x;} struct combination { vector fact, ifact; combination(int n) : fact(n+1), ifact(n+1) { assert(n < mod); fact.at(0) = 1; for(int i=1; i<=n; i++) { fact.at(i) = fact.at(i-1) * i; } ifact.at(n) = fact.at(n).inv(); for(int i=n; i>=1; i--) { ifact.at(i-1) = ifact.at(i) * i; } } mint operator()(int n, int k) { if(k < 0 || k > n) return 0; return fact.at(n) * ifact.at(k) * ifact.at(n-k); } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector A(N); for(int i=0; i> A.at(i); combination cmb(N-1); mint ans = 0; for(int i=0; i