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:
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):
    i %= mod
    kaijou *= i
    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
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)

Submission status: Wrong Answer

Solution code:
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:
N = int(input())
X = list(map(int, input().split()))
mod = 10**9+7
ans = 0

# ある区間X[3] - X[2]をあるスライムが通過する確率
# 3番目のスライムが通過する確率:1 (必ず通過する。3!=6通り。123, 132, 231, 213, 312, 321)
# 2番目のスライムが通過する確率:1/2 (先に3が選ばれる必要がある。3/6=1/2)
# 1番目のスライムが通過する確率:1/3 (先に3,2が選ばれる必要がある。2/6=1/3)
# ある区間X[i+1] - X[i]についてあるスライムi-jが通過する確率は 1/(j+1)

# 1 = 1
# 2 = 1 + 1/2 = 3/2
# 3 = 1 + 1/2 + 1/3 = 11/6
# 4 = 1 + 1/2 + 1/3 + 1/4 = 25/12
# 5 = 1 + 1/2 + 1/3 + 1/4 + 1/5 = 137/60

for i in range(N-1):
    d = X[i+1]-X[i]
    p = 1
    for j in range(1, i+1):
        p += 1/(j+1)
    ans += d * p

# (N-1)!
a = 1
for i in range(1, N):
    a *= i
    a %= mod

ans *= a
ans %= mod
print(int(ans))

Submission status: Wrong Answer

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

d = [0]*(N-1)
for i in range(N-1):
    d[i] = x[i+1]-x[i]
    d[i] %= 10**9+7

kaijou = 1
for i in range(1,N):
    kaijou *= i%(10**9+7)
kaijou %= (10**9+7)
ans=0
x=0
for i in range(N-1):
    x+= (kaijou//(i+1))%(10**9+7)
    ans+= (d[i]*x)%(10**9+7)

print(ans%(10**9+7))

Submission status: Wrong Answer

Solution code:
import numpy as np
from math import factorial
MOD = 10**9 + 7

n = int(input())

dist = np.diff(list(map(int, input().split())))
L = np.cumsum(np.array([1 / x for x in range(1, n)]))
n_1 = factorial(n-1) % MOD

# fac = [1] * n
# for i in range(1,n):
# 	fac[i] = fac[i-1] * i % MOD

# print(int(np.sum(L * dist * n_1)) % MOD)
ans = 0
for l, d in zip(L, dist):
    ans += l * d
    ans %= MOD

print(int(ans * n_1 % MOD))
# print(int(np.sum(dist * L * n_1) % MOD))

Submission status: Wrong Answer

Solution code:
import numpy as np
from math import factorial
MOD = 10**9 + 7

n = int(input())

dist = np.diff(list(map(int, input().split()))) % MOD
L = np.cumsum(np.array([1 / x for x in range(1, n)])) % MOD
n_1 = factorial(n-1) % MOD

# fac = [1] * n
# for i in range(1,n):
# 	fac[i] = fac[i-1] * i % MOD

# print(int(np.sum(L * dist * n_1)) % MOD)
ans = 0
for l, d in zip(L, dist):
    ans += l * d
    ans %= MOD
print(ans * n_1 % MOD)
# print(int(np.sum(dist * L * n_1) % MOD))

Submission status: Wrong Answer

Solution code:
import numpy as np
from math import factorial
MOD = 10**9 + 7

n = int(input())

dist = np.diff(list(map(int, input().split()))) % MOD
L = np.cumsum(np.array([1 / x for x in range(1, n)])) % MOD
# n_1 = factorial(n-1) % MOD

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

# print(int(np.sum(L * dist * n_1)) % MOD)
# ans = 0
# for l, d in zip(L, dist):
#     ans += ((l % MOD) * (d % MOD) * (n_1 % MOD)) % MOD
# print(int(ans) % MOD)
print(int(np.sum(dist * L * (fac[-1])) % MOD))

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    x = list(map(int,input().split()))
    
    mod = int(1e9+7)
    
    distance = []
    for i in range(N-1):
        distance.append((x[i+1]-x[i]))
        
    inv_sum = [0]*N
    inv_sum[0] = 1
    for i in range(1,N):
        inv_sum[i] = (inv_sum[i-1]+1/(i+1))%mod
    
    factorial = 1
    for i in range(1,N):
        factorial *= i
        factorial %= mod
    
    ans = 0
    for i in range(N-1):
        tmp = (factorial*inv_sum[i])%mod
        ans += (distance[i]*tmp)%mod
        ans %= mod
    
    print(int(ans%mod))

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

def inv_sum(j):
    tmp = 0
    for i in range(1,j+1):
        tmp += 1/i
    print(tmp)
    return tmp

mod = int(1e9+7)
ans = 0

for i in range(N-1):
    ans += (x[i+1]-x[i])*inv_sum(i+1)
    
for i in range(1,N):
    ans = (ans*i)

print(ans%mod)

Submission status: Wrong Answer

Solution code:
import statistics
import math

MOD = 10**9+7


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

    c = 0
    t = 0
    for i in range(n-1):
        c += 1/(i+1)
        c %= MOD
        t += c * (x[i+1]-x[i])
        t %= MOD

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


main()

Submission status: Wrong Answer

Solution code:
import statistics
import math

MOD = 10**9+7


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

    c = 0
    t = 0
    for i in range(n-1):
        c += 1/(i+1)
        c %= MOD
        t += c * (x[i+1]-x[i])
        t %= MOD

    fact = math.factorial(n-1) % MOD
    print(int(t * fact % MOD))


main()

Submission status: Wrong Answer

Solution code:
import statistics
import math

MOD = 10**9+7


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

    c = 0
    t = 0
    for i in range(n-1):
        c += 1/(i+1)
        c %= MOD
        t += c * (x[i+1]-x[i])
        t %= MOD
    
    print(0)
    #print(int(t * math.factorial(n-1) % MOD))


main()

Submission status: Wrong Answer

Solution code:
N,*X=map(int,open(0).read().split());M,g,r,h,i=10**9+7,1,0,[1],N;exec("i-=1;h+=[h[-1]*i%M];"*N);print(r)

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
n = 0
for i in range(N-1):
  n = n + (fact // (i+1))
  n = n % mod
  ans = ans + (x[i+1] - x[i]) * n

ans = ans % mod
print(ans)

Submission status: Wrong Answer

Solution code:
import collections as c
ip = lambda : map(int, input().split())
# ##############
N = int(input())
l = list(ip())
d = []
for i in range(N-1):
    d.append(l[i+1]-l[i])

ans = 0
mod = 1e9+7
c=0
l=1
for i in range(N-1):
    c = ((i+1)*c + l)%mod
    ans = ((i+1)*ans + c*d[i])%mod
    l = l*(i+1)%mod
print(int(ans%mod))

Submission status: Wrong Answer

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

mod = 10 ** 9 + 7

c = [1]
for i in range(1,N-1):
    c.append(c[i-1]+(1/(i+1)))

ans = 0
for i in range(N-1):
    ans += (c[i] * (x[i+1] - x[i])) % mod
    ans %= mod
    
for i in range(1,N):
    ans *= i
    ans %= mod

print(round(ans))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000)

n = int(input())
x = list(map(int, input().split()))
d = [x[i+1] - x[i] for i in range(n - 1)]

def fact(m):
  return m * fact(m-1) % 1000000007 if m != 1 else 1
 
fact_n_1 = fact(n-1)

e = [None] * (n-1)
for i in range(n-1):
  if i == 0:
    e[i] = fact_n_1
  else:
    e[i] = e[i - 1] + fact_n_1 // (i + 1)

print(sum(e_i * d_i % 1000000007
          for i, (d_i, e_i) 
          in enumerate(zip(d, e))) % 1000000007 )

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000)

n = int(input())
x = list(map(int, input().split()))
d = [x[i+1] - x[i] for i in range(n - 1)]

def fact(m):
  return m * fact(m-1) % 1000000007 if m != 1 else 1
 
fact_n_1 = fact(n-1)

e = [None] * (n-1)
for i in range(n-1):
  if i == 0:
    e[i] = fact_n_1
  else:
    e[i] = (e[i - 1] + fact_n_1 // (i + 1)) % 1000000007

print(sum(e_i * d_i % 1000000007
          for i, (d_i, e_i) 
          in enumerate(zip(d, e))) % 1000000007 )

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read

sys.setrecursionlimit(100002)
def myfact(n):
    if n < 2:
        return 1
    else:
        return n * myfact(n - 1)
n,*X=map(int,read().split())
last=X[-1]
X=[last-i for i in X[:-1]]
mod = 10**9+7
f=myfact(n-1)%mod
s = sum(f//i*item%mod for i,item in enumerate(X,1))
print(s%mod)

Submission status: Wrong Answer

Solution code:
from math import factorial
 
N = int(input())
x = list(map(int, input().split()))
mod = 10**9 + 7
x_dis = [x[i+1] - x[i] for i in range(N-1)]
ans = 0
m = N-1
fac = factorial(m) % mod
tmp = fac
for i in range(m):
    ans += x_dis[i] * tmp
    ans %= mod
print(ans)

Submission status: Wrong Answer

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

mod = 10**9 + 7

fac = [1, 1]
inv = [1, 1]
finv = [1, 1]
for i in range(2, n+5):
    fac.append(fac[i-1] * i % mod)
    inv.append(mod - inv[mod%i] * (mod//i) % mod)
    finv.append(finv[i-1] * inv[i] % mod)

ans = 0
j_inv = []
num = 0
for j in range(1, n):
    num += inv[j]
    num %= mod
    j_inv.append(num)

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

ans *=fac[n-1]
ans %= mod

print(ans)

Submission status: Wrong Answer

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

mod = 10**9 + 7

fac = [1, 1]
inv = [1, 1]
finv = [1, 1]
for i in range(2, n+5):
    fac.append(fac[i-1] * i % mod)
    inv.append(mod - inv[mod%i] * (mod//i) % mod)
    finv.append(finv[i-1] * inv[i] % mod)

ans = 0
j_inv = []
num = 0
for j in range(1, n):
    num += inv[j]
    num %= mod
    j_inv.append(num)

for i in range(n-1):
    ans += j_inv[i]
    ans %= mod

ans *=fac[n-1]
ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
sa = []
for i in range(n-1):
    sa.append(l[i+1]-l[i])

mod = 10**9+7
ans = 0
count = 0
kai = 1
for i in range(1,n):
    kai *= i
    kai %= mod
    
for i in range(n-1):
    count += kai//(i+1)
    count %= mod
    ans += sa[i]*count
    ans %= mod


print(int(ans%mod))

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy

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

if N == 2:
    print(x[1]-x[0])
elif N == 3:
    print(2*(x[2]-x[1]) + x[2]-x[0] + x[1]-x[0])
else:
    l = [[x[i+j] - x[i] for i in range(N-j)] + [0]*(j-1) for j in range(1, N)]

    move = [0, 0, 0, 0, np.array([[2, 2, 5], [1, 3, 0], [2, 0, 0]])]
    move += [np.array([[1]*(i-1)] + [[0] * (i-1) for _ in range(2, i)]) for i in range(5, N+1)]
    
    for i in range(5, N+1):
        for j in range(i-1):
            nmove = np.insert(np.insert(move[i-1], i-2, 0, axis=0).T, j, 0, axis=0)
            for k in range(j):
                a = copy.copy(nmove[k])
                a = np.insert(a, j-k, 0)
                nmove[k] = np.delete(a, i-1, 0)
            move[i] += nmove.T
    
    print(np.sum(l*move[N]) % 1000000007)

Submission status: Wrong Answer

Solution code:
import math
import itertools

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

mod=(10 ** 9)+7

t=[math.factorial(N-i) for i in range(2,N)]

t=list(itertools.accumulate(t))
t.append(math.factorial(N-1))
t.reverse()
T=list(itertools.accumulate(t))

C=[(x[j]-x[j-1])*T[j-1] for j in range(1,N) ]

print(sum(C)%mod)

Submission status: Wrong Answer

Solution code:
import math
import itertools

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

C=0
t=[math.factorial(N-i) for i in range(2,N)]

t=list(itertools.accumulate(t))
t.append(math.factorial(N-1))
t.reverse()
T=list(itertools.accumulate(t))

C=[(x[j]-x[j-1])*T[j-1] for j in range(1,N) ]

print(sum(C)%((10 ** 9)+7))

Submission status: Wrong Answer

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

ans *= math.factorial(N-1)%mod
print(int(ans)%mod)

Submission status: Wrong Answer

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

ans *= math.factorial(N-1)%mod
print(int(ans%mod))

Submission status: Wrong Answer

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


def main():
    N = int(input())
    X = list(map(int, input().split()))
    D = [0 for i in range(N)]

    for i in range(N-1):
        D[i] = abs(X[i] - X[i+1])

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

    ans = 0
    r = 0
    for i in range(1, N):
        r += n // i
        x = D[i-1] * r
        ans += x
        ans %= 10**9+7
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
x = list(map(int,input().split()))
ans = 0
tmp = 0

frac = 1
for i in range(N-1):
    frac *= i+1
    frac = frac % 1000000007
for i in range(N-1):
    ans += (x[N-1] - x[i])/(i+1) * frac
    if ans > 1000000007:
        ans = ans % 1000000007
print(int(ans))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
x = list(map(int,input().split()))
ans = 0
tmp = 0

frac = 1
for i in range(N-1):
    frac *= i+1
    frac = frac % 1000000007
for i in range(N-1):
    ans += (x[N-1] - x[i])/(i+1) * frac

print(int(ans % 1000000007))

Submission status: Wrong Answer

Solution code:
N = int(input())
x = list(map(int,input().split()))
xx = [x[-i]-x[-i-1] for i in range(1, N)]
xxx = [[] for i in range(N-1)]
xxx[0].append(xx[0])
for i in range(1, N-1):
    for l in range(i):
        xxx[i].append(xxx[i-1][l]+xx[i])
    xxx[i].append(xx[i])
for i in range(N-1):
    xxx[i].reverse()
MOD = 10**9+7
p = 1
for i in range(1, N):
    p *= i
    p %= MOD
S = [[1]]
ans = 0
for i in range(3, N+1):
    t = []
    for l in range(i-3):
        t.append(S[i-3][l])
    t.append(S[i-3][-1]/(i-1))
    t.append(1/(i-1))
    for l in range(i-1):
        ans += xxx[i-2][l]*t[l]
    ans %= MOD
    S.append(t)
ans += xx[0]
print(int((ans*p)%MOD))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
x = list(map(int,input().split()))
ans = 0
tmp = 0

frac = 1
for i in range(N-1):
    frac *= i+1
    frac = frac % 1000000007
for i in range(N-1):
    ans += (x[N-1] - x[i])/(i+1)
    if ans > 1000000007:
        ans = ans % 1000000007

print(int(ans*frac))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
x = list(map(int,input().split()))
ans = 0
tmp = 0

frac = 1
for i in range(N):
    frac *= i
    frac = frac % 1000000007
for i in range(N-1):
    ans += (x[N-1] - x[i])/(i+1)
    if ans > 1000000007:
        ans = ans % 1000000007

print(ans*frac)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = list(map(int,input().split()))
xx = [x[-i]-x[-i-1] for i in range(1, N)]
xxx = [[] for i in range(N-1)]
xxx[0].append(xx[0])
for i in range(1, N-1):
    for l in range(i):
        xxx[i].append(xxx[i-1][l]+xx[i])
    xxx[i].append(xx[i])
for i in range(N-1):
    xxx[i].reverse()
MOD = 10**9+7
p = 1
for i in range(1, N):
    p *= i
    p = p%MOD
S = [[1]]
ans = 0
for i in range(3, N+1):
    t = []
    for l in range(i-3):
        t.append(S[i-3][l])
    t.append(S[i-3][-1]/(i-1))
    t.append(1/(i-1))
    for l in range(i-1):
        ans += xxx[i-2][l]*t[l]
    S.append(t)
ans += xx[0]
print(int((ans*p)%MOD))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
x = list(map(int,input().split()))
ans = 0
tmp = 0

frac = 1
for i in range(N):
    frac *= N
    frac = frac % 1000000007
for i in range(N-1):
    ans += (x[N-1] - x[i])/(i+1)*frac
    if ans > 1000000007:
        ans = ans % 1000000007

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = list(map(int,input().split()))
xx = [x[-i]-x[-i-1] for i in range(1, N)]
xxx = [[] for i in range(N-1)]
xxx[0].append(xx[0])
for i in range(1, N-1):
    for l in range(i):
        xxx[i].append(xxx[i-1][l]+xx[i])
    xxx[i].append(xx[i])
for i in range(N-1):
    xxx[i].reverse()
MOD = 10**9+7
p = 1
for i in range(1, N):
    p *= i
    p = p%MOD
S = [[1]]
ans = 0
for i in range(3, N+1):
    t = []
    for l in range(i-3):
        t.append(S[i-3][l])
    t.append(S[i-3][-1]/(i-1))
    t.append(1/(i-1))
    for l in range(i-1):
        ans += xxx[i-2][l]*t[l]
    ans = ans
    S.append(t)
ans += xx[0]
print(int((ans*p)%MOD))

Submission status: Wrong Answer

Solution code:
MOD = 10**9+7

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

F = [0 for _ in range(N+1)]
F[0] = 1

for i in range(1,N+1):
    F[i] = (F[i-1]*i)%MOD

ans = 0
tmp = 0

for i in range(N-1):
    ans += (tmp*(N-1-i)+(X[-1]-X[i])*F[i])*F[N-2-i]
    ans %= MOD
    tmp = tmp*(N-1-i)+(X[-1]-X[i])*F[i+1]
    tmp %= MOD

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = list(map(int,input().split()))
xx = [x[-i]-x[-i-1] for i in range(1, N)]
xxx = [[] for i in range(N-1)]
xxx[0].append(xx[0])
for i in range(1, N-1):
    for l in range(i):
        xxx[i].append(xxx[i-1][l]+xx[i])
    xxx[i].append(xx[i])
for i in range(N-1):
    xxx[i].reverse()
MOD = 10**9+7
p = 1
for i in range(1, N):
    p *= i
    p = p%MOD
S = [[1]]
ans = 0
for i in range(3, N+1):
    t = []
    for l in range(i-3):
        t.append(S[i-3][l])
    t.append(S[i-3][-1]/(i-1))
    t.append(1/(i-1))
    for l in range(i-1):
        ans += xxx[i-2][l]*t[l]*p
    ans = ans
    S.append(t)
ans += xx[0]*p
print(int(ans%MOD))

Submission status: Wrong Answer

Solution code:
N = int(input())
x = list(map(int,input().split()))
xx = [x[-i]-x[-i-1] for i in range(1, N)]
xxx = [[] for i in range(N-1)]
xxx[0].append(xx[0])
for i in range(1, N-1):
    for l in range(i):
        xxx[i].append(xxx[i-1][l]+xx[i])
    xxx[i].append(xx[i])
for i in range(N-1):
    xxx[i].reverse()
MOD = 10**9+7
p = 1
for i in range(1, N):
    p *= i
    p = p%MOD
S = [[1]]
ans = 0
for i in range(3, N+1):
    t = []
    for l in range(i-3):
        t.append(S[i-3][l])
    t.append(S[i-3][-1]/(i-1))
    t.append(1/(i-1))
    for l in range(i-1):
        ans += (xxx[i-2][l]*t[l]*p)%MOD
    ans = ans%MOD
    S.append(t)
ans += (xx[0]*p)%MOD
print(int(ans%MOD))

Submission status: Wrong Answer

Solution code:
import math
import itertools

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

C=0
t=[math.factorial(N-i) for i in range(1,N)]
T=list(itertools.accumulate(t))

for j in range(1,N):
    C=C+(x[j]-x[j-1])*T[j-1]

print(C%((10 ** 9)+7))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)


def mod_inverse(n, mod=10**9+7):
    return pow(n, mod-2, mod)


def combination(n, k, mod=10**9+7):
    numer = denom = 1
    for i in range(k):
        numer = (numer * (n-i)) % mod
        denom = (denom * (i+1)) % mod
    return (numer * mod_inverse(denom, mod)) % mod


def factorial(n):
    if n == 0:
        return 1
    return n * factorial(n-1) % mod


mod = 10**9+7
N = int(input())
x = [0] + list(map(int, input().split()))

ans = 0
for k in range(2, N):
    ans = (ans + x[k] * (1 - mod_inverse(k))) % mod

for k in range(1, N-1):
    ans = (ans - x[k] * (1 - mod_inverse(N-k))) % mod

ans = (ans + sum((x[N] - x[k]) * mod_inverse(N-k) for k in range(1, N))) % mod

ans = ans * factorial(N-1) * mod

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
sa = []
for i in range(n-1):
    sa.append(l[i+1]-l[i])

mod = 10**9+7
ans = 0
count = 0
kai = 1

    
for i in range(n-1):
    count += 1/(i+1)
    
    
    ans += sa[i]*count
    ans %= mod
for i in range(n-1):
    ans *= (i+1)
    ans %= mod

print(int(ans%mod))

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
from collections import deque
import numpy as np
import heapq
from heapq import heappop, heappush
import math

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

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

fact = 1

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

t = 0
f = 0

for i in range(N-1):
    f += fact // (i+1)
    x = X[i+1] - X[i]
    t += x * f
    t %= 10 ** 9 + 7

print(t % (10 ** 9 + 7))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
x = list(map(int, input().split()))
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)
res = 0
t = [0] * (N + 1)
for i in range(N):
  t[i + 1] = t[i] * (i + 1) + f.factorial(i) % mod
  t[i + 1] %= mod
print(t)
for i in range(N - 2, -1, -1):
  res += (x[i + 1] - x[i]) * t[i + 1] * f.factorial(N - 1) % mod * f.ifactorial(i + 1) % mod
  res %= mod
print(res)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
x = list(map(int, input().split()))
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)
res = 0
t = [0] * (N + 1)
for i in range(N):
  t[i + 1] = t[i] * (i + 1) + f.factorial(i) % mod
print(t)
for i in range(N - 2, -1, -1):
  res += (x[i + 1] - x[i]) * t[i + 1] * f.factorial(N - 1) % mod * f.ifactorial(i + 1) % mod
  res %= mod
print(res)

Submission status: Wrong Answer

Solution code:
MOD=10**9+7
n=int(input())
li=list(map(int,input().split()))
dist=[]
for i in range(n-1):
  dist.append(li[i+1]-li[i])  
  

fact=[-1]*(10**5+10)
fact[0]=1
for i in range(1,10**5+10):
  fact[i]=fact[i-1]*i%MOD


f=fact[(n-1)]
sum=0.0
ss=0
for i in range(1,n-1+1):
  ss+=f/i
  sum+=ss*dist[i-1]%MOD
ans=int(sum%MOD)
print(ans)

Submission status: Wrong Answer

Solution code:
# import numpy as np
# import math
import sys
input = sys.stdin.readline


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

    mod = 10 ** 9 + 7

    res = 0
    frac = 1
    sum = 0

    for i in range(N-1):
        diff = x[i+1] - x[i]
        sum += 1 / (i+1)
        frac *= i + 1
        frac %= mod
        res += diff * sum
        res %= mod

    res *= frac
    res %= mod
    res = int(res)

    print(res)



main()

Submission status: Wrong Answer

Solution code:
N = int(input())
x = list(map(int,input().split()))
xx = [x[-i]-x[-i-1] for i in range(1, N)]
xxx = [[] for i in range(N-1)]
xxx[0].append(xx[0])
for i in range(1, N-1):
    for l in range(i):
        xxx[i].append(xxx[i-1][l]+xx[i])
    xxx[i].append(xx[i])
for i in range(N-1):
    xxx[i].reverse()
MOD = 10**9+7
p = 1
for i in range(1, N):
    p *= i
    p = p%MOD
S = [[1]]
ans = 0
for i in range(3, N+1):
    t = []
    for l in range(i-3):
        t.append(S[i-3][l])
    t.append(S[i-3][-1]/(i-1))
    t.append(1/(i-1))
    for l in range(i-1):
        ans += (xxx[i-2][l-1]*t[l]*p)%MOD
    ans = ans%MOD
    S.append(t)
ans += (xx[0]*p)%MOD
print(int(ans%MOD))

Submission status: Wrong Answer

Solution code:
import scipy.special
import itertools
N = int(input())
x = list(map(int,input().split()))
xx = [x[-i]-x[-i-1] for i in range(1, N)]
xxx = [[] for i in range(N-1)]
xxx[0].append(xx[0])
for i in range(1, N-1):
    for l in range(i):
        xxx[i].append(xxx[i-1][l]+xx[i])
    xxx[i].append(xx[i])
for i in range(N-1):
    xxx[i].reverse()
MOD = 10**9+7
p = 1
for i in range(1, N):
    p *= i
    p = p%MOD
S = [[1]]
ans = 0
for i in range(3, N+1):
    t = []
    for l in range(i-3):
        t.append(S[i-3][l])
    t.append(S[i-3][-1]/(i-1))
    t.append(1/(i-1))
    for l in range(i-1):
        ans += (xxx[i-2][l-1]*t[l]*p)%MOD
    ans = ans%MOD
    S.append(t)
ans += (xx[0]*p)%MOD
print(int(ans%MOD))

Submission status: Wrong Answer

Solution code:
import math

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

MOD = 10 ** 9 + 7
factorial = math.factorial(n - 1) % MOD

diffList = [0] * (n - 1)
for i, position in enumerate(positionList):
  if i == 0:
    continue
  diffList[i - 1] = position - positionList[i - 1]

weightList = [0] * (n - 1)
for i in range(n - 1):
  for j in range(n - i - 1):
    weightList[i + j] += factorial // (i + 1)

result = 0
for i in range(n - 1):
  result = (result + diffList[i] * weightList[i]) % MOD
print(result)

Submission status: Wrong Answer

Solution code:
import numpy as np
# import math
import sys
readline = sys.stdin.buffer.readline
MOD = 10**9+7

def factorial(n, MOD):
    res = 1
    for i in range(n):
        res *= i+1
        res %= MOD
    return res

N = int(readline())
x = np.array(readline().split(), dtype=np.int64)
# print(N, x)

dif = x[1:] - x[:N-1]
# print(dif)

cnt = np.zeros(N-1, dtype=np.int64)
# sm = math.factorial(N-1)
sm = factorial(N-1, MOD)
for i in range(N-1):
    if i == 0:
        cnt[i] = sm
        tmp = sm
    else:
        # tmp = tmp * i // (i+1)
        tmp = sm // (i+1)
        cnt[i] = cnt[i-1] + tmp
# print(cnt)

sums = np.mod((dif * cnt), MOD)
# print(sms)
ans = 0
for i in range(N-1):
    ans += sums[i]
    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()))
dis = [x[i]-x[i-1] for i in range(1,n)]


f = math.factorial(n-1)
f %= mod

def modinv(a, mod=mod):
    return pow(a, mod-2, mod)
inv2 = modinv(2)

count = 0
for i in range(1,n):
    e = (i+1)*inv2%mod
    count = (count + e*dis[i-1])%mod
count = count*f%mod

print(int(count)%mod)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
X=[int(i) for i in input().split()]
mod=10**9+7
n_max=n
if n >2000:
  sys.exit()
n_max=2*10**5
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
  FI[i+1]=pow(F[i+1],mod-2,mod)


ans=0
DP=[0]*n
DP[0]=1
DP[1]=1
ans=(ans+DP[1]*(X[1]-X[0])*F[n-1]*FI[0])%mod
for i in range(2,n):
  DP[i]=(F[i-1]+DP[i-1]*i)%mod
  ans=(ans+DP[i]*(X[i]-X[i-1])*F[n-1]*FI[i])%mod
print(ans)

Submission status: Wrong Answer

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

N = 1e+9 + 7

tmp = 1
l = []
ln = []
for i in range(n-1):
    tmp *= (i+1)%N
    tmp = tmp % N
    l.append(tmp)
for k in range(n-1):
    ln.append(int(tmp/(k+1))%N)

a = 0
b = 1

for i in range(n-1):
    b *= (i+1)%N
    a += ((ln[i]%N) * (x[-1]-x[i]))%N

b *= n
print(int(a%N))