N=int(input())
X= [int(i) for i in input().split()]

def update(l):
    n = len(l)
    k = []
    k.append((l[0]*(n+1)) % lim)
    for i in range(1,n):
        k.append((l[0] + l[i-1]*(i+1) + l[i]*(n-i)) % lim)
    k.append((l[0] + l[n-1]*(n+1))% lim)
    return k

def generate(n):
    if n == 1:
        return [1]
    else:
        l = [1]
        for _ in range(n-1):
            l = update(l)
        return l

diff = [(X[i+1] -X[i]) % lim for i in range(N-1)]

M=generate(N-1)

ans = 0
for i in range(N-1):
    ans = (ans + (diff[i]*M[i]) % lim) % lim
print(ans)