#include <bits/stdc++.h>   using namespace std;   const int L = 332748118, M = 998244353, N = 1e6 + 5;   int l[N];   int ksm(int a, long long b) {     int an = 1;     while (b) {       if (b & 1) an = 1ll * an * a % M;       a = 1ll * a * a % M;       b >>= 1;     }     return an;   }   int main() {     int n, c = 1, a = 0, b = 0, f = 1, s, d = 1, e, g, h;     scanf( %d , &n);     e = s = ksm(L, n);     h = g = ksm(3, 1ll * n * n);     l[1] = 1;     for (int i = 1; i <= n; i++) {       if (i != 1) l[i] = (M - 1ll * M / i * l[M % i]) % M;       c = 1ll * (n - i + 1) * l[i] % M * c % M;       d = 1ll * d * s % M;       e = 3ll * e % M;       h = 3ll * h * s % M;       a = (a + 1ll * f * c % M * h % M) % M;       b = (b + 1ll * f * c * d % M * (ksm(1 - e, n) - 1) % M) % M;       f = -f;     }     printf( %lld , (((a << 1) + 3ll * g * b) % M + M) % M);   }   