MOD = 10**9+7 def create_fact_mod(num_max) $fmod = Array.new(num_max + 1) $fmod[0] = 1 $fmod[1] = 1 (2..num_max).each do |i| $fmod[i] = ($fmod[i - 1] * i) % MOD end end def create_seq_inv_mod(num_max) $simod = Array.new(num_max + 1) $simod[0] = 1 $simod[1] = 1 (2..num_max).each do |i| $simod[i] = (MOD - MOD / i) * $simod[MOD % i] % MOD end end def create_fact_inv_mod(num_max) $fimod = Array.new(num_max + 1) $fimod[0] = 1 $fimod[1] = 1 (2..num_max).each do |i| $fimod[i] = ($fimod[i - 1] * $simod[i]) % MOD end end def create_mod_tables(n) create_fact_mod(n) create_seq_inv_mod(n) create_fact_inv_mod(n) end def comb_mod(n, k) return $fmod[n] * $fimod[n - k] * $fimod[k] % MOD end def perm_mod(n, k) return $fmod[n] * $fimod[n - k] % MOD end N = gets.to_i as = gets.split.map(&:to_i) create_mod_tables(N) ans = 0 N.times do |i| ans += as[i] * comb_mod(N-1, i) ans %= MOD end puts ans