Score : 1100 points
Problem Statement
Given is a sequence of N positive integers X=(X1,X2,…,XN).
For a positive integer K, let f(K) be the number of triples of integers (a,b,c) that satisfy all of the following conditions.
- 1≤c≤K.
- 0≤a<c and 0≤b<c.
- For each i, let Yi be the remainder when aXi+b is divided by c. Then, Y1<Y2<⋯<YN holds.
It can be proved that the limit K→∞limK3f(K) exists. Find this value modulo 998244353 (see Notes).
Notes
We can prove that the limit in question is always a rational number. Additionally, under the Constraints of this problem, when that number is represented as QP using two coprime integers P and Q, we can prove that there is a unique integer R such that R×Q≡P(mod998244353) and 0≤R<998244353. Find this R.
Constraints
- 2≤N≤103
- Xi are positive integers such that ∑i=1NXi≤5×105.
- Xi=Xj if i=j.
Input is given from Standard Input in the following format:
N
X1 X2 … XN
Output
Print K→∞limK3f(K) modulo 998244353.
- For example, when (a,b,c)=(3,5,7), we have Y1=0, Y2=1, Y3=4, which satisfy Y1<Y2<Y3.
- We have f(1)=0, f(2)=0, f(3)=1, f(4)=2, f(5)=5.
- We have K→∞limK3f(K)=241.
We have K→∞limK3f(K)=100855 .
We have K→∞limK3f(K)=61.
We have K→∞limK3f(K)=0.