Problem:


Score : 600 points

Problem Statement

There are N slimes standing on a number line.
The i-th slime from the left is at position x_i.

It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}.

Niwango will perform N-1 operations. The i-th operation consists of the following procedures:

Choose an integer k between 1 and N-i (inclusive) with equal probability.

Move the k-th slime from the left, to the position of the neighboring slime to the right.

Fuse the two slimes at the same position into one slime.

Find the total distance traveled by the slimes multiplied by (N-1)! (we can show that this value is an integer), modulo (10^{9}+7). If a slime is born by a fuse and that slime moves, we count it as just one slime.

Constraints

2 \leq N \leq 10^{5}

1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}

x_i is an integer.

Subtasks

400 points will be awarded for passing the test cases satisfying N \leq 2000.

Input

Input is given from Standard Input in the following format:

N
x_1 x_2 \ldots x_N

Output

Print the answer.

Sample Input 1

3
1 2 3

Sample Output 1

5

With probability \frac{1}{2}, the leftmost slime is chosen in the first operation, in which case the total distance traveled is 2.

With probability \frac{1}{2}, the middle slime is chosen in the first operation, in which case the total distance traveled is 3.

The answer is the expected total distance traveled, 2.5, multiplied by 2!, which is 5.

Sample Input 2

12
161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932

Sample Output 2

750927044

Find the expected value multiplied by (N-1)!, modulo (10^9+7).



Sample input:
3
1 2 3


Sample output:
5

Submission status: Wrong Answer

Solution code:
p = 10**9+7
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x
    if m%2==0:
        return (pow(x,m//2)**2)%p
    else:
        return (x*(pow(x,(m-1)//2)**2)%p)%p

N = int(input())
A = [1 for _ in range(N+1)]
for i in range(2,N+1):
    A[i] = (A[i-1]*i)%p
B = [1 for _ in range(N+1)]
B[N] = pow(A[N],p-2)
for i in range(N-1,1,-1):
    B[i] = (B[i+1]*(i+1))%p
X = list(map(int,input().split()))
X.insert(0,0)
C = [0 for i in range(N+1)]
C[1] = A[N-1]
for i in range(2,N):
    C[i] = (C[i-1]-A[N-1]*B[i])%p
C[N] = 0
for i in range(1,N):
    C[N] = (C[N]+C[i])%p
ans = (C[N]*X[N])%p
for i in range(1,N):
    ans = (ans-C[i]*X[i])%p
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
x=list(map(int,input().split()))

kaijo=1
for i in range(n-1):
    kaijo*=n-i-1
    kaijo%=mod
# print(kaijo)

ans=0
cnt=0
for i in range(n-1):
    y1,y2=x[i],x[i+1]
    sa=y2-y1
    cnt+=kaijo//(i+1)
    ans+=cnt*sa
    ans%=mod

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

mod = 10**9 + 7
stdin = np.array([int(_) for _ in open(0).read().split()])
N, X = stdin[0], stdin[1:]
A = np.array([pow(i, mod - 2, mod) for i in range(N)])
D = X[1:] - X[:-1]
f = 1
for i in range(1, N):
    f *= i
    f %= mod
A = np.cumsum(A)
A *= f
A %= mod
A[1:] *= D
A %= mod
print(np.sum(A) % mod)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
i8 = np.int64
mod = 10**9 + 7


def main(N, X, A):
    D = X[1:] - X[:-1]
    f = 1
    for i in range(1, N):
        f *= i
        f %= mod
    A = np.cumsum(A)
    A *= f
    A %= mod
    A[1:]*=D
    A%=mod
    print(np.sum(A)%mod)


if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', '(i8, i8[:], i8[:],)')(main)
    # b1: bool, i4: int32, i8: int64, double: f8, [:], [:, :]
    cc.compile()
else:
    from my_module import main
    stdin = np.array([int(_) for _ in open(0).read().split()])
    N, X = stdin[0], stdin[1:]
    A = np.array([pow(i, mod - 2, mod) for i in range(N)])
    main(N, X, A)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from math import factorial
import decimal
decimal.getcontext().prec=1000
n=int(input())
x=list(map(int,input().split()))
m=10**9+7
l=list(accumulate([decimal.Decimal(1)/decimal.Decimal(str(i))for i in range(1,10**5+1)]))
ans=0
for i in range(n-1):ans+=(x[i+1]-x[i])*l[i]
print((int(ans*factorial(n-1)))%m)

Submission status: Wrong Answer

Solution code:
mod = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
ans = 0
fact = [i for i in range(n+1)]
fact[0] = 1
for i in range(n):
  fact[i+1] *= fact[i]
  fact[i+1] %= mod
tmp = [None] * n
tmp[0] = 0
for i in range(1,n):
	tmp[i] = (tmp[i-1] + fact[n-1] // i) % mod
for i in range(1,n):
  ans += (a[i]-a[i-1]) * tmp[i]
  ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
mod = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
ans = 0
fact = [i for i in range(n+1)]
fact[0] = 1
for i in range(n):
  fact[i+1] *= fact[i]
  fact[i+1] %= mod
tmp = [None] * n
tmp[0] = 0
for i in range(1,n):
	tmp[i] = (tmp[i-1] + fact[n-1] // i) % mod
for i in range(1,n):
  ans += (a[i]-a[i-1]) * tmp[i]
  ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
x = list(map(int, input().split()))
kyori = [x[i + 1] - x[i] for i in range(N - 1)]
MOD = 10 ** 9 + 7
kai = [0] * (N + 1)
kai[0] = 1
for i in range(1, N + 1):
    kai[i] = (kai[i - 1] * i) % MOD
c = [0] * N
c[0] = 1
for i in range(1, N):
    c[i] = c[i - 1] + (1 / (i + 1))
ans = 0
for i in range(N - 1):
    ans += (c[i] * kyori[i]) % MOD

print(int(ans * kai[N - 1] % MOD))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
x = list(map(int, input().split()))
kyori = [x[i + 1] - x[i] for i in range(N - 1)]
MOD = 10 ** 9 + 7
kai = [0] * (N + 1)
kai[0] = 1
for i in range(1, N + 1):
    kai[i] = (kai[i - 1] * i) % MOD
c = [0] * N
c[0] = 1
for i in range(1, N):
    c[i] = c[i - 1] + (1 / (i + 1))
ans = 0
for i in range(N - 1):
    ans += (c[i] * kyori[i]) % MOD

print(ans * kai[N - 1] % MOD)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
x = list(map(int, input().split()))
kyori = [x[i + 1] - x[i] for i in range(N - 1)]
MOD = 10 ** 9 + 7
kai = [0] * (N + 1)
kai[0] = 1
for i in range(1, N + 1):
    kai[i] = (kai[i - 1] * i) % MOD

kitai = 0
for i in range(2, N + 1):
    kitai += (((i * (i - 1)) // 2) / (i - 1)) * kyori[i - 2]

print(int((kitai * kai[N - 1]) % MOD))

Submission status: Wrong Answer

Solution code:
import sys
#import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def factorial(x, mod=10**9+7):
    # x! 階乗 ex) factorial(5) = 120
    tmp = 1
    for i in range(1, x+1):
        tmp = (tmp * i) % mod
    return tmp

N = ir()
X = lr()
MOD = 10 ** 9 + 7
limit = factorial(N-1)
last = X[-1]
X = [last - x for x in X] #最後までの距離
answer = 0
for i in range(1, N):
    answer += (X[i-1] * limit // i)%MOD
    answer %= MOD

print(answer)

# 42

Submission status: Wrong Answer

Solution code:
import sys
#import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def factorial(x, mod=10**9+7):
    # x! 階乗 ex) factorial(5) = 120
    tmp = 1
    for i in range(1, x+1):
        tmp = (tmp * i) % mod
    return tmp

N = ir()
X = lr()
MOD = 10 ** 9 + 7
limit = factorial(N-1)
last = X[-1]
X = [(last - x)%MOD for x in X] #最後までの距離
answer = 0
for i in range(1, N):
    answer += (X[i-1] * limit // i)%MOD
    answer %= MOD

print(answer)

# 42

Submission status: Wrong Answer

Solution code:
MOD = 10**9+7

N = int(input())
x = list(map(int, input().split()))

f = [1]
for i in range(N):
    f.append(f[-1]*(i+1)%MOD)

ans = 0
c = 0
for i in range(N-1):
    if f[N-1] % (i+1):
        c += f[N-1]
    else:
        c += f[N-1] // (i+1)
    ans += c * (x[i+1] - x[i])
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
res = 0
mod = 10 ** 9 + 7
class Factorial:
  def __init__(self, n, mod):
    self.f = [1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i = [pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i):
    return self.f[i]
  def ifactorial(self, i):
    return self.i[i]
  def combi(self, n, k):
    return self.f[n] * self.i[n - k] % mod * self.i[k] % mod
f = Factorial(N, mod)
for i in range(N - 1):
  for j in range(i, N - 1):
    res += f.factorial(j - i) * f.combi(N - 1, j - i + (j == N - 2)) % mod * (a[j + 1] - a[i]) % mod
    res %= mod
    #print(i, j, res, f.factorial(j - i) * f.combi(N - 1, j - i + (j == N - 1)), (a[j + 1] - a[i]))
print(res)

Submission status: Wrong Answer

Solution code:
MOD = 10 ** 9 + 7
n = int(input())
x = list(map(int, input().split()))
f = 1
for i in range(n - 1):
    f *= (i + 1)
    f %= MOD
ans = 0
t = 0
for i in range(n - 1):
    t += f // (i + 1)
    ans += t * (x[i + 1] - x[i])
print(ans % MOD)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = list(map(int,input().split()))
dp = [[0]*(N+2) for _ in range(3)]
dp[1][0] = -1
dp[1][1] = -1
dp[1][2] = 1
a = 1
MOD = 10**9+7
for i in range(2,N):
    a = (a*(i-1))%MOD
    i2 = (i+2)%2+1
    i3 = (i+1)%2+1
    dp[i3][1] = (dp[i2][1]*(i-1) - a)%MOD
    for j in range(1,i+2):
        dp[i3][j] = (dp[i2][j]*(i-j) + dp[i2][j-1] * (j-1))%MOD
    dp[i3][i+1] = (dp[i2][i]*i + a)%MOD
res = 0
n = (N-2)%2+1
for i in range(N):
    res += (dp[n][i+1]*x[i])%MOD
print(res%MOD)

Submission status: Wrong Answer

Solution code:
MOD = 10**9+7
N = int(input())
x = list(map(int,input().split()))
def mod_pow(x,n,mod):
    res = 1
    while(n > 0):
        if(n and 1):
            res = res * x % mod
        x = x * x % mod
        n >>= 1
    return res
prob = []
a = 0
for i in range(1,N):
    a += mod_pow(i,MOD-2,MOD)
    a %= MOD
    prob.append(a)
ans = 0
for i in range(1,N):

    """for j in range(1,i+1):
        prob += 1/j
    """
    ans += (x[i]-x[i-1]) * prob[i-1]
    ans %= MOD
for i in range(1,N):
    ans *= i
    ans %= MOD
ans = int(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction as Frc
import math

n = int(input())
slime = [int(x) for x in input().split()]

md = 10 ** 9 + 7
fct = math.factorial(n - 1) % md
ans = 0
fr = Frc(1, 1)
for i in range(n - 1):
    c = fr.numerator
    p = fr.denominator
    ans = (ans + int(fct / p) % md * c % md * (slime[i + 1] - slime[i]) % md) % md
    fr += Frc(1, i + 2)
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction as Frc
import math

n = int(input())
slime = [int(x) for x in input().split()]

md = 10**9+7
fct = math.factorial(n-1) % md
ans = 0
fr = Frc(1, 1)

for i in range(n-1):
    ans = (ans + fct * (slime[i+1] - slime[i]) % md * fr) % md
    fr += Frc(1, i + 2)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
mod = 10**9 + 7
# (N-1)!を求める
fac=1
for i in range(1,n):
  fac = fac*i%mod
# 個数テーブルを準備する
cnt=[0]*n
for i in range(1,n):
  cnt[i] = fac // i
  cnt[i] = (cnt[i]+cnt[i-1])
# 計算
ans=0
for i in range(n-1):
  ans += (A[i+1]-A[i]) * cnt[i+1]

print(ans%mod)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
slime = [int(x) for x in input().split()]
fct = math.factorial(n-1) % 1000000007
aa = 0
for a in range(n-1):
    for b in range(a+1,n):
        buf_c = b - a - 1
        buf_p = b - a + 1
        if b == n - 1:
            buf_p -= 1
        if buf_c == 0:
            buf_c = 1
        buf_sum = (fct * math.factorial(buf_c) / math.factorial(buf_p) ) % 1000000007
        # print(buf_c,"/",buf_p,"buf_sum:",buf_sum,"{}→{}".format(str(slime[a]),str(slime[b])))
        # print("答え",pt["{}→{}".format(str(slime[a]),str(slime[b]))])
        aa += (buf_sum * (slime[b] - slime[a])) % 1000000007
        aa %= 1000000007

print(int(aa % 1000000007))

Submission status: Wrong Answer

Solution code:
#----------------------------------------------------------
P = 10**9 + 7
N = 100001 #使う最大値+1以上にする、値に注意3*10^5とかにしとくと安心
inv = [0] + [1] # 1/x
finv = [1] + [1] # 1/x!
fac = [1] + [1] # x!
for i in range(2,N):
  inv += [inv[P % i] * (P - int(P / i)) % P]
  fac += [(fac[i-1] * i) % P]
  finv += [(finv[i-1] * inv[i]) % P]

def comb(a, b):
    if a<b or a<0 or b<0:
        return 0 # error
    return (fac[a] * ((finv[b] * finv[a-b]) % P)) %P
#----------------------------------------------------------

n=int(input())
if n > 2000:
    exit(0)
x=list(map(int,input().split()))
ans=0
for i in range(n-1):
    t = (x[n-1]-x[i])%P
    o =(fac[i]*fac[n-2-i])%P
    g = (comb(n-1,n-1-i)*o)%P
    t = (t * g)%P
    ans=(ans+t)%P

for i in range(n-1):
    for j in range(i+1,n-1):
        t = (x[j]-x[i])%P
        o =(fac[n-1-j+i-1]*fac[j-i-1])%P
        g = (comb(n-1,j-i+1)*o)%P
        t = (t * g)%P
        ans=(ans + t)%P
print(ans%P)

Submission status: Wrong Answer

Solution code:
#----------------------------------------------------------
P = 10**9 + 7
N = 100001 #使う最大値+1以上にする、値に注意3*10^5とかにしとくと安心
inv = [0] + [1] # 1/x
finv = [1] + [1] # 1/x!
fac = [1] + [1] # x!
for i in range(2,N):
  inv += [inv[P % i] * (P - int(P / i)) % P]
  fac += [(fac[i-1] * i) % P]
  finv += [(finv[i-1] * inv[i]) % P]

def comb(a, b):
    if a<b or a<0 or b<0:
        return 0 # error
    return (fac[a] * ((finv[b] * finv[a-b]) % P)) %P
#----------------------------------------------------------

n=int(input())
if n > 2000:
    exit(0)
x=list(map(int,input().split()))
s = [0] * n
for i in range(n):
    s[i] = x[i] + (s[i-1] if i>0 else 0)
ans=0

for i in range(n-1):
    t = (x[n-1]-x[n-2-i])%P
    t = (t * (fac[n-1]*inv[i+1])%P)%P
    ans=(ans+t)%P
for i in range(1, n-1):
    t = (s[n-2] - s[i-1] - s[n-2-i])%P
    p = (((fac[n-1] * inv[i])%P) * inv[i+1])%P
    ans = (ans + (t*p)%P)%P

print(ans%P)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
mod = 10**9 + 7
# (N-1)!を求める
fac=1
for i in range(1,n):
  fac = fac*i%mod
# 個数テーブルを準備する
cnt=[0]*n
for i in range(1,n):
  cnt[i] = fac // i % mod
  cnt[i] = (cnt[i]+cnt[i-1]) % mod
# 計算
ans=0
for i in range(n-1):
  ans += (A[i+1]-A[i]) * cnt[i+1]
  ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list( map(int, input().split()))

ans = 0
MOD = 10**9 + 7

factorial = 1
for i in range(2,n):
    factorial = (factorial%MOD * i%MOD) %MOD

p = [0]*(n-1)
p[0] = 1 * factorial%MOD

for i in range(1,n-1):
    p[i] = p[i-1] + (factorial/(i+1))%MOD
    p[i] %= MOD

for i in range(n-1):
    ans += (x[i+1]-x[i])%MOD*p[i]
    ans %= MOD

print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list( map(int, input().split()))

ans = 0
MOD = 10**9 + 7

factorial = 1
for i in range(2,n):
    factorial = (factorial * i) %MOD

p = [0]*(n-1)
p[0] = 1 * factorial%MOD

for i in range(1,n-1):
    p[i] = p[i-1] + factorial/(i+1)
    p[i] %= MOD

for i in range(n-1):
    ans += (x[i+1]-x[i])*p[i]
    ans %= MOD

ans %= MOD

print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list( map(int, input().split()))

ans = 0
MOD = 10**9 + 7

factorial = 1
for i in range(2,n):
    factorial = (factorial * i) %MOD

p = [0]*(n-1)
p[0] = 1 * factorial%MOD

for i in range(1,n-1):
    p[i] = p[i-1] + (factorial/(i+1))%MOD
    p[i] %= MOD

for i in range(n-1):
    ans += (x[i+1]-x[i])*p[i]
    ans %= MOD

ans %= MOD

print(int(ans))

Submission status: Wrong Answer

Solution code:
MOD = 10**9+7
N = int(input())
x = list(map(int,input().split()))

prob = []
a = 0
for i in range(1,N):
    a += 1/i
    prob.append(a)
ans = 0
for i in range(1,N):

    """for j in range(1,i+1):
        prob += 1/j
    """
    ans += (x[i]-x[i-1]) * prob[i-1]
for i in range(1,N):
    ans *= i
    ans %= MOD
ans = int(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 10**9+7
N = int(input())
x = list(map(int,input().split()))

kaijo = 1
for i in range(1,N):
    kaijo *= i
    kaijo %= MOD
"""for i in range(N-1):
    d[i] = x[i+1] - x[i]
    d[i] %= MOD
"""
prob = []
a = 0
for i in range(1,N):
    a += 1/i
    prob.append(a)
ans = 0
for i in range(1,N):

    """for j in range(1,i+1):
        prob += 1/j
    """
    ans += (x[i]-x[i-1]) * prob[i-1]
for i in range(1,N):
    ans *= i
    ans %= MOD 
ans = int(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 10**9+7
N = int(input())
x = list(map(int,input().split()))

kaijo = 1
for i in range(1,N):
    kaijo *= i
    kaijo %= MOD
"""for i in range(N-1):
    d[i] = x[i+1] - x[i]
    d[i] %= MOD
"""
prob = []
a = 0
for i in range(1,N):
    a += 1/i
    prob.append(a)
ans = 0
for i in range(1,N):

    """for j in range(1,i+1):
        prob += 1/j
    """
    ans += (x[i]-x[i-1]) * prob[i-1]
ans *= kaijo
ans %= MOD
ans = int(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 10**9+7
N = int(input())
x = list(map(int,input().split()))

kaijo = 1
for i in range(1,N):
    kaijo *= i
    kaijo %= MOD
d = [0]*(N-1)
"""for i in range(N-1):
    d[i] = x[i+1] - x[i]
    d[i] %= MOD
"""
ans = 0
for i in range(1,N):
    prob = 0
    for j in range(1,i+1):
        prob += 1/j
    ans += (x[i]-x[i-1]) * prob
ans *= kaijo
ans %= MOD
ans = int(ans)
print(ans)

Submission status: Wrong Answer

Solution code:

import math

n = int(input())
x = list( map(int, input().split()))

ans = 0
MOD = 10**9 + 7

fact = math.factorial(n-1)%MOD

p = [0]*(n-1)
p[0] = 1 * fact

for i in range(1,n-1):
    p[i] = p[i-1] + fact/(i+1)
    p[i] %= MOD

for i in range(n-1):
    ans += (x[i+1]-x[i])*p[i]
    ans %= MOD

ans %= MOD

print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list( map(int, input().split()))

ans = 0
MOD = 10**9 + 7

fact = 1
for i in range(1,n):
    fact *= i
    fact %= MOD

p = [0]*(n-1)
p[0] = 1 * fact

for i in range(1,n-1):
    p[i] = p[i-1] + fact/(i+1)
    p[i] %= MOD

for i in range(n-1):
    ans += (x[i+1]-x[i])*p[i]
    ans %= MOD

ans %= MOD

print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
x = list( map(int, input().split()))

ans = 0
MOD = 10**9 + 7

p = [1]*(n-1)
p = np.array(p)

for i in range(1,n-1):
    p *= i+1
    p[i] = p[i-1] + p[i]/(i+1)
    p[i] %= MOD

for i in range(n-1):
    ans += (x[i+1]-x[i])*p[i]
    ans %= MOD

ans %= MOD

print(int(ans))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int
import math
from itertools import accumulate

def mod_factorial(n):
    value = 1
    for i in range(n,0,-1):
        value*=i
        value%=MOD

    return value

def solve(N: int, x: "List[int]"):
    gyakusu = []
    dif_x = []
    for i in range(1,N):
        gyakusu.append(1/i)
        dif_x.append(x[i]-x[i-1])
    
    accum_gyakusu = list(accumulate(gyakusu))
    answer = 0

    for i in range(N-1):
        answer += accum_gyakusu[i]*dif_x[i]
        answer %= MOD
    
    print(int(answer*mod_factorial(N-1)%MOD))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, x)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
P = 0
B = 10**9 + 7
for i in range(N-1):
    P = 2 * P + X[N -1] - X[i]
    P %= B
print(P%B)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
x = list(map(int, input().split()))
ans = 0
mod = 10 ** 9 + 7
v = math.factorial(n - 1)


for i in range(1, n):
    w = (v//i)%mod
    ans += ((x[n - 1] - x[i - 1]) * w)%mod


print(int(ans))

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
x = list(map(int, input().split()))
ans = 0
mod = 10 ** 9 + 7
v = math.factorial(n - 1)
v %=mod

for i in range(1, n):
    ans += (x[n - 1] - x[i - 1]) * v // i
    ans %= mod

print(int(ans))

Submission status: Wrong Answer

Solution code:
from math import ceil
N = int(input())
X = list(map(int, input().split()))
MOD = 10 ** 9 + 7

# 間の距離を計算
distances = [0] + [X[i + 1] - X[i] for i in range(N - 1)]

expected_cnt = [0] * N
for i in range(1, N):
    expected_cnt[i] = expected_cnt[i - 1] + (1 / i)

factorial = 1
for i in range(1, N):
    factorial *= i
    factorial %= MOD


expected_cnt = [ceil(e * factorial) % MOD for e in expected_cnt]
moves = [(d * e) % MOD for d, e in zip(distances, expected_cnt)]
print(int(sum(moves)) % MOD)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int
import math
from itertools import accumulate

def mod_factorial(n):
    value = 1
    for i in range(n,0,-1):
        value*=i
        value%=MOD

    return value

def solve(N: int, x: "List[int]"):
    gyakusu = []
    dif_x = []
    for i in range(1,N):
        gyakusu.append(1/i)
        dif_x.append(x[i]-x[i-1])
    
    accum_gyakusu = list(accumulate(gyakusu))
    answer = 0
    for i in range(N-1):
        answer += accum_gyakusu[i]*dif_x[i]
        answer %= MOD
    # print(answer)
    
    print(int(answer*mod_factorial(N-1)%MOD))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, x)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# dwacon6th-prelims/dwacon6th_prelims_b
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

MAX = 10**5 + 100
MOD = 10**9 + 7

fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX
coef = [0] * MAX

fac[0:2] = (1, 1)
finv[0:2] = (1, 1)
inv[1] = 1
coef[0:2] = (1, 1)

for i in range(2, MAX):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * MOD // i % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD
    coef[i] = (coef[i - 1] * i) % MOD + fac[i - 1] % MOD

def main():
    N = i2n()
    n = N - 1
    x = i2nn()
    total = 0
    for i in range(1, N):
        d = x[i] - x[i - 1]
        total = (total + (((coef[i] * fac[n]) % MOD * finv[i]) % MOD) * d % MOD) % MOD
    print(total % MOD)
    return

main()

Submission status: Wrong Answer

Solution code:
import math
mod = 10 ** 9 + 7


n = int(input())
X = list(map(int, input().split()))

ans = 0
cum_pattern = []
pattern = 0
for i in range(1, n):
    pattern += math.factorial(n-1) % mod // i % mod
    pattern %= mod
    cum_pattern.append(pattern)


ans = 0
for i in range(n-1):
    dist = X[i+1] - X[i]
    ans += cum_pattern[i] * dist % mod
    ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
import math
mod = 10 ** 9 + 7


n = int(input())
X = list(map(int, input().split()))

ans = 0
cum_pattern = []
pattern = 0
base = math.factorial(n-1) % mod
for i in range(1, n):
    pattern += base // i
    pattern %= mod
    cum_pattern.append(pattern)


ans = 0
for i in range(n-1):
    dist = X[i+1] - X[i]
    ans += cum_pattern[i] * dist % mod
    ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
import math
mod = 10 ** 9 + 7


n = int(input())
X = list(map(int, input().split()))

ans = 0
cum_pattern = []
pattern = 0
base = math.factorial(n-1) % mod
for i in range(1, n):
    pattern += base // i
    pattern %= mod
    cum_pattern.append(pattern)


ans = 0
for i in range(n-1):
    dist = X[i+1] - X[i]
    ans += cum_pattern[i] * dist % mod
    ans %= mod

print

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys

N=input()

mod=10**9+7
fact=[1]
fact_tmp = 1
for i in range(1, N+1):
    fact_tmp *= i
    fact_tmp %= mod
    fact.append(fact_tmp)

X=map(int, sys.stdin.readline().split())
L=map(lambda x: x**-1*fact[N-1], range(1,N))

L_RUISEKI=[]

for i,x in enumerate(L):
    if i==0: L_RUISEKI.append(x)
    else: L_RUISEKI.append(L_RUISEKI[-1]+x)


ans=0
for i in range(N-1):
    value=X[i+1]-X[i]
    ans+=value*L_RUISEKI[i]
    ans%=mod

print ans

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys

N=input()

mod=10**9+7
fact=[1]
fact_tmp = 1
for i in range(1, N+1):
    fact_tmp *= i
    fact_tmp %= mod
    fact.append(fact_tmp)

X=map(int, sys.stdin.readline().split())
L=map(lambda x: x**-1*fact[N-1], range(1,N))

L_RUISEKI=[]

for i,x in enumerate(L):
    if i==0: L_RUISEKI.append(x)
    else: L_RUISEKI.append(L_RUISEKI[-1]+x)


ans=0
for i in range(N-1):
    value=X[i+1]-X[i]
    ans+=value*L_RUISEKI[i]
    ans%=mod

print int(ans)

Submission status: Wrong Answer

Solution code:
from decimal import *

n = int(input())
X = list(map(Decimal, input().split()))
mod = Decimal(10**9+7)

e = Decimal(1)
E = [Decimal(1)]
for i in range(2,n):
    e += + 1/Decimal(i)
    E.append(e)

Dif = []
for i in range(n-1):
    Dif.append(X[i+1]-X[i])

ans = 0
for i in range(n-1):
    ans += E[i] * Dif[i]
    ans = ans % mod

for i in range(1,n):
    ans = ans*i
    ans = ans % mod

ans = Decimal(ans).quantize(Decimal('1.'), rounding=ROUND_CEILING)

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys

N=input()
X=map(int, sys.stdin.readline().split())
L=map(lambda x: x**-1, range(1,N))

L_RUISEKI=[]

for i,x in enumerate(L):
    if i==0: L_RUISEKI.append(x)
    else: L_RUISEKI.append(L_RUISEKI[-1]+x)

ans=0
for i in range(N-1):
    value=X[i+1]-X[i]
    ans+=value*L_RUISEKI[i]

mod=10**9+7
fact=[1]
fact_tmp = 1
for i in range(1, N+1):
    fact_tmp *= i
    fact_tmp %= mod
    fact.append(fact_tmp)

print int(ans*fact[N-1]%mod)

Submission status: Wrong Answer

Solution code:
n = int(input())
X = list(map(int, input().split()))

e = 1
E = [1]
for i in range(2,n):
    e += + 1/i
    E.append(e)

Dif = []
for i in range(n-1):
    Dif.append(X[i+1]-X[i])

ans = 0
for i in range(n-1):
    ans += E[i] * Dif[i]

ans = ans % (10**9+7)
for i in range(1,n):
    ans = ans*i
    ans = ans % (10**9+7)

print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    x = [int(i) for i in input().split()]

    MOD = 10**9+7

    answer = 0
    for i in range(N-1):
        Psum = 0
        for j in range(i+1):
            Psum = (Psum + 1/(j+1)) % MOD
        answer = (answer + (x[i+1] - x[i]) * Psum) % MOD

    tmp = 1
    for i in range(1,N):
        tmp = (tmp * i) % MOD
    answer = (answer * tmp) % MOD
    print(int(answer))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
x = [int(i) for i in input().split()]

MOD = 10**9+7

answer = 0
for i in range(N-1):
    Psum = 0
    for j in range(i+1):
        Psum += 1/(j+1)
    answer = (answer + (x[i+1] - x[i]) * Psum) % MOD

tmp = 1
for i in range(1,N):
    tmp = (tmp * i) % MOD
answer = (answer * tmp) % MOD
print(int(answer))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import math
import fractions
#import numpy as np
inf =int(10**20)
mod=int(10**9+7)
#main
n=int(input())
fac=math.factorial(n-1)%mod
X=list(map(int,input().split()))
A=[X[a+1]-X[a] for a in range(n-1)]
C=[0 for a in range(n-1)]
ans=0
for a in range(n-1):
    len=a+1
    if a==0:
        C[a]=1
        ans+=C[a]*A[a]
    else:
        C[a]=(1/len)*(1+C[a-1])+((len-1)/len)*C[a-1]
        ans+=C[a]*A[a]
    ans%=mod
ans*=fac
ans%=mod
print(int(ans))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys

N=input()
X=map(int, sys.stdin.readline().split())
L=map(lambda x: x**-1, range(N-1,0,-1))

L_RUISEKI=[]

for i,x in enumerate(L):
    if i==0: L_RUISEKI.append(x)
    else: L_RUISEKI.append(L_RUISEKI[-1]+x)

ans=0

for i in range(N-1):
    #print "===",i,"==="
    value=X[i+1]-X[i]
    #print "value :: ", value
    #print "kitaichi :: ",1+(N-1-i)*L_RUISEKI[i]
    #print "keisuu :: ",(N-1-i)
    ans+=value*(N-1-i)*L_RUISEKI[i]


mod=10**9+7
fact=[1]
fact_tmp = 1
for i in range(1, N+1):
    fact_tmp *= i
    fact_tmp %= mod
    fact.append(fact_tmp)

print int(ans*fact[N-1]%mod)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys

N=input()
X=map(int, sys.stdin.readline().split())
L=map(lambda x: x**-1, range(N-1,0,-1))

L_RUISEKI=[]

for i,x in enumerate(L):
    if i==0: L_RUISEKI.append(x)
    else: L_RUISEKI.append(L_RUISEKI[-1]+x)

ans=0

for i in range(N-1):
    #print "===",i,"==="
    value=X[i+1]-X[i]
    #print "value :: ", value
    #print "kitaichi :: ",1+(N-1-i)*L_RUISEKI[i]
    #print "keisuu :: ",(N-1-i)
    ans+=value*(N-1-i)*L_RUISEKI[i]


mod=10**9+7
fact=[1]
fact_tmp = 1
for i in range(1, N+1):
    fact_tmp *= i
    fact_tmp %= mod
    fact.append(fact_tmp)

print ans*fact[N-1]%mod

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(map(int, input().split()))
MOD = 10 ** 9 + 7

fact = [1]*(N+1)
rfact = [1]*(N+1)
r = 1
for i in range(1, N+1):
  fact[i] = r = r * i % MOD
rfact[N] = r = pow(fact[N], MOD-2, MOD)
for i in range(N, 0, -1):
  rfact[i-1] = r = r * i % MOD

ret = 0
inverse = 0
for i in range(1, N):
    diff = X[i] - X[i-1]
    inverse += rfact[i]
    ret += diff * inverse
    ret %= MOD

print(ret*fact[N-1]%MOD)

Submission status: Wrong Answer

Solution code:
import math
import sys 
input = sys.stdin.readline
N = int(input())
x = list(map(int,input().split()))
mod = 10**9+7

d = [0]*(N-1)
"""
for i in range(N-1):
    d[i] = x[i+1]-x[i]
    d[i] %= mod
"""

kaijou = 1
for i in range(1,N):
    kaijou *= i%mod
    kaijou %= mod


ans=0
x=0
"""
def pow_r(x, n):

    x %= mod
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r(x ** 2, n // 2)%mod
    else:  # standard case ② n is odd
        return (x * (pow_r(x ** 2, (n - 1) // 2)))%mod

for i in range(N-1):
    #(i+1)%(mod-2)を計算してyへ
    y = pow_r(i+1,mod-2)
    #x+= kaijou//(i+1))%(10**9+7)
    x += (kaijou*y)%mod
    ans+= (d[i]*x)%mod
"""
print(ans%mod)

Submission status: Wrong Answer

Solution code:
import math
import sys 
input = sys.stdin.readline
N = int(input())
x = list(map(int,input().split()))
mod = 10**9+7

d = [0]*(N-1)
"""
for i in range(N-1):
    d[i] = x[i+1]-x[i]
    d[i] %= mod
"""

kaijou = 1
for i in range(1,N):
    kaijou *= (i%mod)
    kaijou %= mod


ans=0
x=0
"""
def pow_r(x, n):

    x %= mod
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r(x ** 2, n // 2)%mod
    else:  # standard case ② n is odd
        return (x * (pow_r(x ** 2, (n - 1) // 2)))%mod

for i in range(N-1):
    #(i+1)%(mod-2)を計算してyへ
    y = pow_r(i+1,mod-2)
    #x+= kaijou//(i+1))%(10**9+7)
    x += (kaijou*y)%mod
    ans+= (d[i]*x)%mod
"""
print(ans%mod)