CF1473G.Tiles

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Consider 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 11 tile;
  • then a1a_1 rows follow; each of these rows contains 11 tile greater than the previous row;
  • then b1b_1 rows follow; each of these rows contains 11 tile less than the previous row;
  • then a2a_2 rows follow; each of these rows contains 11 tile greater than the previous row;
  • then b2b_2 rows follow; each of these rows contains 11 tile less than the previous row;
  • ...
  • then ana_n rows follow; each of these rows contains 11 tile greater than the previous row;
  • then bnb_n rows follow; each of these rows contains 11 tile less than the previous row.

An example of the road with n=2n = 2 , a1=4a_1 = 4 , b1=2b_1 = 2 , a2=2a_2 = 2 , b2=3b_2 = 3 . Rows are arranged from left to right. 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 998244353998244353 .

输入格式

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

Then nn lines follow. The ii -th of them contains two integers aia_i and bib_i ( 1ai,bi1051 \le a_i, b_i \le 10^5 ; aibi5|a_i - b_i| \le 5 ).

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

输出格式

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

输入输出样例

  • 输入#1

    2
    4 2
    2 3

    输出#1

    850
  • 输入#2

    3
    4 1
    2 3
    3 1

    输出#2

    10150
  • 输入#3

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

    输出#3

    759099319
首页