#P9773. [HUSTFC 2023] 序列配对

[HUSTFC 2023] 序列配对

Problem Description

You have a sequence of length nn: a1,a2,,ana_1,a_2,\dots,a_n. Initially, every element in the sequence satisfies ai=0a_i=0.

Then you are given nn pairs of indices. Each pair is an integer pair (l,r)(l,r), meaning that ala_l and ara_r are paired. After each pairing, you must perform exactly one of the following two operations (you cannot do both):

  • Increase ala_l by 11, then decrease ara_r by 11.
  • Increase ara_r by 11, then decrease ala_l by 11.

You are also told that these pairings follow a special rule: among the 2n2n integers appearing in the nn pairs, each index of the sequence appears exactly 22 times.

You want to know, among all possible choices of operations, how many result in i=1nai2=k\sum_{i=1}^n a_i^2 = k. Since the answer may be very large, output it modulo 998244353998\,244\,353.

Input Format

The first line contains an integer n (1n2105)n\ (1\le n\le 2\cdot 10^5), the length of the sequence.

The next nn lines each contain two integers li,ri (1lrn)l_i,r_i\ (1\le l\le r \le n), describing the ii-th pairing. It is guaranteed that these 2n2n integers satisfy the requirement in the statement.

The last line contains an integer k (0k109)k\ (0\le k \le 10^9), with the meaning as described above.

Output Format

Output one integer: the number of operation plans such that i=1nai2=k\sum_{i=1}^n a_i^2=k, modulo 998244353998\,244\,353.

3
1 3
2 3
1 2
0
2

6
2 5
3 6
2 5
4 6
1 3
1 4
8
28

Hint

Translated by ChatGPT 5