Under construction

Still being built. Things may change

Expected Beauty

Time limit1sMemory limit2048 MB

Summary
Each A_i is uniform in [L_i, R_i]. Find the expected maximum score squared when deleting one of two adjacent equal elements adds its value to the score, mod 998244353.
Level

Hard9 of 10

Topics
Dynamic programming, Probability, Math
Solved
No attempts yet

Problem

Morgan the robot has an array AA of size NN, indexed from 11 to NN. The value of each element is random: AiA_i can be any integer from LiL_i to RiR_i (inclusive), each with equal probability.

Morgan defines the beauty of AA as follows. Morgan has a variable score that starts at 00. An operation on an array aa is:

  • Choose an index ii with 1≤i<∣a∣1 \le i < |a| and ai=ai+1a_i = a_{i+1}. If no such ii exists, the operation cannot be performed.
  • Add the value of aia_i to score and remove aia_i from the array.
  • The remaining elements are joined together, keeping their order.

The beauty of AA is the maximum value of score2^2 that Morgan can get after performing zero or more operations on AA.

Because the array is random, Morgan wants the expected beauty of AA. Morgan's algorithm is too slow, so Morgan asks for help computing the expected value.

Input

The first line contains an integer NN (1≤N≤2000001 \le N \le 200000). Each of the next NN lines contains two integers LiL_i and RiR_i (1≤Li≤Ri≤1081 \le L_i \le R_i \le 10^8).

Output

Let M=998244353M = 998244353. The expected value can be written as an irreducible fraction p/qp/q, where q≢0(modM)q \not\equiv 0 \pmod M. Print one integer xx on a single line such that 0≤x<M0 \le x < M and x⋅q≡p(modM)x \cdot q \equiv p \pmod M.

Examples3

  1. Example 1

    Input
    3
    1 2
    2 3
    1 3
    
    Expected output
    831870298
    
  2. Example 2

    Input
    4
    1 1
    1 1
    2 2
    2 2
    
    Expected output
    9
    
  3. Example 3

    Input
    3
    1 2
    3 4
    5 6
    
    Expected output
    0