using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NMi => ReadLine().Split().Select(c => int.Parse(c) - 1).ToArray(); static int[][] NMap(int n) => Enumerable.Repeat(0, n).Select(_ => NMi).ToArray(); public static void Main() { Solve(); } static void Solve() { var mod = 998_244_353; var n = NN; if (n == 2) { WriteLine(0); return; } var ans = (long)n * (n - 1) % mod; var mul = (Exp(n - 2, n - 1, mod) + (n - 2) * ((Exp(n - 1, n - 2, mod) - Exp(n - 2, n - 2, mod) + mod) % mod) % mod + (Exp(n - 1, n - 2, mod) - Exp(n - 3, n - 2, mod) + mod) % mod) % mod; WriteLine(ans * mul % mod); } static long Exp(long n, long p, int mod) { long _n = n % mod; var _p = p; var result = 1L; if ((_p & 1) == 1) result *= _n; while (_p > 0) { _n = _n * _n % mod; _p >>= 1; if ((_p & 1) == 1) result = result * _n % mod; } return result; } }