#P1792F2. Graph Coloring (hard version)

    ID: 8180 Type: RemoteJudge 5000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 10 Uploaded By: Tags>brute forcecombinatoricsdivide and conquerdpfftgraphs*2900

Graph Coloring (hard version)

No submission language available for this problem.

Description

The only difference between the easy and the hard version is the constraint on nn.

You are given an undirected complete graph on nn vertices. A complete graph is a graph where each pair of vertices is connected by an edge. You have to paint the edges of the graph into two colors, red and blue (each edge will have one color).

A set of vertices SS is red-connected if, for every pair of vertices (v1,v2)(v_1, v_2) such that v1Sv_1 \in S and v2Sv_2 \in S, there exists a path from v1v_1 to v2v_2 that goes only through red edges and vertices from SS. Similarly, a set of vertices SS is blue-connected if, for every pair of vertices (v1,v2)(v_1, v_2) such that v1Sv_1 \in S and v2Sv_2 \in S, there exists a path from v1v_1 to v2v_2 that goes only through blue edges and vertices from SS.

You have to paint the graph in such a way that:

  • there is at least one red edge;
  • there is at least one blue edge;
  • for each set of vertices SS such that S2|S| \ge 2, SS is either red-connected or blue-connected, but not both.

Calculate the number of ways to paint the graph, and print it modulo 998244353998244353.

The first (and only) line contains one integer nn (3n51043 \le n \le 5 \cdot 10^4).

Print one integer — the number of ways to paint the graph, taken modulo 998244353998244353.

Input

The first (and only) line contains one integer nn (3n51043 \le n \le 5 \cdot 10^4).

Output

Print one integer — the number of ways to paint the graph, taken modulo 998244353998244353.

Sample Input 1

3

Sample Output 1

6

Sample Input 2

4

Sample Output 2

50

Sample Input 3

100

Sample Output 3

878752271

Sample Input 4

1337

Sample Output 4

520628749

Sample Input 5

42013

Sample Output 5

906821221