static void Method(string[] args) { long n = ReadLong(); long[] xs = ReadLongs(); long mask = 1000000000 + 7; CaseCalculator calculator = new CaseCalculator(mask, n); long[] divs = new long[n]; for (int i = 0; i < n; i++) { divs[i] = calculator.Reverse(i + 1); } long[] sums = new long[n]; sums[0] = divs[0]; for (int i = 1; i < n; i++) { sums[i] = (sums[i - 1] + divs[i]) % mask; } long res = 0; for (int i = 0; i < n - 1; i++) { long dist = xs[i + 1] - xs[i]; res += dist * sums[i]; res %= mask; } for (int i = 1; i < n; i++) { res = (res * i) % mask; } WriteLine(res); }