package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	x := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&x[i])
	}

	r := dfs(x)
	sum = r
	ans := sum % 1000000007
	fmt.Println(ans)
}

var sum = 0

var memo = map[string]int{}

func dfs(p []int) int {
	if len(p) == 2 {
		return p[1] - p[0]
	}

	s := fmt.Sprint(p)
	if v, ok := memo[s]; ok {
		return v
	}

	r := p[1] - p[0]
	for i := 0; i < len(p); i++ {
		tmp := make([]int, len(p))
		copy(tmp, p)
		r += dfs(unset(tmp, i))
	}

	memo[s] = r
	return r
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func unset(s []int, i int) []int {
	if i >= len(s) {
		return s
	}
	return append(s[:i], s[i+1:]...)
}

func factorial(n int) int {
	a := 1
	for i := 1; i <= n; i++ {
		a = (a * i) % 1000000007
	}
	return a
}
