Buggy python submission (verdict: Runtime Error):
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 ) 

Fixed submission:
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 pow(x, y):
    if y == 0:
        return 1
    ans = 1
    while y > 1:
        if y % 2 != 0:
            ans *= x
            ans %= 1000000007
        x *= x
        x %= 1000000007
        y //= 2
    return ans * x % 1000000007

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 * pow(i + 1, 1000000005)) % 1000000007

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

Buggy python submission (verdict: Time Limit Exceeded):
import math

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 = math.factorial(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 ) 

Fixed submission:
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 pow(x, y):
    if y == 0:
        return 1
    ans = 1
    while y > 1:
        if y % 2 != 0:
            ans *= x
            ans %= 1000000007
        x *= x
        x %= 1000000007
        y //= 2
    return ans * x % 1000000007

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 * pow(i + 1, 1000000005)) % 1000000007

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

Buggy python submission (verdict: Time Limit Exceeded):
import math

n = int(input())
x = list(map(int, input().split()))
d = [x[i+1] - x[i] for i in range(n - 1)]
 
fact_n_1 = math.factorial(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 ) 

Fixed submission:
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 pow(x, y):
    if y == 0:
        return 1
    ans = 1
    while y > 1:
        if y % 2 != 0:
            ans *= x
            ans %= 1000000007
        x *= x
        x %= 1000000007
        y //= 2
    return ans * x % 1000000007

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 * pow(i + 1, 1000000005)) % 1000000007

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

Buggy python submission (verdict: Time Limit Exceeded):
import math

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

e = {}
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 
          in enumerate(d)) % 1000000007 ) 

Fixed submission:
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 pow(x, y):
    if y == 0:
        return 1
    ans = 1
    while y > 1:
        if y % 2 != 0:
            ans *= x
            ans %= 1000000007
        x *= x
        x %= 1000000007
        y //= 2
    return ans * x % 1000000007

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 * pow(i + 1, 1000000005)) % 1000000007

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

Buggy python submission (verdict: Time Limit Exceeded):
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) if m != 1 else 1 

fact_n_1 = fact(n-1)

e = {}
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 
          in enumerate(d)) % 1000000007 ) 

Fixed submission:
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 pow(x, y):
    if y == 0:
        return 1
    ans = 1
    while y > 1:
        if y % 2 != 0:
            ans *= x
            ans %= 1000000007
        x *= x
        x %= 1000000007
        y //= 2
    return ans * x % 1000000007

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 * pow(i + 1, 1000000005)) % 1000000007

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

Buggy python submission (verdict: Runtime Error):
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) if m != 1 else 1 

fact_n_1 = fact(n-1)

e = {}
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 
          in enumerate(d)) % 1000000007 ) 

Fixed submission:
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 pow(x, y):
    if y == 0:
        return 1
    ans = 1
    while y > 1:
        if y % 2 != 0:
            ans *= x
            ans %= 1000000007
        x *= x
        x %= 1000000007
        y //= 2
    return ans * x % 1000000007

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 * pow(i + 1, 1000000005)) % 1000000007

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

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)

n = int(input())
x = list(map(int, input().split()))
 
def fact(m):
  return m * fact(m-1) if m != 1 else 1
 
d = [x[i+1] - x[i] for i in range(n - 1)]
fact_n_1 = fact(n-1)
print(sum(sum(fact_n_1 // (j + 1) 
              for j 
              in range(i + 1)) * d_i % 1000000007
          for i, d_i 
          in enumerate(d)) % 1000000007 ) 

Fixed submission:
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 pow(x, y):
    if y == 0:
        return 1
    ans = 1
    while y > 1:
        if y % 2 != 0:
            ans *= x
            ans %= 1000000007
        x *= x
        x %= 1000000007
        y //= 2
    return ans * x % 1000000007

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 * pow(i + 1, 1000000005)) % 1000000007

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

Buggy python submission (verdict: Runtime Error):
n = int(input())
x = list(map(int, input().split()))

def fact(m):
  return m * fact(m-1) if m != 1 else 1

d = [x[i+1] - x[i] for i in range(n - 1)]
fact_n_1 = fact(n-1)
print(sum(sum(fact_n_1 // (j + 1) 
              for j 
              in range(i + 1)) * d_i % 1000000007
          for i, d_i 
          in enumerate(d)) % 1000000007 ) 

Fixed submission:
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 pow(x, y):
    if y == 0:
        return 1
    ans = 1
    while y > 1:
        if y % 2 != 0:
            ans *= x
            ans %= 1000000007
        x *= x
        x %= 1000000007
        y //= 2
    return ans * x % 1000000007

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 * pow(i + 1, 1000000005)) % 1000000007

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