CF BUDDY
← Problems·

1783D · Different Arrays

2000 · brute force, dp, implementation

Problem: You are given an array aa consisting of nn integers.

You have to perform the sequence of n2n-2 operations on this array:

  • during the first operation, you either add a2a_2 to a1a_1 and subtract a2a_2 from a3a_3, or add a2a_2 to a3a_3 and subtract a2a_2 from a1a_1;
  • during the second operation, you either add a3a_3 to a2a_2 and subtract a3a_3 from a4a_4, or add a3a_3 to a4a_4 and subtract a3a_3 from a2a_2;
  • ...
  • during the last operation, you either add an1a_{n-1} to an2a_{n-2} and subtract an1a_{n-1} from ana_n, or add an1a_{n-1} to ana_n and subtract an1a_{n-1} from an2a_{n-2}.

So, during the ii-th operation, you add the value of ai+1a_{i+1} to one of its neighbors, and subtract it from the other neighbor.

For example, if you have the array [1,2,3,4,5][1, 2, 3, 4, 5], one of the possible sequences of operations is:

  • subtract 22 from a3a_3 and add it to a1a_1, so the array becomes [3,2,1,4,5][3, 2, 1, 4, 5];
  • subtract 11 from a2a_2 and add it to a4a_4, so the array becomes [3,1,1,5,5][3, 1, 1, 5, 5];
  • subtract 55 from a3a_3 and add it to a5a_5, so the array becomes [3,1,4,5,10][3, 1, -4, 5, 10].

So, the resulting array is [3,1,4,5,10][3, 1, -4, 5, 10].

An array is reachable if it can be obtained by performing the aforementioned sequence of operations on aa. You have to calculate the number of reachable arrays, and print it modulo 998244353998244353.

Input Format: The first line contains one integer nn (3n3003 \le n \le 300).

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (0ai3000 \le a_i \le 300).

Output Format: Print one integer — the number of reachable arrays. Since the answer can be very large, print its remainder modulo 998244353998244353.

Sample Cases

Case 1

Input

4
1 1 1 1

Output

3

Case 2

Input

5
1 2 3 5 0

Output

7

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback