Read problems statements in Mandarin Chinese  and Russian. 

For positive integer x let define function F(x) = 1 * (1! + x) + 2 * (2! + x) + .. + x * (x! + x). 
"k!" means factorial: k! = 1 * 2 * .. * k 

Chef wants to calculate F(p_{1}) + F(p_{2}) + ... + F(p_{n}). 
As answer could be large, help him, calculate value modulo m. 

------ Input ------ 

First line contains two integers n and m.
Next line contains n space separated integers p_{i}.

------ Output ------ 

Output a single line containing one integer --- calculated value modulo m.

------ Constraints ------ 

$1 ≤ n_{} ≤  10^{5}$
$1 ≤ p_{i} ≤  10^{18}$
$1 ≤ m ≤  10^{7}$

------  Subtasks  ------ 

$Subtask #1: 1 ≤ p_{i} ≤  6  (10 points)$
$Subtask #2: 1 ≤ p_{i} ≤  7 * 10^{3} (25 points)$
$Subtask #3: m_{}^{} - prime number (25 points)$
$Subtask #4: _{}^{}original constraints (40 points)$

----- Sample Input 1 ------ 
5 7
1 2 3 4 5
----- Sample Output 1 ------ 
6
----- explanation 1 ------ 
F(1) = 1 * (1! + 1) = 2
F(2) = 1 * (1! + 2) + 2 * (2! + 2) = 3 + 8 = 11
F(3) = 1 * (1! + 3) + 2 * (2! + 3) + 3 * (3! + 3) = 4 + 10 + 27 = 41
F(4) = 1 * (1! + 4) + 2 * (2! + 4) + 3 * (3! + 4) + 4 * (4! + 4) = 5 + 12 + 30 + 112 = 159
F(5) = 1 * (1! + 5) + 2 * (2! + 5) + 3 * (3! + 5) + 4 * (4! + 5) + 5 * (5! + 5) = 794
F(1) + F(2) + F(3) + F(4) + F(5) = 2 + 11 + 41 + 159 + 794 = 1007 

1007 modulo 7 = 6

Difficulty: MEDIUM_HARD

Solutions:
(n, m) = input().split()
n = int(n)
m = int(m)
a = []
s = 0
a = input().split()
for i in range(len(a)):
	a[i] = int(a[i])
a.sort()
f = a[len(a) - 1]
i = len(a) - 1
while i > 0:
	if a[i] > m:
		f = a[i - 1]
	else:
		break
	i = i - 1
if a[0] >= m:
	f = 0
j = max(a)
g = []
g.append(1)
g.append(1)
if j + 2 < m:
	d = j + 2
else:
	d = f + 2
r = 0
for i in range(2, d):
	if g[i - 1] * i % m != 0:
		g.append(g[i - 1] * i % m)
	else:
		break
for i in range(len(a)):
	p = a[i]
	if p + 1 < len(g):
		s = s + (g[p + 1] + p * p * (p + 1) // 2 % m - 1)
	else:
		s = s + (p * p * (p + 1) // 2 % m - 1)
print(s % m)


def cal(x, m):
	if x < m:
		return (factorials[x + 1] - 1 + x * x * (x + 1) // 2) % m
	return (x * x * (x + 1) // 2 - 1) % m

def solve(arr, n, m):
	return sum([cal(x, m) for x in arr]) % m
(n, m) = map(int, input().split())
factorials = [1 for i in range(10 ** 7 + 1)]
for i in range(2, 100001):
	factorials[i] = i * factorials[i - 1] % m
arr = list(map(int, input().split()))
print(solve(arr, n, m))


from math import *

def f1(x):
	ans = 0
	for k in range(1, x + 1):
		ans += k * (factorial(k) + x)
	return ans

def f2(x):
	return factorial(x + 1) - 1 + x * x * (x + 1) // 2

def test():
	for x in range(1, 21):
		print(x, f1(x), f2(x))

def main():
	(n, m) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	facts = [1, 1]
	for i in range(2, 10 ** 7 + 10):
		facts.append(facts[-1] * i % m)
		if facts[-1] == 0:
			break
	ans = 0
	for n in a:
		if n + 1 <= len(facts) - 1:
			ans = ans + facts[n + 1]
		ans += m - 1
		tmp = n * n * (n + 1) // 2
		ans += tmp
		ans %= m
	print(ans)
main()


(n, m) = map(int, input().split())
F = [1]
for i in range(1, 10000005):
	F.append(i * F[i - 1] % m)
L = list(map(int, input().split()))
ans = 0
for item in L:
	tmp = item * (item + 1) // 2
	tmp %= m
	tmp *= item
	tmp %= m
	if item < m:
		tmp += (F[item + 1] + m - 1) % m
	else:
		tmp += m - 1
	tmp %= m
	ans += tmp
	ans %= m
print(ans)