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 is $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$. 

You are given $n$. Find the number of distinct subarrays of $P$. 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 distinct subarrays, modulo $998244353$.


-----Examples-----
Input
2

Output
8

Input
10

Output
19210869



-----Note-----

In the first example, the sequence $P = [1, 2, 2, 1]$. It has eight distinct subarrays: $[1]$, $[2]$, $[1, 2]$, $[2, 1]$, $[2, 2]$, $[1, 2, 2]$, $[2, 2, 1]$ and $[1, 2, 2, 1]$.

Difficulty: VERY_HARD
Tags: String algorithms

Starter code:

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)


def fact(n):
	resq = 1
	for i in range(1, n + 1):
		resq *= i
	return resq

def f(n):
	l = fact(n) * n
	ans = l * (l - n + 2) // 2
	for i in range(1, n):
		ans -= fact(n) // fact(i + 1) * n * (i * (n - i) - 1)
	return ans

def g(n):
	M = 998244353
	p = n
	a = 0
	for i in range(n, 1, -1):
		a = (a + p * (i - 1) * (n - i + 1) - p) % M
		p = p * i % M
	a = (p * (p - n + 2) - a - a) % M
	if a & 1:
		a += M
	return a // 2
print(g(int(input())))


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


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)


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)
main()


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)


(M, a) = (998244353, 0)
p = n = int(input())
for i in range(n - 1):
	(a, p) = ((a + p * (n - i - 1) * (i + 1) - p) % M, p * (n - i) % M)
a = (p * (p - n + 2) - a - a) % M
if a & 1:
	a += M
print(a // 2)
t = 0


import math

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

def f(n):
	l = factorial(n) * n
	ans = l * (l - n + 2) // 2
	for i in range(1, n):
		ans -= factorial(n) // factorial(i + 1) * n * (i * (n - i) - 1)
	return ans

def solve(n):
	M = 998244353
	p = n
	a = 0
	for i in range(n, 1, -1):
		a = (a + p * (i - 1) * (n - i + 1) - p) % M
		p = p * i % M
	a = (p * (p - n + 2) - 2 * a) % M
	if a & 1:
		a += M
	return a // 2
x = int(input())
ans = solve(x)
print(ans)


import math

def solution(n):
	MainVariable = 998244353
	p_variable = n
	Veri_A = 0
	for i in range(n, 1, -1):
		Veri_A = (Veri_A + p_variable * (i - 1) * (n - i + 1) - p_variable) % MainVariable
		p_variable = p_variable * i % MainVariable
	Veri_A = (p_variable * (p_variable - n + 2) - 2 * Veri_A) % MainVariable
	if Veri_A & 1:
		Veri_A += MainVariable
	return Veri_A // 2
input_ = int(input())
answer = solution(input_)
print(answer)


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))


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)


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)


import math

def solution(n):
	m_var = 998244353
	p_var = n
	a_var = 0
	for i in range(n, 1, -1):
		a_var = (a_var + p_var * (i - 1) * (n - i + 1) - p_var) % m_var
		p_var = p_var * i % m_var
	a_var = (p_var * (p_var - n + 2) - 2 * a_var) % m_var
	if a_var & 1:
		a_var += m_var
	return a_var // 2
x = int(input())
ans = solution(x)
print(ans)


I = 998244353

def fact1(n):
	ans1 = 1
	for i in range(2, n + 1):
		ans1 *= i
		ans1 %= I
	return ans1
n = int(input())
x = fact1(n)
ans1 = x - n
k = n
for i in range(1, n + 1):
	ans1 += x - k * (n - i)
	ans1 %= I
	k *= n - i
	k %= I
print(ans1)


import math

def poe(z):
	m = 998244353
	p = z
	a = 0
	for i in range(z, 1, -1):
		a = (a + p * (i - 1) * (z - i + 1) - p) % m
		p = p * i % m
	a = (p * (p - z + 2) - 2 * a) % m
	if a & 1:
		a = a + m
	return a // 2
f = int(input())
solution = poe(f)
print(solution)


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)


n = int(input())
sumi = 0
prod = 1
for i in range(n - 1):
	prod *= n - i
	prod %= 998244353
	sumi -= prod
sumi += n * prod
print(sumi % 998244353)


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


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])


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)


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')


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, ans, mod, r) = (int(input()), 1, 998244353, 0)
for i in range(2, n + 1):
	ans = ans * i % mod
	r = (r + 1) * i % mod
print(((ans * n - r) % mod + mod) % mod)


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


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)


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


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)


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))


import math

def solution(n):
	var1 = 998244353
	var3 = n
	var2 = 0
	for i in range(n, 1, -1):
		var2 = (var2 + var3 * (i - 1) * (n - i + 1) - var3) % var1
		var3 = var3 * i % var1
	var2 = (var3 * (var3 - n + 2) - 2 * var2) % var1
	if var2 & 1:
		var2 += var1
	return var2 // 2
x = int(input())
ans = solution(x)
print(ans)


import math

def solution(num):
	m = 998244353
	p = num
	a = 0
	for i in range(num, 1, -1):
		a = (a + p * (i - 1) * (num - i + 1) - p) % m
		p = p * i % m
	a = (p * (p - num + 2) - 2 * a) % m
	if a & 1:
		a += m
	return a // 2
x = int(input())
ans = solution(x)
print(ans)


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())
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)


def solve(n):
	M = 998244353
	p = n
	a = 0
	for i in range(n, 1, -1):
		a = (a + p * (i - 1) * (n - i + 1) - p) % M
		p = p * i % M
	a = (p * (p - n + 2) - 2 * a) % M
	if a & 1:
		a += M
	return a // 2
x = int(input())
ans = solve(x)
print(ans)


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)


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)


import math

def solution(n):
	m_variable = 998244353
	p_variable = n
	a_variable = 0
	for i in range(n, 1, -1):
		a_variable = (a_variable + p_variable * (i - 1) * (n - i + 1) - p_variable) % m_variable
		p_variable = p_variable * i % m_variable
	a_variable = (p_variable * (p_variable - n + 2) - 2 * a_variable) % m_variable
	if a_variable & 1:
		a_variable += m_variable
	return a_variable // 2
x = int(input())
ans = solution(x)
print(ans)


import math

def sol(n):
	p_var = 998244353
	s_var = n
	a_var = 0
	for i in range(n, 1, -1):
		a_var = (a_var + s_var * (i - 1) * (n - i + 1) - s_var) % p_var
		s_var = s_var * i % p_var
	a_var = (s_var * (s_var - n + 2) - 2 * a_var) % p_var
	if a_var & 1:
		a_var += p_var
	return a_var // 2
i = int(input())
out = sol(i)
print(out)


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)


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)


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


import math

def fact(n):
	for i in range(1, n + 1):
		fact = fact * i
	return fact

def f(n):
	l = fact(n) * n
	ans = l * (l - n + 2) // 2
	for i in range(1, n):
		ans -= fact(n) // fact(i + 1)
		n(i * (n - i) - 1)
	return ans

def solve(n):
	k = 998244353
	u = n
	b = 0
	for i in range(n, 1, -1):
		b = (b + u * (i - 1) * (n - i + 1) - u) % k
		u = u * i % k
	b = (u * (u - n + 2) - 2 * b) % k
	if b & 1:
		b += k
	return b // 2
x = int(input())
ans = solve(x)
print(ans)


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)


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)


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 == 1:
	print(1)
else:
	a = []
	for i in range(n):
		a.append(0)
	a[n - 1] = n
	for i in range(n - 1):
		a[n - 2 - i] = a[n - 1 - i] * (n - 1 - i) % mod
	x = n * a[1] % mod
	for i in range(n - 1):
		x = (x + mod - a[i + 1]) % mod
	print(x)


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


def obtain(x):
	Num = 998244353
	number = x
	numx = 0
	for i in range(x, 1, -1):
		numx = (numx + number * (i - 1) * (x - i + 1) - number) % Num
		number = number * i % Num
	numx = (number * (number - x + 2) - 2 * numx) % Num
	if numx & 1:
		numx += Num
	return numx // 2
input1 = int(input())
solution = obtain(input1)
print(solution)


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()


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


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)


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())
a = n
for i in range(2, n + 1):
	a = (a - 1) * i % 998244353
print(a)


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())
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)


import math

def solution(n):
	var1 = 998244353
	var3 = n
	var2 = 0
	i = n
	while i > 1:
		var2 = (var2 + var3 * (i - 1) * (n - i + 1) - var3) % var1
		var3 = var3 * i % var1
		i -= 1
	var2 = (var3 * (var3 - n + 2) - 2 * var2) % var1
	if var2 & 1:
		var2 += var1
	return var2 // 2
x = int(input())
ans = solution(x)
print(ans)


import math

class problem2:

	def solve(self):
		n = int(input())
		m = 998244353
		p = n
		a = 0
		for i in range(n, 1, -1):
			a = (a + p * (i - 1) * (n - i + 1) - p) % m
			p = p * i % m
		a = (p * (p - n + 2) - 2 * a) % m
		if a & 1:
			a += m
		return a // 2
obj = problem2()
print(obj.solve())


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)


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)


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)


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 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)


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))


import math

def fctl(n):
	for i in range(1, n + 1):
		fctl = fctl * i
	return fctl

def f(n):
	l = fctl(n) * n
	a = l * (l - n + 2) // 2
	for i in range(1, n):
		a -= fctl(n) // fctl(i + 1) * n * (i * (n - i) - 1)
	return a

def solution(n):
	M = 998244353
	p = n
	a = 0
	for i in range(n, 1, -1):
		a = (a + p * (i - 1) * (n - i + 1) - p) % M
		p = p * i % M
	a = (p * (p - n + 2) - 2 * a) % M
	if a & 1:
		a += M
	return a // 2
inp = int(input())
answer = solution(inp)
print(answer)


import math

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

def solve(n):
	p = n
	s = 0
	for i in range(n, 1, -1):
		s = (s + p * (i - 1) * (n - i + 1) - p) % 998244353
		p = p * i % 998244353
	s = (p * (p - n + 2) - 2 * s) % 998244353
	if s & 1:
		s += 998244353
	return s // 2
x = int(input())
print(solve(x))


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)


n = int(input())
mod = 998244353
FRAC = 1
INV = 0
for i in range(2, n + 1):
	FRAC = FRAC * i % mod
	INV = INV + pow(FRAC, mod - 2, mod)
print((FRAC * (n - 1) - FRAC * INV + 1) % 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)


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)


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)


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)


import math

class Solution:

	def calculate(self):
		n = int(input())
		m_variable = 998244353
		p_variable = n
		a_variable = 0
		for i in range(n, 1, -1):
			a_variable = (a_variable + p_variable * (i - 1) * (n - i + 1) - p_variable) % m_variable
			p_variable = p_variable * i % m_variable
		a_variable = (p_variable * (p_variable - n + 2) - 2 * a_variable) % m_variable
		if a_variable & 1:
			a_variable += m_variable
		return a_variable // 2
obj = Solution()
print(obj.calculate())