Problem:
Fortune Telling
Your fortune is to be told by a famous fortune teller. She has a number of tarot cards and a six-sided die. Using the die, she will choose one card as follows and that card shall tell your future.
Initially, the cards are lined up in a row from left to right. The die is thrown showing up one of the numbers from one through six with equal probability. When $x$ is the number the die shows up, the $x$-th card from the left and every sixth card following it, i.e., the ($x + 6k$)-th cards for $k = 0, 1, 2, . . .$, are removed and then remaining cards are slid left to eliminate the gaps. Note that if the number of cards remaining is less than $x$, no cards are removed. This removing and sliding procedure is repeated until only one card remains.
Figure G.1 illustrates how cards are removed and slid when the die shows up two.
Figure G.1. Removing and sliding cards
You are given the number of initial tarot cards. For each card initially placed, compute the probability that the card will remain in the end.
Input
The input is a single line containing an integer $n$, indicating the number of tarot cards, which is between $2$ and $3 \times 10^5$, inclusive.
Output
Output $n$ lines, the $i$-th of which should be an integer that is determined, as follows, by the probability of the $i$-th card from the left to remain in the end.
It can be proved that the probability is represented as an irreducible fraction $a/b$, where $b$ is not divisible by a prime number $998 244 353 = 2^{23} \times 7 \times 17 + 1$. There exists a unique integer $c$ such that $bc ≡ a (\mod 998 244 353)$ and $0 \leq c < 998 244 353$. What should be output is this integer $c$.
Sample Input 1
3
Sample Output 1
332748118
332748118
332748118
Sample Input 2
7
Sample Output 2
305019108
876236710
876236710
876236710
876236710
876236710
305019108
Sample Input 3
8
Sample Output 3
64701023
112764640
160828257
160828257
160828257
160828257
112764640
64701023
For Sample Input 1, the probabilities to remain in the end for all the cards are equal, that are $1/3$.
For Sample Input 2, let us consider the probability of the leftmost card to remain in the end. To make this happen, the first number the die shows up should not be one. After getting a number other than one, six cards will remain. Each of these six cards will remain in the end with the same probability. From this observation, the probability of the leftmost card to remain in the end is computed as $(5/6) \times (1/6) = 5/36$. The same argument holds for the rightmost card. As for the rest of the cards, the probabilities are equal, and they are $(1 − 2 \times 5/36)/5 = 13/90$.

Submitted solutions:

code_snippet: #include <bits/stdc++.h>

#define SPED                                                                                                           \
    ios_base::sync_with_stdio(false);                                                                                  \
    cin.tie(0);                                                                                                        \
    cout.tie(0);

#define endl "\n"
#define fi first
#define se second
#define lint long long
#define fami signed
#define lore main
#define freefire freopen

const lint INF = 0x1f1f1f1f1f1f1f1f;
const lint NEG = 0xE1E1E1E1E1E1E1E1;
const lint mod = 998244353;

using namespace std;

int n;

lint binpow(lint x, lint k)
{
    if (k == 0)
        return 1;
    lint temp = binpow(x, k >> 1);
    temp *= temp;
    temp %= mod;
    if (k & 1)
    {
        temp *= x;
        temp %= mod;
    }
    return temp;
}

lint inv6 = binpow(6, mod - 2);
unordered_map<lint, lint> dp[300005];

lint solve(lint z, lint k)
{
    if (dp[z].find(k) != dp[z].end())
        return dp[z][k];
    else if (z <= 6)
        return dp[z][k] = binpow(z, mod - 2);

    lint sum = dp[z][k];
    for (int i = 0; i < 6; i++)
    {
        if ((k - i) % 6 == 0)
            continue;

        lint _z = z - (z / 6) - (i < z % 6);
        lint _k = k - (k / 6) - (i < k % 6);

        sum += inv6 * solve(_z, _k);
        sum %= mod;
    }
    return dp[z][k] = sum;
}

fami lore()
{
    SPED;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cout << solve(n, i) << endl;
    }
}
// Giai thich code cho toi
accuracy: 1
time_ms: 2570
memory_kb: 324752
final_rank: 19

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define mod 998244353
#define nmax 300007
#define fi first
#define se second
#define ll long long
int n,i;
ll h[10];
unordered_map<int,int>f[nmax];
ll power(ll n,ll k)
{
    if(k==0)return 1;
    ll tam=power(n,k/2);
    if(k%2==0)return (tam*tam)%mod;
    return (((tam*tam)%mod)*n)%mod;
}
ll sus(ll n,ll k)
{
    if(n<=6)return h[n];
    if(f[n].find(k)!=f[n].end())return f[n][k];
    int hi=k%6;
    if(hi==0)hi=6;
    ll s=0;
    for(int j=1;j<hi;++j)
    {
        s+=sus(n-(n-j+6)/6,k-(k-j+6)/6);
    }
    for(int j=hi+1;j<=6;++j)
    {
        s+=sus(n-(n-j+6)/6,k-(k-j+6)/6);
    }
    s=(s*h[6])%mod;
    return f[n][k]=s;
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    for(i=1;i<=6;++i)
    {
        h[i]=power(i,mod-2);
    }
    for(i=1;i<=n;++i)
    {
        cout<<sus(n,i)<<"\n";
    }
}
accuracy: 1
time_ms: 2520
memory_kb: 324884
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define ii pair<int,int>
#define ve vector
#define all(x) x.begin(), x.end()
#define fo(i,a,b) for (int i=(a); i<=(b); ++i)
#define fd(i,a,b) for (int i=(a); i>=(b); --i)
#define maxi(a, b) a = max(a, b)
#define mini(a, b) a = min(a, b)
#define _ << ' ' << 

const int N = 3e5+5, inf = 1e9+10, mod = 998244353;

/*

*/

struct node {
    node *son[10];
    int val; bool oc;
    node() {
        val=0; oc=0;
        fo(i,0,9) son[i]=NULL;
    }
    node *getc(int i) {
        if (!son[i]) son[i]=new node();
        return son[i];
    }
    void upd(int num, int x) {
        if (num == 0) {
            oc=1;
            val = x;
            return;
        }
        getc(num%10)->upd(num/10,x);
    }
    int get(int num) {
        return (num == 0 ? val : getc(num%10)->get(num/10));
    }
    bool Oc(int num) {
        if (num == 0) return oc;
        return getc(num%10)->Oc(num/10);
    }
};

int pw(int a, int b) {
    int res = 1;
    for (; b; b>>=1, a=1ll*a*a%mod)
        if (b&1) res=1ll*res*a%mod;
    return res;
}

int calinv(int x) {
    return pw(x, mod-2);
}
int del(int n, int i) {
    return n - (n - i) / 6 - 1;
}

int inv[N];
node mem[N];

int rec(int n, int k) {
    if (n <= 6) return inv[n];
    if (mem[n].Oc(k)) return mem[n].get(k);
    int res = 0;
    fo(i,1,6) if (i%6!=k%6) {
        int nk = del(k, i);
        if(k < i) nk = k;
        res += 1ll * inv[6] * rec(del(n, i), nk) % mod;
        if (res >= mod) res -= mod;
    }
    mem[n].upd(k,res);
    return res;
}

int n;
void sol() {
    cin >> n;
    fo(i,0,n) inv[i]=calinv(i);
    fo(i,1,n) cout << rec(n,i) << '\n';
}

signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    if(fopen("A.inp","r")) {
        freopen("A.inp","r",stdin);
        freopen("A.out","w",stdout);
    }
    int tc = 1; // cin >> tc;
    fo(i,1,tc) sol();
    return 0;
}
accuracy: 1
time_ms: 2100
memory_kb: 734700
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) begin(v), end(v)
#define len(x) ((int)size(x))
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T>
using VV = V<V<T>>;
template <class T, class U>
inline bool chmin(T &a, U b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
constexpr int INF = 1001001001;
vector<ll> dp[300010];
constexpr int mod = 998244353;
ll inv[7];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    inv[1] = 1;
    inv[2] = 499122177;
    inv[3] = 332748118;
    inv[4] = 748683265;
    inv[5] = 598946612;
    inv[6] = 166374059;
    int n;
    cin >> n;
    vector<bool> f(n + 1);
    queue<int> que;
    que.push(n);
    f[n] = true;
    while (que.size()) {
        int v = que.front();
        que.pop();
        if (v == 1) continue;
        vector<int> to;
        to.push_back(v - v / 6);
        if (v % 6) to.push_back(v - v / 6 - 1);
        for (int u : to) {
            if (!f[u]) que.push(u), f[u] = true;
        }
    }
    for (int v = 1; v <= n; v++) {
        if (!f[v]) continue;
        dp[v].resize(v);
        if (v == 1) {
            dp[1][0] = 1;
            continue;
        }
        rep(p, min(6, v)) {
            int nsz = v - v / 6 - (p < v % 6);
            rep(i, v) {
                if (i % 6 == p) continue;
                int pre = i / 6 + (p < i % 6);
                dp[v][i] += dp[nsz][i - pre];
            }
        }
        rep(i, v)(dp[v][i] *= inv[min(6, v)]) %= mod;
    }
    rep(i, n) cout << dp[n][i] << "\n";
}
accuracy: 1
time_ms: 90
memory_kb: 66356
final_rank: 5

code_snippet: // AOJ #1450 Fortune Telling
// 2025.3.29

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int Cin() {
	int n = 0; int c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void Cout(int n) {
	char b[30];
	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		int i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

const int MOD = 998244353;

ll modPow(ll a, ll b) {
    ll res = 1;
    a %= MOD;
    while(b > 0) {
        if(b & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}

ll modInv(ll x) { return modPow(x, MOD - 2); }

vector<int> dp[3 << 17];

void solve(int N) {
    if (!dp[N].empty()) return;
    dp[N].assign(N, 0);
    for (int x = 0; x < 6; x++) {
        int newSize = N - ((N - x + 5) / 6);
        solve(newSize);
        for (int i = 0; i < N; i++) {
            if (i % 6 == x) continue;
            int newIndex = i - ((i - x + 5) / 6);
            dp[N][i] = (dp[N][i] + dp[newSize][newIndex]) % MOD;
        }
    }
    int inv6 = (int) modInv(6);
    for (int i = 0; i < N; i++) dp[N][i] = (int)((1LL * dp[N][i] * inv6) % MOD);
}

int main() {
    for (int n = 1; n <= 6; n++) dp[n] = vector<int>(n, (int) modInv(n));

    int N = Cin();
    solve(N);
    for (int i = 0; i < N; i++) Cout(dp[N][i]);
    return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 40484
final_rank: 1

code_snippet: #include<iostream>
#include<string>
#include<utility>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include <random>
using namespace std;
using ll= long long;
#define rep(i,n) for(ll i=0; i<ll(n); i++)
#define repr(i,n) for(ll i=(n)-1; i>=0; i--)
template<class T> void chmin(T& l, T r){ if(r < l) l = r; }
template<class T> void chmax(T& l, T r){ if(l < r) l = r; }


const int MOD = 998244353;
const int inv6 = 332748118 / 2;


void testcase(){
    ll N; cin >> N;
    vector<vector<ll>> dp(N+1);
    for(ll f=1; f<=5 && f<=N; f++){
        ll t = 1;
        while(t%f != 0) t += MOD;
        dp[f].assign(f, t/f);
    }
    auto rec = [&](auto& rec, ll x) -> void {
        if(!dp[x].empty()) return;
        rec(rec, x-x/6);
        rec(rec, x-(x+5)/6);
        vector<ll> a(x);
        rep(f,6){
            ll q = x - (x + (5-f)) / 6;
            ll p = 0;
            rep(i,q){
                if(p % 6 == f) p++;
                a[p] += dp[q][i];
                p++;
            }
        }
        rep(i,x) a[i] = a[i] * inv6 % MOD;
        swap(dp[x], a);
    };
    rec(rec, N);
    rep(i,N) cout << dp[N][i] << "\n";
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    testcase();
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 66308
final_rank: 3

code_snippet: #include<iostream>
#include<string>
#include<utility>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include <random>
using namespace std;
using ll= long long;
#define rep(i,n) for(ll i=0; i<ll(n); i++)
#define repr(i,n) for(ll i=(n)-1; i>=0; i--)
template<class T> void chmin(T& l, T r){ if(r < l) l = r; }
template<class T> void chmax(T& l, T r){ if(l < r) l = r; }


const int MOD = 998244353;
const int inv6 = 332748118 / 2;


void testcase(){
    ll N; cin >> N;
    vector<vector<ll>> dp(N+1);
    for(ll f=1; f<=5 && f<=N; f++){
        ll t = 1;
        while(t%f != 0) t += MOD;
        dp[f].assign(f, t/f);
    }
    auto rec = [&](auto& rec, ll x) -> void {
        if(!dp[x].empty()) return;
        rec(rec, x-x/6);
        rec(rec, x-(x+5)/6);
        vector<ll> a(x);
        rep(f,6){
            ll q = x - (x + (5-f)) / 6;
            ll p = 0;
            rep(i,q){
                if(p % 6 == f) p++;
                a[p] += dp[q][i];
                p++;
            }
        }
        rep(i,x) a[i] = a[i] * inv6 % MOD;
        swap(dp[x], a);
    };
    rec(rec, N);
    rep(i,N) cout << dp[N][i] << "\n";
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    testcase();
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 66512
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define FOR(i,l,r) for(ll i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define sz(A) (ll)(A.size())
const ll mod=998244353;
ll pow_mod(ll a,ll n){
    ll res=1;a%=mod;
    while(n){
        if(n%2)res=res*a%mod;
        a=a*a%mod;n/=2;
    }
    if(res<0)res+=mod;
    return res;
}
ll inv_mod(ll a){return pow_mod(a,mod-2);}
int main(){
    ll N;cin>>N;
    vector<bool>A(N+1);
    A[N]=1;
    for(ll i=N;i;i--)if(A[i]){
        A[i-i/6]=1;
        A[i-(i+5)/6]=1;
    }
    vi B;
    FOR(i,1,N+1)if(A[i])B.emplace_back(i);
    vvi DP(sz(B),vi(N));
    ll p=inv_mod(6);
    REP(i,sz(B)){
        ll n=B[i];
        if(n<=6){
            REP(j,n)DP[i][j]=inv_mod(n);
            continue;
        }
        ll a=lower_bound(B.begin(),B.end(),n-n/6)-B.begin();
        ll b=lower_bound(B.begin(),B.end(),n-(n+5)/6)-B.begin();
        REP(j,n){
            REP(k,6)if(j%6!=k){
                DP[i][j]+=DP[n%6>k?b:a][j-(j-k+6)/6];
            }
            DP[i][j]*=p;
            DP[i][j]%=mod;
        }
    }
    REP(i,N)cout<<DP.back()[i]<<endl;
    return 0;
}
accuracy: 1
time_ms: 460
memory_kb: 755492
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

constexpr ll MOD = 998244353;

constexpr ll inv(ll x) {
  ll e = MOD - 2;
  ll ans = 1;
  for (; e; x = x * x % MOD, e /= 2)
    if (e & 1) ans = ans * x % MOD;
  return ans;
}

constexpr ll INVs[7] = {0, inv(1), inv(2), inv(3), inv(4), inv(5), inv(6)};

ll f(ll x, ll k) { return x - (x / 6) - ll(k < x % 6); }

ll toHash(ll n, ll x) { return n * ll(1e6) + x; }

unordered_map<ll, ll> memo;
ll solve(ll n, ll x) {
  assert(0 <= x && x < n);
  if (n == 1) return 1;
  ll ha = toHash(n, x);
  if (memo.count(ha)) return memo[ha];
  ll res = 0;
  int cnt = 0;
  rep(k, 0, 6) {
    if (n <= k) continue;
    cnt++;
    if (x % 6 == k) continue;
    res += solve(f(n, k), f(x, k));
  }
  res %= MOD;
  res *= INVs[cnt];
  res %= MOD;
  return memo[ha] = res;
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  ll n;
  cin >> n;
  rep(x, 0, n) cout << solve(n, x) << endl;

  return 0;
}
accuracy: 1
time_ms: 2470
memory_kb: 286448
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep2(i, n) for (ll i = 0; i < (n); i++)
#define rep3(i, a, b) for (ll i = a; i < (b); i++)
#define overload(a, b, c, d, ...) d
#define rep(...) overload(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(a) begin(a), end(a)
#define sz(a) ssize(a)
bool chmin(auto& a, auto b) {
    return a > b ? a = b, 1 : 0;
}
bool chmax(auto& a, auto b) {
    return a < b ? a = b, 1 : 0;
}

constexpr ll mod = 998244353;

ll modpow(ll base, ll exp) {
    ll res = 1;
    for (; exp > 0; exp >>= 1) {
        if (exp & 1) {
            res *= base;
            res %= mod;
        }
        base *= base;
        base %= mod;
    }
    return res;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);

    array<ll, 10> inv;
    inv.fill(0);
    rep(i, 1, 10) inv[i] = modpow(i, mod - 2);

    int n;
    cin >> n;

    auto F = [](int n, int k) {
        int m = n / 6;
        int r = n % 6;
        return n - (m + (k < r));
    };

    auto C = [&](int n, int p) {
        constexpr int N = 10000000;
        return (ll)n * N + p;
    };

    // rep(i, 1, 11) rep(k, 6) cerr << F(i, k) << " \n"[k + 1 == 6];

    unordered_map<ll, ll> memo;
    // n := num of card
    // p := position (0index)
    auto dfs = [&](auto&& self, int n, int p) -> ll {
        if (n <= 6) return inv[n];
        auto key = C(n, p);
        if (memo.contains(key)) return memo[key];
        ll res = 0;
        rep(k, 0, 6) {
            if (p % 6 == k) continue;
            res += self(self, F(n, k), F(p, k)) * inv[6] % mod;
            if (res >= mod) res -= mod;
        }
        return memo[key] = res;
    };
    rep(i, n) cout << dfs(dfs, n, i) << '\n';
}
accuracy: 1
time_ms: 1870
memory_kb: 331132
final_rank: 10

code_snippet: // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define overload3(a, b, c, name, ...) name
#define rep3(i, a, b) for (long i = (a); i < (b); i++)
#define rep2(i, n) rep3(i, 0, n)
#define rep1(n) rep2(i, n)
#define rep(...) overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
#define per3(i, a, b) for (long i = (b) - 1; i >= (a); i--)
#define per2(i, n) per3(i, 0, n)
#define per1(n) per2(i, n)
#define per(...) overload3(__VA_ARGS__, per3, per2, per1)(__VA_ARGS__)
#define vec vector
#undef long
#define long long long
using ll = long;
template <typename T> bool chmin(T &x, T y) {
	if (y < x) {
		x = y;
		return true;
	}
	return false;
}
template <typename T> bool chmax(T &x, T y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}
// #undef cerr
// #define cerr  if (0)   cerr
constexpr long mod = 998244353;
long modpow(long a, long b) {
	if (b == 0)
		return 1;
	if (b % 2)
		return a * modpow(a, b - 1) % mod;
	return modpow(a * a % mod, b / 2);
}
long inv[7];
unordered_map<long, long> mp;
constexpr long inf = 3e5 + 2022;
long to_key(long x, long y) { return x * inf + y; }
long f(int i, int j) {
	// cerr << i << " " << j << endl << flush;
	// this_thread::sleep_for(std::chrono::seconds(1));
	if (i <= 6)
		return inv[i];
	const long key = to_key(i, j);
	if (mp.count(key))
		return mp[key];
	long ans = 0;
	rep(c, 6) {
		if (c == j % 6)
			continue;
		ans += f(i - (i + 6 - c - 1) / 6, j - (j + 6 - c - 1) / 6);
	}
	ans %= mod, ans *= inv[6], ans %= mod;
	return mp[key] = ans;
}
void solve() {
	int n;
	cin >> n;
	rep(i, 1, 7) inv[i] = modpow(i, mod - 2);
	rep(i, n) {
		long ans = f(n, i);
		if (ans < 0)
			ans += mod;
		cout << ans << '\n';
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}
accuracy: 1
time_ms: 2190
memory_kb: 286324
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
using ll = long long;
ll modpow(ll a, ll n) {
	ll r = 1, t = a;
	while (n) {
		if (n & 1) {
			r *= t;
		}
		n >>= 1;
		t *= t;
		t %= MOD;
		r %= MOD;
	}
	assert(r >= 0);
	return r;
}
ll inv(ll a) {
	return modpow(a, MOD - 2);
}
int main() {
	int n;
	cin >> n;
	auto cnt = [](int X, int d) {
		// X ikani d+6N ha ikutu?
		if (X < d) return 0;
		return (X - d) / 6 + 1;
	};
	vector<ll> preinv(7);
	for (int i = 1; i < 7; i++) {
		preinv[i] = inv(i);
	}
	vector<vector<ll>> memo(n + 1);
	vector<vector<bool>> vis(n + 1);
	auto f = [&](auto self, int x, int k) -> ll {
		assert(x >= 1 && k <= x && 1 <= k);
		if (x <= 6) return preinv[x];
		if (vis[x].size() != 0 && vis[x][k]) return memo[x][k];
		ll res = 0;
		for (int d = 1; d <= 6; d++) {
			if (((k - d) % 6 + 6) % 6 == 0) continue;
			int rem = cnt(x, d);
			int aum = cnt(k, d);
			ll ta = self(self, x - rem, k - aum);
			ta *= preinv[6];
			ta %= MOD;
			res += ta;
			res %= MOD;
		}
		if (vis[x].size() == 0) {
			vis[x].assign(x + 1, false);
			memo[x].assign(x + 1, 0);
		}
		vis[x][k] = true;
		memo[x][k] = res;
		return res;
	};

	for (int i = 0; i < n; i++) {
		// for (int i = 0; i < 1; i++) {
		cout << f(f, n, i + 1) << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 640
memory_kb: 78704
final_rank: 9

code_snippet: #include<bits/stdc++.h>
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
using namespace std;
#define ll long long
#define rep(i,j,k) for(int (i)=(j);(i)<(k);(i)++)
#define MOD 998244353

ll f(int a,int b){
	return (ll)a+(((ll)b)<<32);
}
ll inv_mod(ll a){
	ll b=MOD-2;
	ll res=1,d=a;
	while(b!=0){
		if(b&1){
			res*=d;
			res%=MOD;
		}
		d*=d;
		d%=MOD;
		b>>=1;
	}
	return res;
}
ll s=inv_mod(6);
unordered_map<ll,int>M;
ll solve(int l,int k){
	ll p=f(l,k);
	if(M.find(p)!=M.end())return M[p];
	if(l<=6){
		return M[p]=inv_mod(l);
	}
	ll res=0;
	
	rep(i,0,6){
		if(k%6!=i)if(i<l%6){
			if(i<k%6){
				res+=s*solve(l-(l+5)/6,k-(k+5)/6);
			}else{
				res+=s*solve(l-(l+5)/6,k-(k)/6);
			}
		}else{
			if(i<k%6){
				res+=s*solve(l-(l)/6,k-(k+5)/6);
			}else{
				res+=s*solve(l-(l)/6,k-(k)/6);
			}
		}
		res%=MOD;
	}
	return M[p]=res;
}
int main()
{
	ll N;
	cin>>N;
	rep(i,0,N){
		cout<<solve(N,i)<<endl;
	}
	return 0;
}
accuracy: 1
time_ms: 2070
memory_kb: 331116
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;

const ll MOD = 998244353;
ll ModPow(ll a, ll n){
	ll ret = 1;
	while(n){
		if(n&1) (ret *= a) %= MOD;
		(a *= a) %= MOD;
		n /= 2;
	}
	return ret;
}

int main(){
	int N; cin >> N;

	unordered_map<ll, ll> memo;
	ll inv = ModPow(6, MOD-2);
	auto rec = [&](auto&& rec, int all, int pos)->ll{
		if(all <= 6) return ModPow(all, MOD-2);
		if(memo.count(((ll)all << 31)+ pos)) return memo[((ll)all << 31)+ pos];

		ll ret = 0;
		for(int i=0; i<6; i++){
			if(i == pos%6) continue;
			int nxt_all = all - all/6;
			if(i < all%6) nxt_all--;
			int nxt_pos = pos - pos/6;
			if(i < pos%6) nxt_pos--;

			//printf("(%d, %d), %d -> (%d, %d)\n", all, pos, i, nxt_all, nxt_pos);

			(ret += (inv * rec(rec, nxt_all, nxt_pos))) %= MOD;
		}

		return memo[((ll)all << 31)+ pos] = ret;
	};

	for(int i=0; i<N; i++) cout << rec(rec, N, i) << '\n';
}
accuracy: 1
time_ms: 2260
memory_kb: 286340
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;

const ll MOD = 998244353;
ll ModPow(ll a, ll n){
	ll ret = 1;
	while(n){
		if(n&1) (ret *= a) %= MOD;
		(a *= a) %= MOD;
		n /= 2;
	}
	return ret;
}

int main(){
	int N; cin >> N;

	vector<vector<ll>> memo(N+1);
	ll inv = ModPow(6, MOD-2);
	auto rec = [&](auto&& rec, int all, int pos)->ll{
		if(memo[all].size()>pos && memo[all][pos] != -1) return memo[all][pos];
		if(memo[all].size()==0) memo[all].resize(all, -1);
		if(all <= 6) return memo[all][pos] = ModPow(all, MOD-2);

		ll ret = 0;
		for(int i=0; i<6; i++){
			if(i == pos%6) continue;
			int nxt_all = all - all/6;
			if(i < all%6) nxt_all--;
			int nxt_pos = pos - pos/6;
			if(i < pos%6) nxt_pos--;

			//printf("(%d, %d), %d -> (%d, %d)\n", all, pos, i, nxt_all, nxt_pos);

			(ret += (inv * rec(rec, nxt_all, nxt_pos))) %= MOD;
		}

		return memo[all][pos] = ret;
	};

	for(int i=0; i<N; i++) cout << rec(rec, N, i) << '\n';
}
accuracy: 1
time_ms: 280
memory_kb: 66408
final_rank: 7

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

template <unsigned mod = 1000000007> struct fp {
    unsigned v;
    static constexpr int get_mod() {
        return mod;
    }
    constexpr unsigned inv() const {
        assert(v != 0);
        int x = v, y = mod, p = 1, q = 0, t = 0, tmp = 0;
        while (y > 0) {
            t = x / y;
            x -= t * y, p -= t * q;
            tmp = x, x = y, y = tmp;
            tmp = p, p = q, q = tmp;
        }
        if (p < 0)
            p += mod;
        return p;
    }
    constexpr fp(ll x = 0) : v(x >= 0 ? x % mod : (mod - (-x) % mod) % mod) {}
    fp operator-() const {
        return fp() - *this;
    }
    fp pow(ull t) {
        fp res = 1, b = *this;
        while (t) {
            if (t & 1)
                res *= b;
            b *= b;
            t >>= 1;
        }
        return res;
    }
    fp &operator+=(const fp &x) {
        if ((v += x.v) >= mod)
            v -= mod;
        return *this;
    }
    fp &operator-=(const fp &x) {
        if ((v += mod - x.v) >= mod)
            v -= mod;
        return *this;
    }
    fp &operator*=(const fp &x) {
        v = ull(v) * x.v % mod;
        return *this;
    }
    fp &operator/=(const fp &x) {
        v = ull(v) * x.inv() % mod;
        return *this;
    }
    fp operator+(const fp &x) const {
        return fp(*this) += x;
    }
    fp operator-(const fp &x) const {
        return fp(*this) -= x;
    }
    fp operator*(const fp &x) const {
        return fp(*this) *= x;
    }
    fp operator/(const fp &x) const {
        return fp(*this) /= x;
    }
    bool operator==(const fp &x) const {
        return v == x.v;
    }
    bool operator!=(const fp &x) const {
        return v != x.v;
    }
    friend istream &operator>>(istream &is, fp &x) {
        return is >> x.v;
    }
    friend ostream &operator<<(ostream &os, const fp &x) {
        return os << x.v;
    }
};

template <typename T> T Inv(ll n) {
    static const int md = T::get_mod();
    static vector<T> buf({0, 1});
    assert(n > 0);
    n %= md;
    while (SZ(buf) <= n) {
        int k = SZ(buf), q = (md + k - 1) / k;
        buf.push_back(buf[k * q - md] * q);
    }
    return buf[n];
}

template <typename T> T Fact(ll n, bool inv = 0) {
    static const int md = T::get_mod();
    static vector<T> buf({1, 1}), ibuf({1, 1});
    assert(n >= 0 and n < md);
    while (SZ(buf) <= n) {
        buf.push_back(buf.back() * SZ(buf));
        ibuf.push_back(ibuf.back() * Inv<T>(SZ(ibuf)));
    }
    return inv ? ibuf[n] : buf[n];
}

template <typename T> T nPr(int n, int r, bool inv = 0) {
    if (n < 0 || n < r || r < 0)
        return 0;
    return Fact<T>(n, inv) * Fact<T>(n - r, inv ^ 1);
}
template <typename T> T nCr(int n, int r, bool inv = 0) {
    if (n < 0 || n < r || r < 0)
        return 0;
    return Fact<T>(n, inv) * Fact<T>(r, inv ^ 1) * Fact<T>(n - r, inv ^ 1);
}
template <typename T> T nHr(int n, int r, bool inv = 0) {
    return nCr<T>(n + r - 1, r, inv);
}

/**
 * @brief Modint
 */

using Fp = fp<998244353>;

int main() {
    int N;
    cin >> N;
    vector<vector<Fp>> ANS;
    map<int,int> mp;
    int Cur = 0;
    Fp inv6 = Fp(6).inv();
    auto DFS = [&](auto self, int X) -> void {
        if (mp.count(X)) return;
        if (X <= 6) {
            mp[X] = Cur;
            ANS.push_back(vector<Fp>(X,Fp(X).inv()));
            Cur++;
            return;
        }
        int Now = Cur;
        mp[X] = Cur;
        ANS.push_back(vector<Fp>(X,0));
        Cur++;
        rep(i,0,6) {
            self(self,X-(X-i+5)/6);
            int Next = mp[X-(X-i+5)/6];
            rep(j,0,X) {
                if (j % 6 == i) continue;
                int k = (j/6)*5 + (j%6>i ? j%6-1 : j%6);
                ANS[Now][j] += ANS[Next][k] * inv6;
            }
        }
        return;
    };
    DFS(DFS,N);
    int ID = mp[N];
    rep(i,0,N) cout << ANS[ID][i] << endl;
}
accuracy: 1
time_ms: 300
memory_kb: 31288
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (auto i = (m); i < (n); i++)
#define rept(i, n) rep(i, 0, n)
#define repr(i, m, n) for (auto i = (m); i-- > (n);)
#define reptr(i, n) repr(i, 0, n)
#define all(x) begin(x), end(x)
#define sz(x) (int)size(x)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vc = vector<char>;
using pii = pair<int, int>;

#include <ext/pb_ds/assoc_container.hpp>

vector<int> memo[300'001];

constexpr ll MOD = 998244353;

constexpr ll mpow(ll b, ll e) {
	ll res = 1;
	for (b %= MOD; e; e /= 2, b = b*b % MOD) {
		if (e % 2) res = res*b % MOD;
	}
	return res;
}

ll invs[7];

constexpr ll inv6 = mpow(6, MOD - 2);

const vi& f(int n) {
	if (!memo[n].empty()) return memo[n];
	if (n == 1) {
		return memo[n] = {1};
	}
	memo[n].resize(n);
	const int rn = n % 6;
	rept(i, n) {
		const int ri = i % 6;
		ll sum = 0;
		int self = 0;
		rept(x, 6) {
			if (x == ri) continue;
			int i2 = i - i / 6 - (ri > x);
			int n2 = n - n / 6 - (rn > x);
			if (i2 != i || n2 != n) sum += f(n2)[i2];
			else self++;
		}
		memo[n][i] = sum * invs[6 - self] % MOD;
	}
	return memo[n];
}

void solve() {
	int n; scanf("%d", &n);
	rept(i, n) printf("%lld\n", f(n)[i]);
}

int main() {
	rep(x, 1, size(invs)) invs[x] = mpow(x, MOD - 2);

	int n = 1;
	// scanf("%d", &n);
	while (n--) solve();
}
accuracy: 1
time_ms: 130
memory_kb: 38204
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

using i64 = int64_t;
using u64 = uint64_t;
constexpr i64 MOD = 998244353;

struct modint {
    u64 v;
    modint() : v(0) {}
    modint(int64_t _v) { v = _v % MOD; if (v < 0) v += MOD; }
    modint& operator+=(const modint& rhs) { v += rhs.v; if (v >= MOD) v -= MOD; return *this; }
    modint& operator-=(const modint& rhs) { v -= rhs.v; if (v >= MOD) v += MOD; return *this; }
    modint& operator*=(const modint& rhs) { v = (v * rhs.v) % MOD; return *this; }
    modint& operator/=(const modint& rhs) { return *this *= rhs.inv(); }
    friend modint operator+(modint lhs, const modint& rhs) { lhs += rhs; return lhs; }
    friend modint operator-(modint lhs, const modint& rhs) { lhs -= rhs; return lhs; }
    friend modint operator*(modint lhs, const modint& rhs) { lhs *= rhs; return lhs; }
    friend modint operator/(modint lhs, const modint& rhs) { lhs /= rhs; return lhs; }
    friend bool operator==(const modint& lhs, const modint& rhs) { return lhs.v == rhs.v; }
    friend bool operator!=(const modint& lhs, const modint& rhs) { return lhs.v != rhs.v; }
    modint pow(i64 n) const {
        modint res = 1, x = *this;
        while (n) {
            if (n & 1) res *= x;
            x *= x;
            n >>= 1;
        }
        return res;
    }
    modint inv() const { return pow(MOD - 2); }
    u64 val() const { return v; }
    static modint raw(u64 v) { modint x; x.v = v; return x; }
};

const int N = 300010;
vector<modint> dp[N];
modint den[7];

int divFloor(int a, int b) {
    if (a >= 0) return a / b;
    return (a - b + 1) / b;
}

int computeMinus(int n, int v) {
    return max(0, divFloor(n - v, 6) + 1);
}

modint rec(int remain, int front) {
    assert(1 <= remain);
    assert(1 <= front);
    assert(front <= remain);

    if (dp[remain].empty()) dp[remain].resize(remain + 1);
    if (dp[remain][front] != modint()) return dp[remain][front];

    modint &res = dp[remain][front];
    if (remain == 1 && front == 1) {
        return res = modint(1);
    }

    int count = 0;
    for (int i = 1; i <= 6; i++) {
        int sub = computeMinus(remain, i);
        if (sub == 0) continue;
        count++;
    }

    for (int i = 1; i <= 6; i++) {
        if (front % 6 == i % 6) continue;
        int sub = computeMinus(remain, i);
        if (sub == 0) continue;
        int fsub = computeMinus(front, i);
        res += rec(remain - sub, front - fsub) * den[count];
    }

    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    for (int i = 1; i <= 6; i++) den[i] = modint::raw(i).inv();

    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        modint ans = rec(n, i);
        cout << ans.val() << '\n';
    }
}
accuracy: 1
time_ms: 330
memory_kb: 66212
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define all(A) A.begin(),A.end()

vll dx = { 1,0,-1,0 };
vll dy = { 0,1,0,-1 };

const ll mod = 998244353;

vector<ll> inv(7);

unordered_map<ll, ll> M;

ll dfs(ll N, ll n) {
    if (!M.count(N*400000+n)) {
        if (N <= 6) {
            M[N*400000+n] = inv[N];
        }
        else {
            ll res = 0;
            rep(i, 6) {
                if (n % 6 == i)continue;
                ll nextN = N - (N / 6);
                if (N % 6 != 0 && N % 6> i)nextN--;
                ll nextn = n - n / 6;
                if (n % 6 > i)nextn--;
                res += dfs(nextN, nextn);
            }
           res *= inv[6];
            res %= mod;
            M[N*400000+n] = res;
        }
    }

    return M[N*400000+n];
}

int main() {

    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    for (ll i = 1; i <= 6; i++) {
        rep(k, 100) {
            if ((mod * k + 1) % i == 0) {
                inv[i] = ((mod * k + 1) / i) % mod;
                break;
            }
        }
    }
    ll N;
    cin >> N;
    rep(i, N){
        ll an=dfs(N,i);
        cout << an << "\n";
    }
}
accuracy: 1
time_ms: 2440
memory_kb: 286580
final_rank: 16

code_snippet: /**
    Author: Kristopher Paul
    Date Created: 02-06-2023
**/
#include<bits/stdc++.h>
#include<unordered_map>
//#include<stdio.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int ll
#define pb push_back
#define INF 1e18
//#define MOD 1000000007
#define MOD 998244353
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap unordered_map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // set
//typedef tree<pii,null_type,less_equal<pii>,rb_tree_tag,tree_order_statistics_node_update> pbds; // multiset

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int ModExp(int x, int y, int m){
    int res = 1;
    x = x % m;
    while (y > 0){
        if (y & 1)
            res = (res*x) % m;
        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

//map<pii,int> dp;
vector<umap<int,int> > dp(300005);

int f(int n,int idx){
    if(idx > n){
        return 0;
    }
    if(n <= 6){
        return ModExp(n,MOD-2,MOD);
    }
    if(dp[n][idx]){
        return dp[n][idx];
    }
    int val = 0;
    FOR(i,1,7){
        if((idx-i) % 6 == 0){
            continue;
        }
        int removed = ((n-i)/6) + 1;
        int new_n = n-removed;
        
        int removed_before = 0;
        if(idx >= i){
            removed_before = ((idx-i)/6) + 1;
        }
        int new_idx = idx - removed_before;
        int new_v = f(new_n,new_idx);
        new_v *= ModExp(6LL,MOD-2,MOD);
        new_v %= MOD;
        val += new_v;
        val %= MOD;
    }
    return dp[n][idx] = val;
}

void solve(){
    int n;
    cin >> n;
    if(n % 2 == 0){
        FOR(i,0,n){
            if(i >= (n/2)){
                cout << f(n,n-i) << "\n";
            }else{
                cout << f(n,i+1) << "\n";
            }
        }   
    }else{
        FOR(i,0,n){
            if(i > (n/2)){
                cout << f(n,n-i) << "\n";
            }else{
                cout << f(n,i+1) << "\n";
            }
        }   
    }
}

signed main(){
    FastIO;
    int t = 1;
//    cin >> t;
    WL(t){
        solve();
    }
}
accuracy: 1
time_ms: 2610
memory_kb: 171708
final_rank: 13