output_description: For all of the N! orders, find the total cost of the N operations, and print
  the sum of those N! total costs, modulo 10^9+7.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      A_1 A_2 ... A_N
attempt: N = int(input())
  A = list(map(int, input().split()))
  
  P = 10**9 + 7
  memo = {str([]): 0}
  
  
  def dp(a):
      key = str(a)
      ret = memo.get(key, None)
      if ret != None:
          return ret
      ret = (sum(a) * len(a)) % P
      for i in range(len(a)):
          ret += dp(a[:i])
          ret += dp(a[i + 1 :])
      ret %= P
      memo[key] = ret
      return ret
  
  
  print(dp(A))
  
problem_description: Statement
  
  There are N blocks arranged in a row, numbered 1 to N from left to right. Each
  block has a weight, and the weight of Block i is A_i. Snuke will perform the
  following operation on these blocks N times:
  
    * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are _connected_ when, for all z ( x \leq z \leq y ), Block z is still not removed.
  
  There are N! possible orders in which Snuke removes the blocks. For all of
  those N! orders, find the total cost of the N operations, and calculate the
  sum of those N! total costs. As the answer can be extremely large, compute the
  sum modulo 10^9+7.
samples: [{"input": "2\n    1 2", "output": "9\n    \n\nFirst, we will consider the order \"Block 1 -> Block 2\". In the first\noperation, the cost of the operation is 1+2=3, as Block 1 and 2 are connected.\nIn the second operation, the cost of the operation is 2, as only Block 2\nremains. Thus, the total cost of the two operations for this order is 3+2=5.\n\nThen, we will consider the order \"Block 2 -> Block 1\". In the first operation,\nthe cost of the operation is 1+2=3, as Block 1 and 2 are connected. In the\nsecond operation, the cost of the operation is 1, as only Block 1 remains.\nThus, the total cost of the two operations for this order is 3+1=4.\n\nTherefore, the answer is 5+4=9.\n\n* * *"}, {"input": "4\n    1 1 1 1", "output": "212\n    \n\n* * *"}, {"input": "10\n    1 2 4 8 16 32 64 128 256 512", "output": "880971923"}]