MOD = 998244353 n = int(input()) ans = n * pow(n - 1, n, MOD) ans -= n * (n - 1) * pow(n - 3, n - 2, MOD) print(ans % MOD)