#P1792F2. Graph Coloring (hard version)
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 .
You are given an undirected complete graph on 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 is red-connected if, for every pair of vertices such that and , there exists a path from to that goes only through red edges and vertices from . Similarly, a set of vertices is blue-connected if, for every pair of vertices such that and , there exists a path from to that goes only through blue edges and vertices from .
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 such that , is either red-connected or blue-connected, but not both.
Calculate the number of ways to paint the graph, and print it modulo .
The first (and only) line contains one integer ().
Print one integer — the number of ways to paint the graph, taken modulo .
Input
The first (and only) line contains one integer ().
Output
Print one integer — the number of ways to paint the graph, taken modulo .