DBG = !true
K = 1000000007

def comb(p, q)
  return 1 if p==q
  return p if p==q+1
  x = (q+2)*(q+1)
  for i in (q+3)..p
    x = (x * i) % K
  end
  return x
end

n = gets.to_i
w = gets.split.map{|x| x.to_i}
printf("n:%d\n", n) if DBG
print w if DBG
print "---\n" if DBG

a = []
for i in 0...n
  a << Array.new(i+1)
  a[i][i] = w[i]
end

for d in 1...n
  for p in 0...(n-d)
    # compute f(p, p+d)
    q = p + d
    printf("p:%d q:%d\n", p, q) if DBG
    sum = 0
    for i in p..q
      sum += w[i]
    end
    sum *= comb(d+1, 1)
    printf("sum1 %d\n", sum) if DBG
    sum += a[p+1][q] + a[p][q-1]
    printf("sum2 %d\n", sum) if DBG
    for i in (p+1)..(q-1)
      sum += a[p][i-1] * comb(q-p, i-p) +
             a[i+1][q] * comb(q-p, q-i)
      sum = sum % K
    end
    a[p][q] = sum
  end
end

if DBG
  for j in 0...n
    printf("j:%d ", j)
    for i in 0..j
      printf("%d ", a[i][j])
    end
    print "\n"
  end
end
print a[0][n-1]
