Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

The problem statement has recently been changed. View the changes.

×
G. Tiles

time limit per test

4 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputConsider a road consisting of several rows. Each row is divided into several rectangular tiles, and all tiles in the same row are equal. The first row contains exactly one rectangular tile. Look at the picture below which shows how the tiles are arranged.

The road is constructed as follows:

- the first row consists of $$$1$$$ tile;
- then $$$a_1$$$ rows follow; each of these rows contains $$$1$$$ tile greater than the previous row;
- then $$$b_1$$$ rows follow; each of these rows contains $$$1$$$ tile less than the previous row;
- then $$$a_2$$$ rows follow; each of these rows contains $$$1$$$ tile greater than the previous row;
- then $$$b_2$$$ rows follow; each of these rows contains $$$1$$$ tile less than the previous row;
- ...
- then $$$a_n$$$ rows follow; each of these rows contains $$$1$$$ tile greater than the previous row;
- then $$$b_n$$$ rows follow; each of these rows contains $$$1$$$ tile less than the previous row.

You start from the only tile in the first row and want to reach the last row (any tile of it). From your current tile, you can move to any tile in the next row which touches your current tile.

Calculate the number of different paths from the first row to the last row. Since it can be large, print it modulo $$$998244353$$$.

Input

The first line contains one integer $$$n$$$ ($$$1 \le n \le 1000$$$).

Then $$$n$$$ lines follow. The $$$i$$$-th of them contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \le a_i, b_i \le 10^5$$$; $$$|a_i - b_i| \le 5$$$).

Additional constraint on the input: the sequence of $$$a_i$$$ and $$$b_i$$$ never results in a row with non-positive number of tiles.

Output

Print one integer — the number of paths from the first row to the last row, taken modulo $$$998244353$$$.

Examples

Input

2 4 2 2 3

Output

850

Input

3 4 1 2 3 3 1

Output

10150

Input

8 328 323 867 868 715 718 721 722 439 435 868 870 834 834 797 796

Output

759099319

Codeforces (c) Copyright 2010-2022 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: May/23/2022 15:31:04 (h2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|