import itertools
from fractions import gcd

def main():
    N = int(input())
    a = list(map(int, input().split()))
    standard = a[-1] - a[0]
    all_pattern = list(itertools.permutations([i for i in range(1,N)]))
    #print(all_pattern)
    total = standard * len(all_pattern)
    for i, node in enumerate(all_pattern):
        for p, num in enumerate(node):
            if p >= 0 and num-1 in node[0:num-1]:
                total += a[num] -a[num-1]
                
    print(int(total%(10e9+7)))
 
main()