Recall that the permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array) and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array).

A sequence $a$ is a subsegment of a sequence $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. We will denote the subsegments as $[l, r]$, where $l, r$ are two integers with $1 \le l \le r \le n$. This indicates the subsegment where $l-1$ elements from the beginning and $n-r$ elements from the end are deleted from the sequence.

For a permutation $p_1, p_2, \ldots, p_n$, we define a framed segment as a subsegment $[l,r]$ where $\max\{p_l, p_{l+1}, \dots, p_r\} - \min\{p_l, p_{l+1}, \dots, p_r\} = r - l$. For example, for the permutation $(6, 7, 1, 8, 5, 3, 2, 4)$ some of its framed segments are: $[1, 2], [5, 8], [6, 7], [3, 3], [8, 8]$. In particular, a subsegment $[i,i]$ is always a framed segments for any $i$ between $1$ and $n$, inclusive.

We define the happiness of a permutation $p$ as the number of pairs $(l, r)$ such that $1 \le l \le r \le n$, and $[l, r]$ is a framed segment. For example, the permutation $[3, 1, 2]$ has happiness $5$: all segments except $[1, 2]$ are framed segments.

Given integers $n$ and $m$, Jongwon wants to compute the sum of happiness for all permutations of length $n$, modulo the prime number $m$. Note that there exist $n!$ (factorial of $n$) different permutations of length $n$.


-----Input-----

The only line contains two integers $n$ and $m$ ($1 \le n \le 250\,000$, $10^8 \le m \le 10^9$, $m$ is prime).


-----Output-----

Print $r$ ($0 \le r < m$), the sum of happiness for all permutations of length $n$, modulo a prime number $m$.


-----Examples-----
Input
1 993244853

Output
1

Input
2 993244853

Output
6

Input
3 993244853

Output
32

Input
2019 993244853

Output
923958830

Input
2020 437122297

Output
265955509



-----Note-----

For sample input $n=3$, let's consider all permutations of length $3$:  $[1, 2, 3]$, all subsegments are framed segment. Happiness is $6$.  $[1, 3, 2]$, all subsegments except $[1, 2]$ are framed segment. Happiness is $5$.  $[2, 1, 3]$, all subsegments except $[2, 3]$ are framed segment. Happiness is $5$.  $[2, 3, 1]$, all subsegments except $[2, 3]$ are framed segment. Happiness is $5$.  $[3, 1, 2]$, all subsegments except $[1, 2]$ are framed segment. Happiness is $5$.  $[3, 2, 1]$, all subsegments are framed segment. Happiness is $6$. 

Thus, the sum of happiness is $6+5+5+5+5+6 = 32$.

Difficulty: MEDIUM_HARD

Solutions:
(n, m) = map(int, input().split())
fac = [1]
for i in range(1, n + 1):
	fac.append(i * fac[i - 1] % m)
ans = 0
for i in range(1, n + 1):
	ans += (n - i + 1) * fac[i] * fac[n - i + 1]
	ans %= m
print(ans)


from array import array
from sys import stdin
import bisect
from itertools import *

def scan_gen():
	for line in stdin:
		yield from iter(line.split())
scan = scan_gen()

def nint():
	return int(next(scan))

def nintk(k):
	return tuple((nint() for _ in range(k)))

def nfloat():
	return float(next(scan))

def intar_init(size):
	return array('i', [0]) * size

def intar(size=None):
	if size == None:
		size = nint()
	arr = intar_init(size)
	for x in range(size):
		arr[x] = nint()
	return arr

def count(s):
	r = 0
	for a in range(len(s)):
		for b in range(a + 1, len(s) + 1):
			if max(s[a:b]) - min(s[a:b]) == b - a - 1:
				r += 1
	return r
fact = [1, 1]
mod = 0

def doit(n):
	res = 0
	for ln in range(1, n + 1):
		counts = n - ln + 1
		starts = n - ln + 1
		res = (res + counts * starts * fact[ln] * fact[n - ln]) % mod
	return res

def solve():
	global mod
	(n, mod) = nintk(2)
	for i in range(2, 300000):
		fact.append(fact[-1] * i % mod)
	print(doit(n))
solve()


(n, m) = map(int, input().split())
factorial = [1] * (n + 1)
for i in range(1, n + 1):
	factorial[i] = factorial[i - 1] * i % m
ans = 0
for i in range(1, n + 1):
	ans = (ans + i * factorial[i] * factorial[n - i + 1]) % m
print(ans)


(n, m) = map(int, input().split())
f = [1]
for i in range(1, n + 1):
	f.append(f[-1] * i % m)
s = 0
for x in range(1, n + 1):
	s += f[x] * f[n - x] % m * ((n - x + 1) ** 2 % m) % m
	s %= m
print(s)


(n, mod) = list(map(int, input().split()))
f = [1]
for i in range(1, n + 1):
	f.append(f[-1] * i % mod)
res = 0
for i in range(1, n + 1):
	res += f[i] * f[n - i + 1] * (n - i + 1) % mod
	res %= mod
print(res)


import sys
import math
from collections import defaultdict, Counter
from itertools import permutations
(n, m) = map(int, input().split())
ans = 0
fact = [1] * (n + 1)
for i in range(2, n + 1):
	fact[i] = fact[i - 1] * i % m
for i in range(1, n + 1):
	cur = pow(n - i + 1, 2, m) * fact[i] % m
	cur = cur * fact[n - i] % m
	ans = (ans + cur) % m
print(ans)


def R():
	return map(int, input().split())

def I():
	return int(input())

def S():
	return str(input())
from collections import Counter
import math
import sys
f = open('test.txt', 'w')
(n, m) = R()
fact = [1] * (n + 1)
for i in range(1, n + 1):
	fact[i] = fact[i - 1] * i
	fact[i] %= m
sum = 0
for i in range(1, n + 1):
	sum = (sum + fact[n - i + 1] * fact[i] * (n - i + 1)) % m
print(sum % m)


(n, m) = map(int, input().split())
F = []
f = 1
res = 0
for i in range(1, n + 1):
	f *= i
	f %= m
	F.append(f)
for i in range(n // 2):
	res += F[i] * F[len(F) - i - 1] * (n + 1)
	res %= m
if n % 2 == 1:
	res += F[n // 2] ** 2 * (n // 2 + 1)
	res %= m
print(res)


import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import factorial
(n, m) = [int(item) for item in input().split()]
fac = [0] * (n + 1)
fac[0] = 1
fac[1] = 1
for i in range(2, n + 1):
	fac[i] = fac[i - 1] * i % m
ans = 0
for i in range(1, n + 1):
	val = fac[n - i + 1] * (n - i + 1) * fac[i]
	ans += val
	ans %= m
print(ans)


a = []
a.append(1)
a.append(1)
(n, m) = map(int, input().split())
for i in range(2, 250001):
	a.append(a[i - 1] * i % m)
ans = 0
for i in range(1, n + 1):
	ans += (n - i + 1) * a[i] * a[n - i + 1]
	ans %= m
print(ans)


(n, m) = map(int, input().split())
fc = [1]
for i in range(1, n + 1):
	fc.append(fc[i - 1] * i % m)
s = 0
s = fc[n] * n
for d in range(1, n):
	s += (n - d) * fc[d + 1] * fc[n - d] % m
s = s % m
print(s)


(n, m) = map(int, input().split())
l = [0] * (n + 1)
c = 1
for i in range(1, n + 1):
	l[i] = i * c % m
	c = l[i]
ans = 0
for i in range(n):
	ans += (n - i) % m * (l[n - i] % m) * (l[i + 1] % m) % m
print(ans % m)


(n, m) = map(int, input().split())
f = [1 for i in range(n)]
for i in range(1, len(f)):
	f[i] = f[i - 1] * (i + 1) % m

def s(b, m):
	global c
	c += b
	if c >= m:
		c -= m
c = 0
for i in range(1, n + 1):
	s(f[i - 1] * f[n - i] * (n - i + 1) % m, m)
print(c)


fuck = [int(1)]
(n, m) = map(int, input().split())
for i in range(1, n + 1):
	now = fuck[i - 1] * i
	fuck.append((now + m) % m)
ans = 0
for i in range(n):
	l = 1
	r = l + i
	x = i + 1
	now = max(n - r + 1, l) * max(n - r + 1, l) * fuck[n - x] * fuck[x]
	now = (now + m) % m
	ans = (ans + now + m) % m
print(ans)


(N, M) = map(int, input().split())
T = 0
F = []
f = 1
for k in range(1, N + 1):
	f *= k
	f %= M
	F.append(f)
for i in range(N // 2):
	T += F[i] * F[len(F) - i - 1] * (N + 1)
	T %= M
if N % 2 == 1:
	T += F[N // 2 + N % 2 - 1] ** 2 * (N // 2 + N % 2)
	T %= M
print(T)


(n, m) = map(int, input().split())
a = [1]
for q in range(2, n + 1):
	a.append(a[-1] * q % m)
a.reverse()
ans = 0
for q in range(n):
	ans += a[q] * a[n - q - 1] * (n - q) % m
print(ans % m)


(n, m) = map(int, input().split())
facts = [1]
fact = 1
for n1 in range(1, n + 1):
	fact = fact * n1 % m
	facts.append(fact)
ans = 0
for n1 in range(1, n + 1):
	ans = (ans + facts[n1] * facts[n - n1] % m * pow(n + 1 - n1, 2, m) % m) % m
print(ans)


(n, mod) = input().split()
(n, mod) = (int(n), int(mod))
ans = 0
fact = [1 for i in range(n + 2)]
for i in range(1, n + 1):
	fact[i] = i * fact[i - 1] % mod
for i in range(1, n + 1):
	cnt = n - i + 1
	ans = (ans + fact[i] * fact[n - i] * cnt * cnt) % mod
print(ans)


(n, m) = list(map(int, input().split()))
fact = [1]
for i in range(1, n + 1):
	fact.append(fact[-1] * i % m)
out = 0
for size in range(1, n + 1):
	out += fact[size] * (n - size + 1) ** 2 * fact[n - size]
	out %= m
print(out)


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

def fac(c):
	ans = 1
	for i in range(1, c + 1):
		ans *= i
		ans %= mod
	return max(ans, 1)

def dev(a, b):
	return a * pow(b, mod - 2, mod) % mod

def mult(a, b):
	return a * b % mod
ans = 0
facs = [0] * 251000
m = 1
facs[0] = 1
for i in range(1, len(facs)):
	m *= i
	m %= mod
	facs[i] = m
for i in range(1, n + 1):
	ans += mult(n - i + 1, mult(n - i + 1, mult(facs[i], facs[n - i])))
	ans %= mod
print(ans)


(n, m) = map(int, input().split())
ls = [1]
fact = 1
for i in range(1, n + 1):
	fact *= i
	fact %= m
	ls.append(fact)
ans = 0
for i in range(1, n + 1):
	ans += ls[i] * ls[n - i + 1] * i
	ans %= m
print(ans)


(n, mod) = list(map(int, input().split()))
factorial = [0 for _ in range(0, 250001)]
factorial[1] = 1
factorial[0] = 1

def fact_mod(n, mod):
	ans = 1
	for i in range(2, n + 1):
		ans = ans * i % mod
		factorial[i] = ans
	return ans
fact_mod(250000, mod)
ans = 0
for i in range(0, n):
	ans = (ans + (n - i) * ((n - i) * factorial[n - i - 1] % mod) % mod * factorial[i + 1] % mod) % mod
print(ans)


(n, p) = map(int, input().split())
fact = [1] * 250005
for i in range(2, 250001):
	fact[i] = fact[i - 1] * i % p
ans = 0
for k in range(1, n + 1):
	m = n + 1 - k
	ans = (ans + m * m * fact[k] % p * fact[n - k]) % p
print(ans)


def num():
	return int(input())

def line():
	return map(int, input().split())
from itertools import repeat, islice
(n, m) = line()
facts = [1]
for i in range(1, n + 1):
	facts.append(facts[-1] * i % m)
print(sum((facts[i] * facts[n - i] * (n - i + 1) ** 2 % m for i in range(1, n + 1))) % m)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop

def fac(m):
	dp = [0] * 250001
	dp[1] = 1
	dp[0] = 1
	for i in range(2, len(dp)):
		dp[i] = dp[i - 1] % m * i % m
		dp[i] %= m
	return dp
(n, m) = map(int, input().split())
dp = fac(m)
ans = 0
for i in range(1, n + 1):
	z = n - i + 1
	ans += z % m * dp[i] % m * dp[n - i + 1] % m
	ans %= m
print(ans)


import sys, math
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
t = 1
for tt in range(t):
	(n, m) = invr()
	q = [1]
	for i in range(n):
		q.append(q[-1] * (i + 1) % m)
	w = 0
	for i in range(n):
		w = w + (n - i) * q[i + 1] * q[n - i] % m
		w = w % m
	print(w)


(n, MOD) = map(int, input().split())
fact = [1]
for i in range(1, n + 1):
	fact.append(fact[-1] * i % MOD)
ans = 0
for i in range(1, n + 1):
	ans += (n - i + 1) ** 2 * fact[i] * fact[n - i]
	ans %= MOD
print(ans)


(n, m) = [int(x) for x in input().split()]
MOD = m
MAX = n
fact = [1]
for zz in range(1, MAX + 1):
	fact.append(fact[-1] % MOD * zz % MOD % MOD)
ans = 0
for lenn in range(1, n + 1):
	temp = (n - lenn + 1) * (n - lenn + 1) * fact[lenn]
	temp %= MOD
	temp *= fact[n - lenn]
	temp %= MOD
	ans += temp
	ans %= MOD
print(ans)


(n, m) = map(int, input().split())
a = [1] * (n + 1)
for _ in range(2, n + 1):
	a[_] = _ * a[_ - 1] % m
ans = 0
for i in range(1, n + 1):
	ans = (ans + a[i] * a[n - i + 1] * (n - i + 1)) % m
print(ans)


import sys
readline = sys.stdin.readline
(N, MOD) = map(int, readline().split())

def frac(limit):
	frac = [1] * limit
	for i in range(2, limit):
		frac[i] = i * frac[i - 1] % MOD
	fraci = [None] * limit
	fraci[-1] = pow(frac[-1], MOD - 2, MOD)
	for i in range(-2, -limit - 1, -1):
		fraci[i] = fraci[i + 1] * (limit + i + 1) % MOD
	return (frac, fraci)
(frac, fraci) = frac(341398)

def comb(a, b):
	if not a >= b >= 0:
		return 0
	return frac[a] * fraci[b] * fraci[a - b] % MOD

def perm(a, b):
	if not a >= b >= 0:
		return 0
	return frac[a] * fraci[a - b] % MOD

def f(k, x):
	return perm(N - x + 1, k) * frac[N - k] * (N - k + 1)
ans = 0
for k in range(1, N + 1):
	ans = (ans + (N - k + 1) * (N - k + 1) * frac[k] * frac[N - k]) % MOD
print(ans)


(n, m) = map(int, input().split())
su = 0
fac = [1 for i in range(250005)]
for i in range(1, 250005):
	fac[i] = fac[i - 1] * i % m
for k in range(1, n + 1):
	su += (n - k + 1) * (n - k + 1) * fac[k] * fac[n - k] % m
print(su % m)


import math
(n, m) = map(int, input().split())
count = 0
fac = [1]
for i in range(1, n + 1):
	fac.append(fac[-1] * i % m)
for length in range(n):
	times = n - length
	length += 1
	p = fac[length]
	number = n - length + 1
	q = fac[number]
	count += times * p * q % m
print(count % m)


(n, m) = map(int, input().split())
facts = [1]
for i in range(1, 250001):
	facts.append(facts[-1] * i % m)
total = 0
for i in range(n):
	total += (n - i) * (n - i) * facts[n - (i + 1)] * facts[i + 1]
	total = total % m
print(total)


import sys
input = sys.stdin.readline
(n, mod) = map(int, input().split())
FACT = [1]
for i in range(1, 3 * 10 ** 5 + 1):
	FACT.append(FACT[-1] * i % mod)
ANS = 0
for i in range(1, n + 1):
	ANS = (ANS + i * i * FACT[n + 1 - i] * FACT[i - 1]) % mod
print(ANS)


(n, m) = list(map(int, input().split()))
dp = [0 for i in range(n + 1)]
dp[0] = 1
for i in range(1, n + 1):
	dp[i] = i * dp[i - 1] % m
ans = 0
for i in range(n, 0, -1):
	val = i * dp[i] * dp[n - i + 1] % m
	ans += val
	ans = ans % m
print(ans)


(n, m) = map(int, input().split())
fact = [1]
sm = 0
for i in range(1, n + 1):
	fact.append(fact[i - 1] * i % m)
for i in range(1, n + 1):
	sm += fact[i] * fact[n - i + 1] % m * (n - i + 1) % m
print(sm % m)


from math import factorial
(n, m) = map(int, input().split())
X = 1
fac_DP = [1] * (n + 1)
for k in range(n):
	X *= k + 1
	X %= m
	fac_DP[k + 1] = X
ans = []
q = fac_DP[n]
ans.append(q)
for i in range(2, n + 1):
	q = ans[-1]
	pair = n - i + 1
	q += pair * fac_DP[i] * fac_DP[n - i]
	q %= m
	ans.append(q)
print(sum(ans) % m)


(n, m) = map(int, input().split())
count = 0
factorial = [1]
for i in range(n - 1):
	factorial.append((i + 2) * factorial[i] % m)
for i in range(n):
	x = i + 1
	count += (n - i) * factorial[i] * factorial[n - i - 1]
print(count % m)


from sys import stdin
from itertools import permutations

def input():
	return stdin.readline()[:-1]

def intput():
	return int(input())

def sinput():
	return input().split()

def intsput():
	return map(int, sinput())
debugging = False

def dprint(*args):
	if debugging:
		print(*args)
	else:
		pass
(n, mod) = intsput()
fact = [1]
for i in range(1, 250001):
	fact.append(fact[-1] * i % mod)
cnt = 0
for k in range(1, n + 1):
	cnt += k ** 2 % mod * fact[n + 1 - k] * fact[k - 1]
	cnt %= mod
print(cnt)


(n, m) = [int(i) for i in input().split()]
s = 0
g = 1
facts = [0] * n
f = 1
for i in range(n):
	f *= i + 1
	f = f % m
	facts[i] = f
for i in range(n):
	g = facts[i]
	g *= facts[n - i - 1]
	g = g % m
	g *= n - i
	g = g % m
	s += g
	s = s % m
print(s)


(n, m) = map(int, input().split())
ans = 0
fa = 1
Fa = []
x = 1
for i in range(1, 1 + n):
	x *= i
	x %= m
	Fa.append(x)
for i in range(1, 1 + n):
	ans += (n - i + 1) * Fa[i - 1] * Fa[n - i]
	ans %= m
print(ans)


(n, mod) = list(map(int, input().split(' ')))
ans = [1, 1]
tot = 0
for i in range(2, n + 10):
	ans.append(ans[-1] * i % mod)
for i in range(1, n + 1):
	tot = (tot + ans[n - i + 1] * ans[i] % mod * (n - i + 1) % mod) % mod
print(tot)


(n, m) = map(int, input().split())
f = [1]
for n in range(1, n + 1):
	f.append(f[-1] * n % m)
ans = 0
for l in range(1, n + 1):
	ans += f[n - l + 1] * f[l] * (n - l + 1) % m
	ans %= m
print(ans)


class Combination:

	def __init__(self, n, MOD):
		self.fact = [1]
		for i in range(1, n + 1):
			self.fact.append(self.fact[-1] * i % MOD)
		self.inv_fact = [pow(self.fact[i], MOD - 2, MOD) for i in range(n + 1)]
		self.MOD = MOD

	def factorial(self, k):
		return self.fact[k]

	def inverse_factorial(self, k):
		return self.inv_fact[k]

	def permutation(self, k, r):
		if k < r:
			return 0
		return self.fact[k] * self.inv_fact[r] % self.MOD

	def combination(self, k, r):
		if k < r:
			return 0
		return self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r] % self.MOD
(n, m) = map(int, input().split())
comb = Combination(n, m)
ans = 0
for length in range(1, n + 1):
	ptn = n - length + 1
	pos = n - length + 1
	ans += ptn * pos * comb.factorial(length) * comb.factorial(n - length)
	ans %= m
print(ans)


(n, m) = map(int, input().split())
ans = 0
a = [1]
k = 1
for i in range(n):
	a.append(k * a[-1] % m)
	k += 1
for i in range(n):
	x = n - i
	ans += a[x] * a[i + 1] * (n - i)
	ans %= m
print(ans)


(n, m) = [int(i) for i in input().split()]
arr = [0] * (n + 1)
arr[0] = 1
for i in range(1, n + 1):
	arr[i] = arr[i - 1] * i % m
total = 0
for i in range(0, n):
	total += arr[i + 1] * (n - i) * arr[n - i] % m
	total %= m
print(total)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest
N = 250005
factorialNumInverse = [None] * (N + 1)
naturalNumInverse = [None] * (N + 1)
fact = [None] * (N + 1)

def InverseofNumber(p):
	naturalNumInverse[0] = naturalNumInverse[1] = 1
	for i in range(2, N + 1, 1):
		naturalNumInverse[i] = naturalNumInverse[p % i] * (p - int(p / i)) % p

def InverseofFactorial(p):
	factorialNumInverse[0] = factorialNumInverse[1] = 1
	for i in range(2, N + 1, 1):
		factorialNumInverse[i] = naturalNumInverse[i] * factorialNumInverse[i - 1] % p

def factorial(p):
	fact[0] = 1
	for i in range(1, N + 1):
		fact[i] = fact[i - 1] * i % p

def Binomial(N, R, p):
	ans = fact[N] * factorialNumInverse[R] % p * factorialNumInverse[N - R] % p
	return ans

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	for _ in range(tc):
		(n, mod) = ria()
		InverseofNumber(mod)
		InverseofFactorial(mod)
		factorial(mod)
		ans = 0
		for i in range(n, 0, -1):
			len = n - i + 1
			ans += fact[n - len + 1] * fact[len] * i
			ans = ans % mod
		print(ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


(n, m) = map(int, input().split())
fact = [0] * 250005
fact[0] = 1
for i in range(1, n + 1):
	fact[i] = fact[i - 1] * i % m
ans = 0
for le in range(1, n + 1):
	ans += (n - le + 1) * fact[le] * fact[n - le + 1]
	ans %= m
print(ans)


from collections import Counter, OrderedDict
from itertools import permutations as perm
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(n, m) = gil()
fac = [1] * (n + 1)
for i in range(2, n + 1):
	fac[i] = fac[i - 1] * (i % m) % m
ans = 0
for ln in range(1, n + 1):
	ans = (ans + fac[n + 1 - ln] * fac[ln] * ((n - ln + 1) % m) % m) % m
print(ans)


(n, m) = map(int, input().split())
factorials = [1]
for i in range(1, n + 1):
	factorials.append(factorials[-1] * i % m)
ans = 0
for i in range(1, n + 1):
	ans += factorials[i] * (n + 1 - i) ** 2 * factorials[n - i] % m
	ans %= m
print(ans)


def get_happiness(n, m):
	res = 0
	factorials = [1] * (n + 1)
	current_factorial = 1
	for i in range(2, n + 1):
		current_factorial *= i % m
		current_factorial = current_factorial % m
		factorials[i] = current_factorial
	for i in range(1, n + 1):
		term = factorials[i]
		term *= factorials[n - i + 1]
		term = term % m
		term *= (n - i + 1) % m
		term = term % m
		res += term
		res = res % m
	return res

def solve():
	(n, m) = [int(num) for num in input().split()]
	print(get_happiness(n, m))
solve()


(n, mod) = map(int, input().strip().split(' '))
factorials = [0 for i in range(250005)]
(factorials[0], factorials[1]) = (1, 1)
for i in range(2, 250004):
	factorials[i] = i * factorials[i - 1] % mod
ans = 0
for k in range(1, n + 1):
	ans = (ans % mod + (n - k + 1) % mod * ((n - k + 1) % mod) * (factorials[k] % mod) * (factorials[n - k] % mod) % mod) % mod
print(ans)


(n, m) = map(int, input().split())
f = [1] * (n + 1)
for i in range(1, n + 1):
	f[i] = f[i - 1] * i % m
ans = 0
for k in range(1, n + 1):
	ans = (ans + (n - k + 1) * f[k] * (n - k + 1) * f[n - k]) % m
print(ans)


(n, m) = map(int, input().split())
mod = m
n_max = n
(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 = F[n]
for i in range(1, n):
	ans = (ans + pow(n - i + 1, 2, mod) * F[i] * F[n - i]) % mod
print(ans)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, m) = list(map(int, input().split()))
factorial = [1]
for i in range(2, n + 1):
	factorial.append(factorial[-1] * i % m)
ans = 0
for i in range(n):
	temp = factorial[i] * factorial[-i - 1] % m
	temp = temp * (n - i) % m
	ans += temp
	ans %= m
print(ans)


def main():
	(n, m) = map(int, input().split())
	fact = [0] * (n + 1)
	fact[0] = 1
	for i in range(1, n + 1):
		fact[i] = fact[i - 1] * i % m
	ans = 0
	for i in range(n):
		k = (n - i) * fact[i + 1]
		k = k % m
		k = k * fact[n - i] % m
		ans = (ans + k) % m
	print(ans)
	return
main()


(n, p) = list(map(int, input().split()))
sil = [1] * 300000
sil[0] = 1
sil[1] = 1
for i in range(2, 300000):
	sil[i] = sil[i - 1] * i % p
wyn = 0
for i in range(n):
	wyn = (wyn + (n - i) * sil[n - i] * sil[i + 1]) % p
print(wyn)


(n, m) = map(int, input().split())
fac = [1]
for i in range(1, n + 1):
	fac += [i * fac[-1] % m]
ans = (n + 1) * fac[n] % m
for i in range(1, n - 1):
	ans = (ans + (n - i) * (n - i) * fac[i + 1] * fac[n - i - 1]) % m
print(ans if n > 1 else 1 % m)


(n, m) = map(int, input().split())
fact = [1]
for el in range(1, n + 1):
	fact.append(fact[-1] * el % m)
ans = 0
for el in range(1, n + 1):
	t = fact[el]
	p = fact[n - el + 1]
	q = n - el + 1
	ans = (ans + t * p % m * q % m) % m
print(ans)


def inp(dtype=str, strip=True):
	s = input()
	res = [dtype(p) for p in s.split()]
	res = res[0] if len(res) == 1 and strip else res
	return res

def problem1():
	(n, m) = inp(int)
	s = inp(strip=False)
	t = inp(strip=False)
	q = inp(int)
	for _ in range(q):
		y = inp(int) - 1
		print(s[y % n] + t[y % m])

def problem2():
	n = inp(int)
	res = 0
	noascent_mins = [0 for _ in range(n)]
	noascent_maxs = [0 for _ in range(n)]
	noascent_cnt = 0
	for i in range(n):
		s = inp(int, strip=False)
		assert s[0] == len(s) - 1
		s = s[1:]
		ssort = sorted(s, reverse=True)
		(mn, mx) = (ssort[-1], ssort[0])
		has_ascent = s != ssort and mn < mx
		if has_ascent:
			num = 2 * (n - i + noascent_cnt) - 1
			res += num
		else:
			noascent_mins[noascent_cnt] = mn
			noascent_maxs[noascent_cnt] = mx
			noascent_cnt += 1
	noascent_maxs = noascent_maxs[:noascent_cnt]
	noascent_mins = noascent_mins[:noascent_cnt]
	noascent_mins = sorted(noascent_mins)
	noascent_maxs = sorted(noascent_maxs)
	n = noascent_cnt
	i = 0
	for j in range(n):
		while i < n and noascent_mins[i] < noascent_maxs[j]:
			i += 1
		res += i
	print(res)

def problem3():
	(n, m) = inp(int)
	res = 0
	factorials = [1 for i in range(n + 1)]
	for k in range(1, n + 1):
		factorials[k] = factorials[k - 1] * k % m
	for k in range(1, n + 1):
		res += (n - k + 1) ** 2 * factorials[k] * factorials[n - k] % m
	print(res % m)

def problem4():
	pass

def problem5():
	pass
problem3()


f = [1]
(n, mod) = map(int, input().split())
for i in range(1, n + 1):
	f.append(f[-1] * i % mod)
SUM = 0
for i in range(1, n + 1):
	SUM += f[i] * f[n - i + 1] * (n - i + 1)
	SUM %= mod
print(SUM)


import itertools
import math
(n, mod) = map(int, input().split())
fact = [1]
f = 1
for i in range(1, 251000):
	f *= i
	f %= mod
	fact.append(f)
score = 0
for m in range(1, n + 1):
	res = fact[n] * (n - m + 1)
	res *= fact[n - m + 1]
	res *= fact[m]
	res //= fact[n]
	score += res
print(score % mod)


def main():
	(n, mod) = map(int, input().split())
	facts = [1]
	for i in range(1, n + 1):
		facts.append(facts[-1] * i % mod)
	ans = 0
	for i in range(n):
		ans += facts[i + 1] * (n - i) * (facts[n - i] % mod)
		ans %= mod
	print(ans)
main()


a = [1]
(n, m) = map(int, input().split())
for i in range(1, n + 1):
	a.append(a[-1] * i % m)
ans = 0
for i in range(1, n + 1):
	p = a[i] * a[n - i + 1] * (n - i + 1)
	ans += p
	ans %= m
print(ans)


def solve(n, m):
	fact = [1]
	for i in range(1, 250001):
		fact.append(fact[i - 1] * i % m)
	answer = 0
	for i in range(n):
		t = i + 1
		subsum = (n - t + 1) * fact[t] * fact[n - t + 1] % m
		answer += subsum
		answer %= m
	return answer
nm = [int(x) for x in input().split(' ')]
(n, m) = (nm[0], nm[1])
print(solve(n, m))


(n, m) = map(int, input().split())
ans = 0
fact = [1]
for i in range(1, n + 1):
	fact.append(fact[-1] * i % m)
for d in range(1, n):
	ans = (ans + fact[n - d] * (n - d) * fact[d + 1]) % m
temp = fact[n] * n
ans += temp
ans = ans % m
print(ans)


(n, m) = map(int, input().split())
lst = [1]
for i in range(1, n + 1):
	lst.append(lst[-1] * i % m)
result = 0
for i in range(1, n + 1):
	result = (result + (n - i + 1) * lst[i] * lst[n - i + 1] % m) % m
print(result)


(n, mod) = map(int, input().split())
ans = 0
fac = [1] * (n + 1)
for i in range(2, n + 1):
	fac[i] = fac[i - 1] * i % mod
ans = 0
for x in range(1, n + 1):
	ans = (ans + fac[x] * fac[n - x] * (n - (x - 1)) ** 2) % mod
print(ans)


import sys
(n, mod) = map(int, sys.stdin.readline().split())
ans = 0
fac = [1]
for i in range(n):
	a = fac[-1] * (i + 1) % mod
	fac.append(a)
for i in range(n):
	ans = ans + (n - i) ** 2 % mod * fac[i + 1] * fac[n - (i + 1)]
	ans = ans % mod
print(ans)


import sys
input = sys.stdin.buffer.readline
(n, m) = [int(i) for i in input().split()]
f = [0] * (n + 1)
f[0] = 1
for i in range(1, n + 1):
	f[i] = f[i - 1] * i
	f[i] %= m
ans = 0
for i in range(n):
	temp = 1
	temp *= f[i + 1]
	temp *= f[n - i]
	temp *= i + 1
	ans += temp
	ans %= m
print(ans)


(n, m) = map(int, input().split())
ans = 0
f = [1]
for i in range(1, n + 2):
	f += (f[-1] * i % m,)
for l in range(1, n + 1):
	ans += (f[n - l + 2] - f[n - l + 1]) * f[l] % m
	ans %= m
print(ans)


from sys import stdin, stdout
(n, m) = map(int, stdin.readline().split())
memo = {0: 1}

def fac(x):
	if x not in memo:
		r = 1
		for i in range(x):
			if i in memo:
				r = memo[i]
				continue
			else:
				r = r * i % m
				memo[i] = r
		memo[x] = x * r % m
	return memo[x]
total = 0
mid = n // 2 + 1
for i in range(1, mid):
	total = (total + fac(n - i + 1) * fac(i)) % m
total = total * (n + 1) % m
if n % 2:
	total = (total + mid * fac(n - mid + 1) * fac(mid)) % m
print(total)


(N, mod) = map(int, input().split())
NNN = 10 ** 6
g1 = [1, 1]

def mul(a, b):
	return a % mod * (b % mod) % mod
for i in range(2, NNN + 1):
	g1.append(g1[-1] * i % mod)
r = 0
for i in range(1, N + 1):
	r += mul(mul(mul(N - i + 1, N - i + 1), g1[N - i]), g1[i])
	r %= mod
print(r)


(n, m) = map(int, input().split())
fact = [0] * (n + 1)
fact[0] = fact[1] = 1
for i in range(2, n + 1):
	fact[i] = fact[i - 1] * i % m
ans = 0
for i in range(n, 0, -1):
	term = fact[i] * fact[n - i + 1] % m
	ans += term * i % m
	ans %= m
print(ans)


import sys
import math
import heapq
import bisect
import re
from collections import deque
sys.setrecursionlimit(1000000000)

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def finput():
	return float(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())

def modst(w, s):
	res = 1
	while s:
		if s % 2:
			res *= w
		w *= w
		s //= 2
	return res

def error(n):
	print('YES')
	exit(n)

def pro(n, m):
	q = [1]
	for i in range(1, n + 5):
		q.append(q[-1] * i % m)
	return q

def main():
	(n, m) = rinput()
	q = pro(n, m)
	result = n * q[n] % m
	for k in range(2, n + 1):
		t = n - k
		result += (t + 1) * (t + 1) % m * q[k] % m * q[t] % m
		result %= m
	print(result)
for i in range(1):
	main()


from sys import stdin, stdout
(n, mod) = map(int, stdin.readline().strip().split())
f = [1, 1]
for i in range(2, n + 1):
	f.append(f[-1] * i % mod)
x = n
ans = 0
for i in range(1, n + 1):
	ans = (ans + x * f[i] * x * f[n - i] % mod) % mod
	x -= 1
print(ans)


(n, m) = map(int, input().split())
fact = [1] * (n + 1)
for i in range(1, n + 1):
	fact[i] = fact[i - 1] * i
	fact[i] %= m
ans = 0
for len in range(1, n + 1):
	x = fact[len] * fact[n - len + 1] * (n - len + 1)
	x %= m
	ans += x
	ans %= m
print(ans)


import sys

def solve():
	(n, M) = map(int, sys.stdin.readline().split())
	f = [1 for _ in range(n + 1)]
	ans = 0
	for i in range(2, n + 1, 1):
		f[i] = f[i - 1] * i % M
	for i in range(1, n + 1, 1):
		mtp = (n - i + 1) * (n - i + 1) % M
		mtp = mtp * f[i] % M
		mtp = mtp * f[n - i] % M
		ans = (ans + mtp) % M
	print(ans)
solve()


(n, m) = map(int, input().split())
fact = [1] * (n + 1)
for i in range(1, n + 1):
	fact[i] = fact[i - 1] * i % m

def multiple(x, y):
	return x % m * (y % m) % m

def add(x, y):
	return (x % m + y % m) % m
res = 0
for i in range(1, n + 1):
	t1 = multiple(n - i + 1, n - i + 1)
	t2 = multiple(fact[i], fact[n - i])
	res = add(res, multiple(t1, t2))
print(res)


(n, mod) = map(int, input().split())
f = [1] + [0] * n
for i in range(1, n + 1):
	f[i] = i * f[i - 1] % mod
ret = 0
for size in range(1, n + 1):
	ret += (n - size + 1) * (f[size] * f[n - size + 1]) % mod
	ret %= mod
print(ret)


import itertools
(n, m) = map(int, input().split(' '))
factorial = [1, 1]
for i in range(2, n + 1):
	factorial.append(factorial[-1] * i % m)
ss2 = 0
for l in range(1, n + 1):
	term = factorial[l] * factorial[n - l + 1] * (n - l + 1)
	ss2 = (term + ss2) % m
print(ss2)


(n, m) = input().split(' ')
n = int(n)
m = int(m)
val = m

def bin_exp(a, n):
	if n == 0:
		return 1
	else:
		j = 0
		bin_val = []
		while n > 0:
			bin_val.append(n % 2)
			n = n // 2
			j += 1
		power_arr = [a % val]
		for i in range(1, j):
			power_arr.append(power_arr[-1] ** 2 % val)
		value = 1
		for i in range(0, j):
			if bin_val[i] == 1:
				value = value * power_arr[i] % val
		return value % val

def fact_arr(n):
	arr = [1]
	for i in range(n):
		arr.append(arr[-1] * (i + 1) % val)
	return arr

def mult_inver(a):
	return bin_exp(a, val - 2)
ans = 0
fact_list = fact_arr(250000)
for i in range(1, n + 1):
	ans = (ans + (n + 1 - i) ** 2 * (fact_list[i] * fact_list[n - i])) % val
print(ans % val)


(num, mod) = map(int, input().split())
fact = [0] * (num + 2)
fact[0] = 1
for i in range(1, num + 1):
	fact[i] = fact[i - 1] * i
	fact[i] %= mod
ans = 1
for i in range(num):
	ans += (num - i) * fact[num - i] % mod * fact[i + 1] % mod
	ans %= mod
print(ans - 1)


(n, m) = list(map(int, input().split(' ')))
ans = 0
d = [1] * (n + 1)
for i in range(1, n + 1):
	d[i] = d[i - 1] * i % m
for i in range(1, n + 1):
	ans = (ans + (n - i + 1) * d[n - i + 1] % m * d[i]) % m
print(ans)


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(n, m) = I()
ans = 0
fac = [1] * 3000000
for i in range(1, 300000):
	fac[i] = i * fac[i - 1] % m
for i in range(1, n + 1):
	pairs = n - i + 1
	ans += pairs * fac[n - i + 1] * fac[i]
	ans %= m
print(ans % m)


(n, m) = map(int, input().split())
l = [1] * (n + 1)
for i in range(2, n + 1):
	l[i] = l[i - 1] * i % m % m
res = 0
for x in range(0, n):
	res = res % m + (n - x) * l[n - x] % m * l[x + 1] % m
print(res % m)


l = input().split()
n = int(l[0])
m = int(l[1])
fact = [1 for i in range(250007)]
for i in range(2, 250007):
	fact[i] = fact[i - 1] * i
	fact[i] %= m
ans = 0
for i in range(1, n + 1):
	z = fact[n - i]
	z = z * fact[i]
	z %= m
	z = z * (n - i + 1)
	z %= m
	z = z * (n - i + 1)
	z %= m
	ans += z
	ans %= m
print(ans)


(n, mod) = map(int, input().split())
fact = [1]
for i in range(1, n + 1):
	fact.append(fact[i - 1] * i % mod)
ans = 0
for i in range(n):
	ans = (ans + fact[i + 1] * fact[n - i - 1] % mod * (n - i) % mod * (n - i) % mod) % mod
print(ans)


import sys
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
(n, m) = mi()
fact = [1, 1]
for i in range(2, n + 1):
	fact.append(fact[-1] * i % m)
res = 0
for i in range(1, n + 1):
	res = (res + (n - i + 1) * fact[i] * fact[n - i + 1]) % m
print(res)


def mp():
	return map(int, input().split())
(n, mod) = mp()
f = [1] * (n + 1)
for i in range(1, n + 1):
	f[i] = f[i - 1] * i % mod
ans = f[n] * n
for i in range(2, n + 1):
	t = (n - i + 1) * f[i] * f[n - i] * (n - i + 1) % mod
	ans += t
print(ans % mod)


import sys
(n, m) = list(map(int, sys.stdin.readline().strip().split()))
ans = 0
F = [1] * (n + 1)
for i in range(0, n):
	F[i + 1] = F[i] * (i + 1) % m
for i in range(0, n):
	ans = (ans + (n - i) * (n - i) * F[n - i - 1] * F[i + 1]) % m
print(ans)


(n, m) = map(int, input().split())
fac = [1]
for i in range(1, n + 1):
	fac.append(fac[i - 1] * i % m)
res = 0
for i in range(1, n + 1):
	cv = fac[i] * fac[n - i] * (n - i + 1) * (n - i + 1) % m
	res = (res + cv) % m
print(res)


def main():
	import sys
	input = sys.stdin.readline
	(N, mod) = map(int, input().split())
	nmax = N + 1
	fac = [0] * (nmax + 1)
	fac[0] = 1
	fac[1] = 1
	for i in range(2, nmax):
		fac[i] = fac[i - 1] * i % mod
	ans = 0
	for k in range(1, N + 1):
		ans = (ans + (N - k + 1) ** 2 % mod * (fac[N - k] * fac[k]) % mod % mod) % mod
	print(ans)
main()


import sys
sys.setrecursionlimit(10 ** 7)

def fact(n, m):
	if n >= m:
		return 0
	result = 1
	for i in range(1, n + 1):
		result = result * i % m
	return result
(n, m) = [int(x) for x in input().split()]
total = 0
facts = list()
facts = [1]
for i in range(n):
	facts.append(facts[-1] % m * ((i + 1) % m) % m)
for i in range(n):
	total = (total % m + (n - i) % m * (facts[i + 1] % m) * (facts[n - i] % m) % m) % m
print(total)


(n, m) = map(int, input().split())
facts = list()
fact = 1
for i in range(1, n + 1):
	fact *= i
	fact %= m
	facts.append(fact)
ans = 0
for i in range(1, n + 1):
	ans += facts[i - 1] * facts[n - i] * (n - i + 1)
	ans %= m
print(ans)


(n, m) = map(int, input().split())
factorials = [1]
for num in range(1, 250001):
	factorials.append(factorials[-1] * num % m)
sum_of_happiness = 0
for num_of_subsegments in range(1, n + 1):
	sum_of_happiness = (sum_of_happiness + (n - num_of_subsegments + 1) * factorials[n - num_of_subsegments + 1] * factorials[num_of_subsegments]) % m
print(sum_of_happiness)


import math
line = input().split()
upfac = []
upfac.append(1)
for a in range(1, int(line[0]) + 1):
	upfac.append(upfac[a - 1] * a % int(line[1]))
ans = 0
for a in range(1, int(line[0]) + 1):
	ans += a * upfac[a] * upfac[int(line[0]) + 1 - a]
print(ans % int(line[1]))


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
(n, m) = inputnums()
factorial = [1]
for i in range(1, n + 1):
	factorial.append(i * factorial[i - 1] % m)
ans = 0
for i in range(1, n + 1):
	ans += (n - i + 1) * (factorial[i] * factorial[n - i + 1]) % m
	ans %= m
print(ans)


(n, m) = [int(x) for x in input().split()]
fac = [1] * n
for i in range(2, n + 1):
	fac[i - 1] = fac[i - 2] * i % m
ans = 0
for i in range(n):
	ans += (i + 1) * fac[i] % m * fac[n - i - 1] % m
	ans %= m
print(ans)


(n, m) = map(int, input().split())
facts = [1 for _ in range(n + 1)]
for i in range(1, n + 1):
	facts[i] = facts[i - 1] * i % m
ans = 0
for len_otr in range(1, n + 1):
	ans += (n + 1 - len_otr) % m * facts[len_otr] * facts[n - len_otr] * ((n + 1 - len_otr) % m)
	ans = ans % m
print(ans)


import sys

class CNewYearAndPermutation:

	def solve(self):
		from math import factorial

		def stupid(n, m):
			ans = factorial(n) * n % m
			for i in range(1, n + 1):
				for j in range(i + 1, n + 1):
					for mn in range(1, n - (j - i) + 1):
						ans += factorial(j - i + 1) * factorial(n - (j - i + 1))
						ans %= m
			return ans

		def smart(n, m):
			ans = fact[n] * n % m
			for k in range(1, n):
				ans += (n - k) * fact[k + 1] * fact[n - k]
				ans %= m
			return ans
		(n, m) = [int(_) for _ in input().split()]
		fact = [1] * (n + 1)
		for i in range(1, n + 1):
			fact[i] = i * fact[i - 1]
			fact[i] %= m
		ans = 0
		print(smart(n, m))
solver = CNewYearAndPermutation()
input = sys.stdin.readline
solver.solve()


(n, m) = [int(s) for s in input().split()]
fac = [1] * (n + 1)
for i in range(1, n + 1):
	fac[i] = fac[i - 1] * i % m
ans = n * fac[n] % m
for i in range(n - 1):
	ans = (ans + (n - i - 1) * fac[n - 1 - i] % m * fac[i + 2] % m) % m
print(ans)


(n, m) = map(int, input().split())
fact = [1]
for i in range(1, n + 1):
	fact.append(fact[-1] * i % m)
ans = 0
val = n
for i in range(1, n + 1):
	t = val * val % m * (fact[i] % m) * (fact[n - i] % m) % m
	ans = (ans + t) % m
	val = (val - 1) % m
print(ans)


(n, m) = map(int, input().split())
fact = [1]
for i in range(1, n + 1):
	fact.append(fact[-1] * i % m)
total = 0
for k in range(1, n + 1):
	total = (total + (n - k + 1) * (n - k + 1) % m * fact[k] % m * fact[n - k] % m) % m
print(total)


input = __import__('sys').stdin.readline
MIS = lambda : map(int, input().split())
(n, MOD) = MIS()
ans = 0
fac = [1]
for i in range(1, n + 2):
	fac.append(fac[-1] * i % MOD)
for d in range(1, n + 1):
	ans += (n - d + 1) ** 2 * fac[d] * fac[n - d]
	ans %= MOD
print(ans)


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import *
getcontext().prec = 25
MOD = pow(10, 9) + 7
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, k) = map(int, input().split(' '))
d = [1]
for i in range(1, n + 2):
	d.append(d[-1] * i % k)
ans = 0
for i in range(1, n + 1):
	ans += d[i] * d[n - i + 1] * (n - i + 1)
	ans %= k
print(ans)


import os, sys
from io import BytesIO, IOBase
from fractions import Fraction

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
import math
(n, m) = mi()
l = [1, 1]
for i in range(2, n + 1):
	l.append(l[i - 1] * i % m)
ans = 0
for i in range(n):
	c = (n - i) % m * (l[i + 1] % m) * ((n - i) * l[n - i - 1]) % m
	ans += c
print(ans % m)


(n, m) = map(int, input().split())
mass = [1, 1]
for i in range(2, n + 1):
	mass.append(mass[-1] * i % m)
summ = 0
for i in range(1, n + 1):
	summ += (n - i + 1) ** 2 * mass[i] * mass[n - i]
	summ %= m
print(summ)


(N, P) = map(int, input().split())
fa = [1]
for i in range(1, N + 100):
	fa.append(fa[-1] * i % P)
fainv = [pow(fa[-1], P - 2, P)]
for i in range(1, N + 100)[::-1]:
	fainv.append(fainv[-1] * i % P)
fainv = fainv[::-1]
print(sum([fa[k] * fa[N - k] * (N - k + 1) ** 2 for k in range(1, N + 1)]) % P)


(n, m) = [int(x) for x in input().split()]
factor = [1] * (n + 2)
for i in range(1, n + 2):
	factor[i] = factor[i - 1] * i
	factor[i] %= m
ans = factor[n] * n % m
for i in range(1, n):
	ans += (n - i) * (n - i) * factor[i + 1] * factor[n - i - 1]
	ans %= m
print(ans)