Richard wants to demonstrate that there are things far worse than Fenwick in terms of things to remember, and the first example he gave was heap Dijkstra.
To demonstrate this, he wants a problem that has many edges, but doesn't benefit too much from fast I/O. So a natural candidate is https://szkopul.edu.pl/problemset/problem/ROXsaseQWYR11jbNvCgM19Er/site/?key=statement.
The algorithm in that problem is basically to construct a graph on the modulus against
Your job will be to solve this problem with some tuned bounds.
Input Specification
The first line contains a single integer,
You may assume
Furthermore,
Output Specification
Let
It is guaranteed that
Sample Input
6
10
1
11
22
33
478154081019
Sample Output
1
Comments