Let $n$ be an integer. Consider all permutations on integers $1$ to $n$ in lexicographic order, and concatenate them into one big sequence $p$. For example, if $n = 3$, then $p = [1, 2, 3, 1, 3, 2, 2, 1, 3, 2, 3, 1, 3, 1, 2, 3, 2, 1]$. The length of this sequence will be $n \cdot n!$.

Let $1 \leq i \leq j \leq n \cdot n!$ be a pair of indices. We call the sequence $(p_i, p_{i+1}, \dots, p_{j-1}, p_j)$ a subarray of $p$. Its length is defined as the number of its elements, i.e., $j - i + 1$. Its sum is the sum of all its elements, i.e., $\sum_{k=i}^j p_k$. 

You are given $n$. Find the number of subarrays of $p$ of length $n$ having sum $\frac{n(n+1)}{2}$. Since this number may be large, output it modulo $998244353$ (a prime number). 


-----Input-----

The only line contains one integer $n$ ($1 \leq n \leq 10^6$), as described in the problem statement.


-----Output-----

Output a single integer — the number of subarrays of length $n$ having sum $\frac{n(n+1)}{2}$, modulo $998244353$.


-----Examples-----
Input
3

Output
9

Input
4

Output
56

Input
10

Output
30052700



-----Note-----

In the first sample, there are $16$ subarrays of length $3$. In order of appearance, they are:

$[1, 2, 3]$, $[2, 3, 1]$, $[3, 1, 3]$, $[1, 3, 2]$, $[3, 2, 2]$, $[2, 2, 1]$, $[2, 1, 3]$, $[1, 3, 2]$, $[3, 2, 3]$, $[2, 3, 1]$, $[3, 1, 3]$, $[1, 3, 1]$, $[3, 1, 2]$, $[1, 2, 3]$, $[2, 3, 2]$, $[3, 2, 1]$. 

Their sums are $6$, $6$, $7$, $6$, $7$, $5$, $6$, $6$, $8$, $6$, $7$, $5$, $6$, $6$, $7$, $6$. As $\frac{n(n+1)}{2} = 6$, the answer is $9$.

Difficulty: MEDIUM_HARD

Solutions:
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
z = 998244353
if n == 1:
	print(1)
else:
	lis = [1]
	for i in range(2, n + 1):
		lis.append(int(lis[-1] * i) % z)
	arr = [n]
	for i in range(n - 2):
		a = n - i - 1
		arr.append(a * arr[-1] % z)
	num = [arr[0]]
	for i in range(1, n - 1):
		num.append((num[-1] + arr[i]) % z)
	x = n * lis[-1] % z
	ans = (x - num[-1]) % z
	print(ans)


P = 998244353
n = int(input().strip())
sub_sum = 0
curr_num = 1
for idx in range(n - 1):
	curr_num = curr_num * (n - idx) % P
	sub_sum = (sub_sum + curr_num) % P
add_num = curr_num * n % P
final = (add_num - sub_sum) % P
print(final)


MOD = 998244353
I = lambda : list(map(int, input().split()))
(n,) = I()
s = [1, 2]
for i in range(3, 10 ** 6 + 1):
	s.append((s[-1] + 1) * i % MOD)
f = 1
l = []
for i in range(1, 10 ** 6 + 1):
	l.append(f * i % MOD)
	f = f * (i + 1) % MOD
n -= 1
if n == 0:
	print(1)
	return
print((l[n] - s[n]) % MOD)


n = int(input())
M = 998244353
ans = 1
fac = 1
phi = 1
for q in range(n, 2, -1):
	fac *= q
	fac %= M
	phi += fac
	phi %= M
fac *= 2
fac %= M
ans += fac * (n - 1)
ans %= M
ans += M - phi
ans %= M
if n == 1:
	ans = 1
print(ans)


import sys
input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
MOD = 998244353
n = inp()
dp = [0 for i in range(n + 1)]
fact = [1 for i in range(n + 1)]
for i in range(2, n + 1):
	dp[i] = i * (dp[i - 1] + 1)
	dp[i] %= MOD
	fact[i] = fact[i - 1] * i
	fact[i] %= MOD
ans = n * fact[n] - dp[n]
ans %= MOD
if ans < 0:
	ans += MOD
print(ans)


import sys
input = sys.stdin.readline
n = int(input())
s = 0
m = 998244353
a = 1
for i in range(n, 1, -1):
	a *= i
	a %= m
	s += a
	s %= m
b = 1
for i in range(1, n + 1):
	b *= i
	b %= m
print((b * n - s) % m)


mod = 998244353
n = int(input())
x = 1
f = 1
for i in range(2, n + 1):
	f = f * i % mod
	t = (x - 1 + mod) % mod
	y = i * t % mod
	x = (f + y) % mod
print(x)


res = 0
n = int(input())
f = 1
s = 0
for i in range(n, 1, -1):
	f = f * i % 998244353
	s = (s + f) % 998244353
print((f * n - s) % 998244353)


n = int(input())
x = n
for p in range(1, n):
	x = (p + 1) * (x - 1) % 998244353
print(x)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10 ** 8)
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
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')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 51, func=lambda a, b: a & b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
n = int(input())
if n == 1:
	print(1)
elif n == 2:
	print(2)
elif n == 3:
	print(9)
else:
	mod = mod1
	ans = n
	ans += (n + 1) * (n - 2)
	st = n - 3
	fact = n - 1
	cou = n - 1
	t = 3
	for i in range(n - 4):
		ans += (n - 1 + t) * st * fact % mod
		ans %= mod
		fact *= cou - 1
		fact %= mod
		cou -= 1
		st -= 1
		t += 1
	print(ans * n % mod)


import math
n = int(input())
mod = 998244353
F = [1, 1]
f = 1
for i in range(2, n + 1):
	f *= i
	f %= mod
	F.append(f)
ret = 1
for i in range(1, n + 1):
	ret = ret * i - i + F[i]
	ret %= mod
print(ret)


n = int(input())
prefix = 1
ans = 0
mod = 998244353
for k in range(1, n):
	ans += prefix * (n - k) * k % mod
	prefix *= n - k + 1
	prefix %= mod
print((ans + 1) % mod)


import sys
import math
MAX = 1000010
MOD = 998244353

def main():
	ar = [1 for _ in range(MAX)]
	fact = [1 for _ in range(MAX)]
	for n in range(2, MAX):
		fact[n] = fact[n - 1] * n % MOD
	for n in range(2, MAX):
		ar[n] = ((ar[n - 1] - 1) * n + fact[n]) % MOD
	n = int(input())
	print(ar[n])

def __starting_point():
	main()
__starting_point()


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


md = 998244353
n = int(input())
p = 1
ans = 0
for i in range(n - 1):
	p = p * (n - i) % md
	ans -= p
ans += n * p
print(ans % md)


MOD = 998244353
list_size = 1000001
f_list = [1] * list_size
f_r_list = [1] * list_size
for i in range(list_size - 1):
	f_list[i + 1] = int(f_list[i] * (i + 2) % MOD)

def power(n, x):
	if x == 1:
		return n
	elif x % 2 == 0:
		return power(int(n * n % MOD), int(x / 2))
	else:
		return int(n * power(n, x - 1) % MOD)
f_r_list[-1] = power(f_list[-1], MOD - 2)
for i in range(2, list_size + 1):
	f_r_list[-i] = int(f_r_list[-i + 1] * (list_size + 2 - i) % MOD)

def comb(n, r):
	if n < r:
		return 0
	elif n == 0 or r == 0 or n == r:
		return 1
	else:
		return f_list[n - 1] * f_r_list[n - r - 1] % MOD * f_r_list[r - 1] % MOD
n = int(input())
ans = f_list[n - 1]
for i in range(2, n):
	ans = (ans + comb(n, i) * (f_list[i - 1] - 1) * f_list[n - i - 1]) % MOD
print(ans)


def factorial_mod(n, mod):
	ans = 1
	for i in range(1, n + 1):
		ans = ans * i % mod
	return ans

def solve(n):
	if n == 1:
		return 1
	elif n == 2:
		return 2
	mod = 998244353
	len_metaseq = factorial_mod(n, mod)
	ans = (n - 1 + (n - 2)) * len_metaseq * 499122177 % mod
	error = 0
	for curr in range(4, n + 1):
		error = (error + 1) * curr % mod
	return (ans - error) % mod
n = int(input())
print(solve(n))


n = int(input())
M = 998244353
f = n
s = n
for i in range(1, n):
	f = f * (n - i)
	x = n - i - 1
	y = f * x // (x + 1)
	s += (i + 1) * y
	s %= M
	f %= M
print(s % M)


MAX = 1000010
MOD = 998244353

def main():
	ar = [1 for _ in range(MAX)]
	fact = [1 for _ in range(MAX)]
	for n in range(2, MAX):
		fact[n] = fact[n - 1] * n % MOD
	for n in range(2, MAX):
		ar[n] = ((ar[n - 1] - 1) * n + fact[n]) % MOD
	n = int(input())
	print(ar[n])
main()


n = int(input())

def fun(n):
	if n == 1:
		return 1
	else:
		cur = n
		for i in range(1, n):
			cur = (cur - 1) * (i + 1) % 998244353
		return cur
print(fun(n))


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


from sys import stdin
mod = 998244353
n = int(stdin.readline().strip())
if n == 1:
	print(1)
	exit(0)
dp = [0 for i in range(n + 1)]
dp[1] = n
dp[2] = n * (n - 2) % mod
fact = [1 for i in range(n + 1)]
y = n - 1
for i in range(1, n + 1):
	fact[i] = fact[i - 1] * y % mod
	y -= 1
for i in range(3, n):
	dp[i] = n * (fact[i - 2] * (n - i)) % mod
ans = 0
for i in range(1, n):
	ans = (ans + i * dp[i]) % mod
print(ans)


MOD = 998244353
n = int(input())
if n < 3:
	print(n)
else:
	mxm = 9
	m = 3
	mf = 6
	for _ in range(n - 3):
		m += 1
		mxm = (mxm + 1) * m
		mxm %= MOD
		mf *= m
		mf %= MOD
	print((n * mf - mxm) % MOD)


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


n = int(input())
dd = 998244353
dp = [(1, 0), (1, 0), (2, 0), (6, 3)]
if n == 1:
	print(1)
	exit()
elif n == 2:
	print(2)
	exit()
for i in range(4, n + 1):
	np = (dp[-1][0] * i, i * (dp[-1][0] - 1) + i * dp[-1][1])
	np = (np[0] % dd, np[1] % dd)
	dp.append(np)
print((dp[-1][0] + dp[-1][1]) % dd)


t = int(input())
res = t
i = 2
while i <= t:
	res = (res - 1) * i % 998244353
	i += 1
print(res)


n = int(input())
f_n = n
cnt = 0
for k in range(n - 1, 0, -1):
	cnt += f_n
	f_n *= k
	if f_n >= 998244353:
		f_n %= 998244353
print((n * f_n - cnt) % 998244353)


def solve():
	n = int(input())
	factorials = [0, 1, 2, 6, 24, 120]
	subtract = [0, 0, 2, 9, 40, 205]
	for item in range(6, n + 1):
		factorials.append(factorials[-1] * item % 998244353)
		subtract.append((subtract[-1] + 1) * item % 998244353)
	print((n * factorials[n] % 998244353 - subtract[n]) % 998244353)
solve()


a = int(input())
n = a
for i in range(2, n + 1):
	a = (a - 1) * i % 998244353
print(a)


n = int(input())
ans = 1
frac = 1
m = 998244353
for i in range(2, n + 1):
	ans = (ans + frac - 1) % m * i % m
	frac = frac * i % m
print(ans)


from sys import stdin, stdout
from collections import defaultdict, Counter
from bisect import bisect, bisect_left
import math
from itertools import permutations
I = stdin.readline
mod = 998244353
n = int(I())
b = 0
prod = 1
for i in range(0, n - 1):
	prod *= n - i
	prod %= mod
	b -= prod
b += n * prod
print(int(b % mod))


n = int(input())
mod = 998244353
fact = 1
for i in range(1, n + 1):
	fact *= i
	fact %= mod
ans = fact
k = 1
for i in range(n, 1, -1):
	k *= i
	k %= mod
	ans += (fact - k) % mod
	ans %= mod
print(ans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
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')
dp = [None] * 1000006
mod = 998244353
n = int(input())
dp[1] = n
for i in range(2, n + 1):
	dp[i] = (n - i + 1) * dp[i - 1] % mod
ans = dp[n] * n % mod
for i in range(1, n):
	ans = (ans + mod - dp[i]) % mod
print(ans)


MOD = 998244353
fac = [1] * 1000007
for i in range(2, 1000001):
	fac[i] = fac[i - 1] * i
	fac[i] %= MOD
dp = [0] * 1000007
for i in range(3, 1000001):
	dp[i] = (dp[i - 1] + fac[i - 1] - 1) * i
	dp[i] %= MOD
n = int(input())
ans = (fac[n] + dp[n]) % MOD
print(ans)


def read_nums():
	return [int(x) for x in input().split()]

def main():
	(n,) = read_nums()
	cur_res = 1
	factorial = 1
	for i in range(2, n + 1):
		factorial = factorial * i % 998244353
		cur_res = ((cur_res - 1) * i + factorial) % 998244353
	print(cur_res)

def __starting_point():
	main()
__starting_point()


def iterative_egcd(a, b):
	(x, y, u, v) = (0, 1, 1, 0)
	while a != 0:
		(q, r) = (b // a, b % a)
		(m, n) = (x - u * q, y - v * q)
		(b, a, x, y, u, v) = (a, r, u, v, m, n)
	return (b, x, y)

def modinv(a, m):
	(g, x, y) = iterative_egcd(a, m)
	if g != 1:
		return None
	else:
		return x % m

def factorialMod(n, modulus):
	ans = 1
	if n <= modulus // 2:
		for i in range(1, n + 1):
			ans = ans * i % modulus
	else:
		for i in range(1, modulus - n):
			ans = ans * i % modulus
		ans = modinv(ans, modulus)
		if n % 2 == 0:
			ans = -1 * ans + modulus
	return ans % modulus
n = int(input())
if n == 1:
	print(1)
else:
	m = 998244353
	ans = (n - 1) * factorialMod(n, m) % m
	k = 0
	for i in range(3, n + 1):
		k = (k + 1) * i % m
	print((ans - k) % m)


n = int(input())
last = n - 1
for i in range(3, n + 2):
	last = (last * (i - 1) - 1) % 998244353
print(last + 1)


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


n = int(input())
fac = 1
for i in range(2, n + 1):
	fac = fac * i % 998244353
total = (n - 1) * fac % 998244353
dsum = 0
diff = 1
for i in range(0, n - 2):
	diff = diff * (n - i) % 998244353
	dsum += diff % 998244353
answer = (total - dsum) % 998244353
if n == 1:
	print(1)
else:
	print(answer)


def main():
	n = int(input())
	if n == 1:
		print(1)
		return
	total = 0
	mod = 998244353
	p = 1
	got = 0
	for i in range(n, 1, -1):
		p *= i
		p %= mod
		total += (p - got) * (n - i + 1)
		total %= mod
		got = p
	print(total)
main()


n = int(input())
permut = n
n += 1
for cursuf in range(2, n):
	permut = (permut - 1) * cursuf % 998244353
print(permut)


n = int(input())
if n == 1:
	print(1)
	exit(0)
if n == 2:
	print(2)
	exit(0)
a = []
n += 1
a.append(9)
iter = 1
nn = 4
m = 6
for i in range(nn, n):
	m *= i
	m %= 998244353
	a.append((a[iter - 1] - 1) * nn + m)
	a[iter] %= 998244353
	nn += 1
	iter += 1
print(a[iter - 1])


import sys
from bisect import bisect_right as rb
from collections import deque
from queue import PriorityQueue
from math import *
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
mod = 998244353
n = ii()
ans = n
for i in range(2, n + 1):
	ans = (ans - 1) * i % mod
print(ans)


n = int(input())
if n == 1:
	print(1)
elif n == 2:
	print(2)
else:
	(res, x) = (1, n * 2)
	for i in range(3, n + 1):
		res = ((res + i - 1) * i - (i - 1)) % 998244353
		x = x * i % 998244353
	result = x - res - n + 1
	if result < 0:
		print(998244353 + result)
	else:
		print(result)


n = int(input())
dp = [0] * (n + 1)
dp[1] = 1
f = 1
for i in range(2, n + 1):
	f *= i
	f %= 998244353
	dp[i] = dp[i - 1] * i + f - i
	dp[i] %= 998244353
print(dp[n])


n = int(input())
(ans, m) = (n, 998244353)
for i in range(n):
	ans *= i + 1
	if ans > m:
		ans %= m
cur = n
for i in range(1, n):
	ans -= cur
	if ans < 0:
		ans %= m
	cur *= n - i
	if cur > m:
		cur %= m
print(ans)


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


n = int(input())
m = 998244353
(p, p_, mul) = (1, 0, n)

def getp():
	global p, p_, mul
	p_ = p
	p = p * mul % m
	mul -= 1
	return (p - p_ + m) % m
ans = 1 + sum([i * getp() for i in range(1, n)])
print(ans % m)


mod = 998244353
n = int(input())
ans = n
for i in range(2, n + 1):
	ans = (ans - 1) * i % mod
print(ans)


mod = 998244353
n = int(input())
ans = n
val = n
temp = n - 1
count = 2
sumx = n
for i in range(n - 2):
	val = val % mod * (temp % mod) % mod
	lol = ((val % mod - sumx % mod) % mod + mod) % mod
	lol = lol % mod * (count % mod) % mod
	ans = (ans % mod + lol % mod) % mod
	sumx = val % mod
	temp -= 1
	count += 1
print(ans)


import sys
n = int(input())
M = 998244353

def mod(n, m):
	if n >= 0:
		return n % m
	else:
		n = n % m
		return (m + n) % m
if n > 1:
	fact = 2
	ans = [0 for i in range(n + 1)]
	ans[2] = 0
	for i in range(3, n + 1):
		ans[i] = i * (fact + ans[i - 1] - 1) % M
		fact = fact * i % M
	sys.stdout.write(str((ans[n] + fact) % M) + '\n')
else:
	sys.stdout.write('1\n')


mod = 998244353
n = int(input())
if n == 1:
	print(1)
	exit()
if n == 2:
	print(2)
	exit()
l = [None] * (n + 1)
l[1] = 1
l[2] = 2
l[3] = 9
f = 6
for i in range(4, n + 1):
	f = f * i % mod
	l[i] = f % mod + i * (l[i - 1] - 1) % mod
print(l[n] % mod)


from sys import stdin
input = lambda : stdin.readline().strip()
lin = lambda : list(map(int, input().split()))
iin = lambda : int(input())
main = lambda : map(int, input().split())
from math import ceil, sqrt, factorial, log
from collections import deque
from bisect import bisect_left
mod = 998244353

def gcd(a, b):
	(a, b) = (max(a, b), min(a, b))
	while a % b != 0:
		(a, b) = (b, a % b)
	return b

def moduloinverse(a):
	return pow(a, mod - 2, mod)

def solve(we):
	n = int(input())
	ans = n
	for i in range(2, n + 1):
		ans = (ans - 1) * i % mod
	print(ans)
qwe = 1
for _ in range(qwe):
	solve(_ + 1)


M = 998244353

def fact(n):
	ans = 1
	for i in range(2, n + 1):
		ans *= i
		ans %= M
	return ans
n = int(input())
x = fact(n)
ans = x - n
k = n
for i in range(1, n + 1):
	ans += x - k * (n - i)
	ans %= M
	k *= n - i
	k %= M
print(ans)


MOD = 998244353
n = int(input())
a = [1] * (n + 1)
b = [1] * (n + 1)
b[n] = n
for i in range(1, n + 1):
	a[i] = a[i - 1] * i % MOD
i = n - 1
while i > 0:
	b[i] = b[i + 1] * i % MOD
	i -= 1
i = n - 1
j = n
s = a[n]
while i > 1:
	s = (s + (a[i] - 1) * b[j] % MOD) % MOD
	i -= 1
	j -= 1
print(s)


m = 998244353
n = int(input())
fact = 1
for i in range(2, n + 1):
	fact *= i
	fact %= m
ans = fact
k = 1
for i in range(n, 1, -1):
	k *= i
	k %= m
	ans += (fact - k) % m
	ans %= m
print(ans)


n = int(input())
mod = 998244353
rev = []
cur = 1
s = 0
for i in range(n, 0, -1):
	cur *= i
	tmp = cur - s
	s += tmp
	s %= mod
	cur %= mod
	rev.append(tmp % mod)
ans = 1
for i in range(1, n + 1):
	ans *= i
	ans %= mod
for i in range(1, n - 1):
	ans += i * rev[i]
	ans %= mod
print(ans)


modr = 998244353
n = int(input())
fact = 1
for i in range(1, n + 1):
	fact = fact * i % modr
res = n * fact % modr
rfact = n
for i in range(n - 1, 0, -1):
	res = (res + modr - rfact) % modr
	rfact = rfact * i % modr
print(res)