Problem Description
Given n intervals pi,qi.
Compute $\sum\limits_{s_1={p_1}}^{q_1}\sum\limits_{s_2={p_2}}^{q_2}\sum\limits_{s_3={p_3}}^{q_3} \cdots\sum\limits_{s_n={p_n}}^{q_n}\max\limits_{i=1}^ns_i$ modulo 998244353.
Line 1 contains an integer n, representing the number of intervals.
Lines 2 to (n+1) each contain two integers pi,qi.
Output one integer, representing the answer. You need to output the answer modulo 998244353.
2
1 4
2 3
24
见文件附件的 sum2.in
见文件附件的 sum2.ans
Hint
Sample Explanation
Take s={1,2}, i=1maxnsi=2.
Take s={2,2}, i=1maxnsi=2.
Take s={3,2}, i=1maxnsi=3.
Take s={4,2}, i=1maxnsi=4.
Take s={1,3}, i=1maxnsi=3.
Take s={2,3}, i=1maxnsi=3.
Take s={3,3}, i=1maxnsi=3.
Take s={4,3}, i=1maxnsi=4.
2+2+3+4+3+3+3+4=24.
Constraints
For 30% of the testdata, it is guaranteed that n≤8, and pi,qi≤10.
For 100% of the testdata, it is guaranteed that 1≤n≤5×103, 1≤pi≤qi≤5×103. Some intervals may be identical.
Translated by ChatGPT 5