n = gets.chomp.to_i
a_i = gets.chomp.split.map(&:to_i)


def func(ary)
  if ary.length == 1
    return ary[0]
  end

  tmp = 0
  (ary.length).times do |i|
    len = factorial(ary.length-1)
    if i == 0
      tmp += ary.sum * len + func(ary[1..-1])
    elsif i == ary.length-1
      tmp += ary.sum * len + func(ary[0..-2])
    else
      tmp += ary.sum * len + func(ary[0..(i-1)]) * (len / factorial(ary[0..(i-1)].length)) + func(ary[(i+1)..-1]) * (len / factorial(ary[(i+1)..-1].length))
    end
  end
  return tmp % (10**9+7)
end

def factorial(number)
  number = 0 if number.nil?
  (1..number).inject(1,:*)
end
print(func(a_i))
# print(func([1, 2, 4, 8, 16, 32, 64, 128, 256, 512]))
# print(func([1,1,1,1]))
