import copy
def process(total, short_ls):
    lg = len(short_ls)
    if lg == 2:
        #print("returnきた")
        return short_ls[1]-short_ls[0]
    else:
        #print("short_ls", short_ls,"lg",lg)
        for i in range(lg-1):
            a = copy.copy(short_ls)
            #print("i",i,"a[1]",a[1])
            total+=(a[i+1]-a[i])
            total%=(10**9+7)
            a.pop(i)
            #print("a_pop_len",len(a))
            p = process(total, a)
            if type(p) is int:
                total+=p
                total%=(10**9+7)

        return total
if __name__ == "__main__":
    n = int(input())
    x_ls = list(map(int, input().split()))
    sub = process(0, x_ls)
    print(sub)
