object Main {
  import java.util.Scanner

  def readStrings(n: Int)(implicit sc: Scanner): Array[String] = Array.fill(n) { sc.next() }
  def readInts(n: Int)(implicit sc: Scanner): Array[Int] = Array.fill(n) { sc.nextInt() }
  def readLongs(n: Int)(implicit sc: Scanner): Array[Long] = Array.fill(n) { sc.nextLong() }
  def readLineStrings(implicit sc: Scanner): Array[String] = sc.nextLine().split(' ')
  def readLineInts(implicit sc: Scanner): Array[Int] = readLineStrings.map(_.toInt)
  def readLineLongs(implicit sc: Scanner): Array[Long] = readLineStrings.map(_.toLong)

  def main(args: Array[String]): Unit = solve(new Scanner(System.in))

  def fact(n: Int): Long = if (n == 0) 1 else n * fact(n - 1)

  def test(arrayLength: Int): Array[Long] = {
    if (arrayLength == 0) return Array(1L)
    val base = Array.fill(arrayLength)(fact(arrayLength))
    for (i <- 0 until arrayLength) {
      val leftLength = i
      if (leftLength != 0) {
        val left = test(leftLength)
        val leftMultiplier = fact(arrayLength - 1) / fact(leftLength)
        for (j <- 0 until leftLength) {
          base(j) += left(j) * leftMultiplier
        }
      }

      val rightLength = arrayLength - i - 1
      if (rightLength != 0) {
        val right = test(rightLength)
        val rightMultiplier = fact(arrayLength - 1) / fact(rightLength)
        for (j <- 0 until rightLength) {
          base(j + i + 1) += right(j) * rightMultiplier
        }
      }
    }

    base
  }

  def solve(implicit sc: Scanner): Unit = {
    val N = sc.nextLine().toInt
    val A = readLineLongs

    println(test(N).zipWithIndex.map { case (e, i) => e * A(i) }.sum % 1000000007)
  }
}
