//vanitas vanitatum et omnia vanitas #include #define fi first #define se second #define eb emplace_back #define mp make_pair using namespace std; typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef __int128 i128; template T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);} template T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);} template bool chmax(T &a,const S b) {return (a bool chmin(T &a,const S b) {return (a>b?a=b,1:0);} int popcnt(int x) {return __builtin_popcount(x);} int popcnt(ll x) {return __builtin_popcountll(x);} int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));} int topbit(ll x) {return (x==0?-1:63-__builtin_clzll(x));} int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));} int lowbit(ll x) {return (x==0?-1:__builtin_ctzll(x));} #define int long long #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define per(i,a,b) for(int i=(a);i>=(b);i--) typedef pair pii; typedef vector vi; typedef vector vp; typedef tuple tiii; int read() { int x=0,w=1; char c=getchar(); while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();} while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();} return x*w; } const int N=2e5+5,mod=998244353; int n,f[N],id[N],m,dfn[N],sz[N],son[N],top[N],tick,fa[N],d[N],ans,s[N]; vi e[N],t[N]; int find(int i) {return i==id[i]?i:id[i]=find(id[i]);} int lb(int x) {return x&-x;} void add(int x,int y=0) {for(;x<=n;x+=lb(x)) s[x]=(s[x]+y)%mod;} int qry(int x,int y=0) {for(;x;x-=lb(x)) y=(y+s[x])%mod; return y;} int sum(int u,int v) {return (qry(dfn[u])+mod-qry(dfn[v]))%mod;} void dfs1(int u) { for(int v:t[u]) { d[v]=d[u]+1; dfs1(v); if(sz[v]>sz[son[u]]) son[u]=v; sz[u]+=sz[v]; } sz[u]++; } void dfs2(int u,int tp) { top[u]=tp; dfn[u]=++tick; if(son[u]) dfs2(son[u],tp); for(int v:t[u]) if(v!=son[u]) dfs2(v,v); } int lca(int u,int v) { for(;top[u]!=top[v];u=fa[top[u]]) if(d[top[u]]v) swap(u,v); e[v].eb(u); } rep(i,1,n) id[i]=i; rep(i,1,n) { for(int j:e[i]) { j=find(j); if(j==i) continue; t[i].eb(j); id[j]=i; fa[j]=i; } } dfs1(n), dfs2(n,n); rep(i,1,n) { sort(e[i].begin(),e[i].end()); if(e[i].size()) { f[i]=sum(e[i][0],i); int k=e[i].size(); rep(j,1,k-1) f[i]=(f[i]+sum(e[i][j],lca(e[i][j],e[i][j-1])))%mod; } f[i]=(f[i]+1)%mod; add(dfn[i],f[i]), add(dfn[i]+sz[i],mod-f[i]); } rep(i,1,n) ans=(ans+f[i])%mod; printf("%lld\n",ans); return 0; }