# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
N = int(input())
L = list(map(int, input().split()))

dd = (10 ** 9) + 7
sum = 0
def srch(L, DelIndex) :
  global sum
  #print("srch IN")
  #print(len(L))
  if DelIndex != None :
    L.pop(DelIndex)
  if len(L) == 1 :
    #print("return")
    return 0
  else :
    #print(L)
    #print(len(L)-1)
    for i in range(len(L)-1) :
      #print("i")
      #print(i)
      #print("L[i]")
      #print(L[i])
      #print("L[i+1]")
      #print(L[i+1])
      sum += L[i+1]-L[i]
      copyL = copy.deepcopy(L)
      srch(copyL, i)

DelIndex = None
srch(L, DelIndex)

print (sum%dd)
