Under construction

Still being built. Things may change

Somewhere Over the Rainbow

Time limit2sMemory limit512 MB

Summary
Given lower bounds a_x at n points, find the minimum sum of a strictly convex integer sequence with a_0 = a_m = 0, modulo 998244353.
Level

Hard9 of 10

Topics
Dynamic programming, Math, Greedy
Solved
No attempts yet

Problem

Time limit: 2000 ms. Memory limit: 512 MB.

You want to draw a rainbow. The rainbow can be represented as a sequence of integer heights a0,a1,…,ama_0, a_1, \ldots, a_m that must satisfy the following constraints:

  • a0=am=0a_0 = a_m = 0 (both endpoints are 0 meters above the horizon)
  • 2ai>ai−1+ai+12a_i > a_{i-1} + a_{i+1} for all 0<i<m0 < i < m (the rainbow is convex)
  • axi≥yia_{x_i} \ge y_i for nn given pairs (xi,yi)(x_i, y_i).

You also want the rainbow to take as little space as possible. Find the minimum possible value of ∑ai\sum a_i. Since the answer may be very large, output it modulo 998244353.

Input

The first line contains two positive integers nn and mm (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, 1≤m≤1091 \le m \le 10^9): the number of constraints and the length of the sequence.

Each of the next nn lines contains two integers xix_i (1≤xi≤m−11 \le x_i \le m - 1) and yiy_i (1≤yi≤10181 \le y_i \le 10^{18}), which set the condition axi≥yia_{x_i} \ge y_i.

It is guaranteed that x1<x2<…<xnx_1 < x_2 < \ldots < x_n.

Output

Print one integer: the minimum value of ∑ai\sum a_i modulo 998244353.

Hint

In the sample case, one optimal height sequence is (0,100,82,63,43,22,0)(0, 100, 82, 63, 43, 22, 0).

Examples1

  1. Example 1

    Input
    3 6
    1 100
    4 42
    5 22
    
    Expected output
    310