n = int(input())
x_lis = list(map(int, input().split()))
def dfs(x_lis, dis):
    if len(x_lis) == 1:
        return dis % (10 ** 9 + 7)
    cur_dis = 0
    for i in range(len(x_lis) - 1):
        cur_dis += dfs(x_lis[:i] + x_lis[i + 1:], dis + x_lis[i + 1] - x_lis[i])
    return cur_dis % (10 ** 9 + 7)
print(dfs(x_lis, 0))