CF BUDDY
← Problems·

1954D · Colored Balls

1800 · combinatorics, dp, math

Problem: There are balls of nn different colors; the number of balls of the ii-th color is aia_i.

The balls can be combined into groups. Each group should contain at most 22 balls, and no more than 11 ball of each color.

Consider all 2n2^n sets of colors. For a set of colors, let's denote its value as the minimum number of groups the balls of those colors can be distributed into. For example, if there are three colors with 33, 11 and 77 balls respectively, they can be combined into 77 groups (and not less than 77), so the value of that set of colors is 77.

Your task is to calculate the sum of values over all 2n2^n possible sets of colors. Since the answer may be too large, print it modulo 998244353998\,244\,353.

Input Format: The first line contains a single integer nn (1n50001 \le n \le 5000) — the number of colors.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai50001 \le a_i \le 5000) — the number of balls of the ii-th color.

Additional constraint on input: the total number of balls doesn't exceed 50005000.

Output Format: Print a single integer — the sum of values of all 2n2^n sets of colors, taken modulo 998244353998\,244\,353.

Note: Consider the first example. There are 88 sets of colors:

  • for the empty set, its value is 00;
  • for the set {1}\{1\}, its value is 11;
  • for the set {2}\{2\}, its value is 11;
  • for the set {3}\{3\}, its value is 22;
  • for the set {1,2}\{1,2\}, its value is 11;
  • for the set {1,3}\{1,3\}, its value is 22;
  • for the set {2,3}\{2,3\}, its value is 22;
  • for the set {1,2,3}\{1,2,3\}, its value is 22.

So, the sum of values over all 2n2^n sets of colors is 1111.

Sample Cases

Case 1

Input

3
1 1 2

Output

11

Case 2

Input

1
5

Output

5

Case 3

Input

4
1 3 3 7

Output

76

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