import java.util.Scanner

object Main {
  def main(args:Array[String]):Unit={
    val sc=new Scanner(System.in)
    val N=sc.nextInt()
    val As=List.fill(N)(sc.nextInt())
    println(answer(As))
  }
  def answer(ints: List[Int]):Int={
    (ints,ints.length) match{
      case (Nil,0) => 0
      case (xs,n) =>
        (1 to n).foldLeft(0)((z,i)=> (z + fact(n-1,1)*xs.sum%1000000007+fact(n-1,i)*answer(xs.take(i - 1))%1000000007+fact(n-1,n-i+1)*answer(xs.drop(i))%1000000007)%1000000007)%1000000007
    }
  }
  def fact(n:Int,m:Int):Int={
    n match{
      case num if num<m => 1
      case num => num*fact(num-1,m)%1000000007
    }
  }
}
