| SanSi Cup 2026 Qualification round |
|---|
| Finished |
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:
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.
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
Print one integer: the time, in seconds, it takes Dilon to reach position $$$x_N + 1$$$, modulo $$$998\,244\,353$$$.
4 3 0 6 1 7 0 8 1
57
3 2 0 5 0 9 0
10
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$$$.
| Name |
|---|


