atcoder#TENKA12019D. Three Colors

Three Colors

Score : 600600 points

Problem Statement

You are given NN integers. The ii-th integer is aia_i. Find the number, modulo 998244353998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied:

  • Let RR, GG and BB be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths RR, GG and BB.

Constraints

  • 3N3003 \leq N \leq 300
  • 1ai300(1iN)1 \leq a_i \leq 300(1\leq i\leq N)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

a1a_1

::

aNa_N

Output

Print the number, modulo 998244353998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied.

4
1
1
1
2
18

We can only paint the integers so that the lengths of the sides of the triangle will be 11, 22 and 22, and there are 1818 such ways.

6
1
3
2
3
5
2
150
20
3
1
4
1
5
9
2
6
5
3
5
8
9
7
9
3
2
3
8
4
563038556