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