#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int n;
long long c[1000010], p[1000010];
long long mul(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) {
      ans = ans * a % mod;
    }
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  long long sum = 0;
  c[0] = p[0] = 1;
  for (int i = 1; i <= n; i++) {
    c[i] = c[i - 1] * i % mod;
    p[i] = mul(c[i], mod - 2);
  }
  for (int i = 1; i <= n; i++) {
    sum = (sum +
           mul(3, (1LL * n * (n - i) + i)) % mod * mul(-1, i + 1) % mod * c[n] %
               mod * p[i] % mod * p[n - i] % mod +
           mod) %
          mod;
  }
  sum = sum * 2 % mod;
  long long t = 0;
  for (int i = 0; i < n; i++) {
    t = (t +
         c[n] % mod * p[i] % mod * p[n - i] % mod * mul(-1, i + 1) % mod *
             (mul(1 - mul(3, i), n) % mod - mul(-mul(3, i), n) % mod + mod) %
             mod +
         mod) %
        mod;
  }
  printf("%lld", (sum + t * 3) % mod);
  return 0;
}
