H. The Sabrosso Cleaner
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Pache is in a bad mood and ordered Dilon, el Sabrosso, to clean the training area. The area is a straight hallway, which we see as a number line. Dilon starts sweeping at position $$$0$$$ and moves to the right at a constant speed of one unit per second.

Pache watches $$$N$$$ points of the hallway. Point $$$i$$$ is at position $$$x_i$$$. At each point, Pache is angry or calm: at the beginning he is angry if $$$s_i = 1$$$ and calm if $$$s_i = 0$$$.

Dilon starts at position $$$0$$$ and walks to the right. Every time he reaches a point, Pache's mood at that point decides what happens, and then that mood changes:

  • If Pache is angry, with his powers he instantly teleports Dilon to position $$$0$$$, and Dilon walks to the right again from there. Then Pache becomes calm at that point.
  • If Pache is calm, Dilon keeps walking and Pache becomes angry at that point.

Dilon finishes cleaning when he reaches position $$$x_N + 1$$$. How many seconds does it take him to get there? Since the answer can be huge, print it modulo $$$998\,244\,353$$$.

It can be shown that Dilon always finishes.

Input

The first line contains an integer $$$N$$$, the number of points.

Each of the following $$$N$$$ lines contains two integers $$$x_i$$$ and $$$s_i$$$: the position of point $$$i$$$ and Pache's initial mood at that point.

Constraints

  • $$$1 \le N \le 2 \cdot 10^5$$$
  • $$$1 \le x_1 \lt x_2 \lt \dots \lt x_N \le 10^9$$$
  • $$$s_i \in \{0, 1\}$$$
Output

Print one integer: the time, in seconds, it takes Dilon to reach position $$$x_N + 1$$$, modulo $$$998\,244\,353$$$.

Examples
Input
4
3 0
6 1
7 0
8 1
Output
57
Input
3
2 0
5 0
9 0
Output
10
Note

Example 1. In the first example, Dilon passes $$$3$$$ at second $$$3$$$ (Pache becomes angry there) and reaches $$$6$$$ at second $$$6$$$, where Pache is angry and sends him back to $$$0$$$. At second $$$9$$$ he reaches $$$3$$$ again, where Pache is now angry, and goes back to $$$0$$$. Then he passes $$$3$$$ (second $$$12$$$), $$$6$$$ (second $$$15$$$) and $$$7$$$ (second $$$16$$$), leaving Pache angry at all three, and at second $$$17$$$ point $$$8$$$ sends him back to $$$0$$$. From there he still has seven more rounds before finally reaching position $$$9$$$ at second $$$57$$$.

Example 2. In the second example Pache starts calm at every point, so Dilon never starts over and reaches position $$$10$$$ at second $$$10$$$.