#P15554. [CCPC 2025 哈尔滨站] Many Many Sequence Covering Problems

[CCPC 2025 哈尔滨站] Many Many Sequence Covering Problems

Problem Description

Consider the following two problems:

Sequence Covering Problems\textbf{Sequence Covering Problems}:

In this problem, you are given three non-negative integer sequences a,b,ca, b, c of length nn at the beginning. Each time, you may choose an interval [l,r][l, r] with cost bl+crb_l + c_r, such that the minimum of al,al+1,,ara_l, a_{l+1}, \cdots, a_r is not 00, and then decrease all of al,al+1,,ara_l, a_{l+1}, \cdots, a_r by 11. The goal is to make all numbers in aa become 00 with the minimum total cost.

Many Sequence Covering Problems\textbf{Many Sequence Covering Problems}:

Based on Sequence Covering Problems, you are additionally given two non-negative integer sequences d,ed, e. Now you may perform the following operations any number of times: choose i[1,n]i \in [1, n], pay cost did_i to increase bib_i by 11, or pay cost eie_i to increase cic_i by 11. After all operations are finished, solve the Sequence Covering Problems for the modified sequences b,cb, c. Let the answer of that problem be PP, and let the total cost spent on the operations be QQ. You need to maximize PQP - Q. If this value can be unbounded (infinite), output INF\texttt{INF}. Otherwise, output this maximum value.

Now you need to solve Many Many Sequence Covering Problems\textbf{Many Many Sequence Covering Problems}:

You are given five incomplete sequences A,B,C,D,EA, B, C, D, E of length nn. It is defined that if Ai0A_i \ge 0, then the value of AiA_i is fixed as given; otherwise, the value of AiA_i can be any integer in [0,Ai][0, -A_i]. The same rule applies to sequences B,C,D,EB, C, D, E.

You need to compute, over all possible completions, the sum of the corresponding answers of Many Sequence Covering Problems. Since the answer may be INF\texttt{INF}, you need to output separately: the sum of all answers (modulo 998244353998244353) over the cases where the answer is not INF\texttt{INF}, and the number of cases whose answer is INF\texttt{INF}. Since the results may be large, take all outputs modulo 998244353998244353.

Input Format

The first line contains an integer nn (1n50001 \le n \le 5000), indicating the length of the sequences.

The second line contains nn integers A1,A2,,AnA_1, A_2, \ldots, A_n (0Ai50000 \le |A_i| \le 5000).

The third line contains nn integers B1,B2,,BnB_1, B_2, \ldots, B_n (0Bi50000 \le |B_i| \le 5000).

The fourth line contains nn integers C1,C2,,CnC_1, C_2, \ldots, C_n (0Ci50000 \le |C_i| \le 5000).

The fifth line contains nn integers D1,D2,,DnD_1, D_2, \ldots, D_n (0Di50000 \le |D_i| \le 5000).

The sixth line contains nn integers E1,E2,,EnE_1, E_2, \ldots, E_n (0Ei50000 \le |E_i| \le 5000).

Output Format

Output a single line containing two integers: the sum of all answers (modulo 998244353998244353) over the cases where the answer is not INF\texttt{INF}, and the number of cases where the answer is INF\texttt{INF} (modulo 998244353998244353).

2
1 1
1 2
2 1
-1 -1
-1 -1
8 12
3
-1 -2 2
1 3 0
-3 0 -2
1 -3 0
1 3 3
408 228

Hint

Translated by ChatGPT 5