N = gets.to_i
ary = gets.split.map(&:to_i)
a = [0, 1].repeated_permutation(N).to_a.permutation(N).to_a
res = 0
a.each do |i|
  i.flatten!
  num = i.count(0)
  if i.count(1) < num
    num = i.count(1)
  end
  count = 0
  while num > 0
    res += ary[count] * num
    count += 1
    num -= 1
  end
end
p (res % (10**9+ 7))