N = int(eval(input()))

A = [int(eval(input())) for _ in range(N)]



sum_A = sum(A)

MOD = 998244353



dp1 = [0] * (sum_A + 1)

dp2 = [0] * (sum_A + 1)

dp1[0] = dp2[0] = 1





for a in A:

    dp1_ = [0] * (sum_A + 1)

    dp2_ = [0] * (sum_A + 1)

    for i in range(sum_A + 1):

        if i - a >= 0:

            # R に塗れる場合

            dp1_[i] = (dp1[i - a] + dp1[i] * 2) % MOD

            dp2_[i] = (dp2[i - a] + dp2[i]) % MOD

        else:

            dp1_[i] = (dp1[i] * 2) % MOD

            dp2_[i] = dp2[i]

    dp1, dp2 = dp1_, dp2_





ans = pow(3, N, MOD)

for i in range(sum_A + 1):

    if i * 2 >= sum_A:

        ans = (ans - dp1[i] * 3 + MOD * 3) % MOD

    if i * 2 == sum_A:

        ans = (ans + dp2[i] * 3) % MOD

print(ans)

N = int(eval(input()))

A = [int(eval(input())) for _ in range(N)]



sum_A = sum(A)

MOD = 998244353



dp1 = [0] * (sum_A + 1)

dp2 = [0] * (sum_A + 1)

dp1[0] = dp2[0] = 1





for a in A:

    for i in reversed(list(range(sum_A + 1))):

        if i - a >= 0:

            # R に塗れる場合

            dp1[i] = (dp1[i - a] + dp1[i] * 2) % MOD

            dp2[i] = (dp2[i - a] + dp2[i]) % MOD

        else:

            dp1[i] = (dp1[i] * 2) % MOD

            dp2[i] = dp2[i]





ans = pow(3, N, MOD)

for i in range(sum_A + 1):

    if i * 2 >= sum_A:

        ans = (ans - dp1[i] * 3 + MOD * 3) % MOD

    if i * 2 == sum_A:

        ans = (ans + dp2[i] * 3) % MOD

print(ans)

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
sum_A = sum(A)
MOD = 998244353
dp1 = [0] * (sum_A + 1)
dp2 = [0] * (sum_A + 1)
dp1[0] = dp2[0] = 1
for a in A:
    dp1_ = [0] * (sum_A + 1)
    dp2_ = [0] * (sum_A + 1)
    for i in range(sum_A + 1):
        if i - a >= 0:
            # R に塗れる場合
            dp1_[i] = (dp1[i - a] + dp1[i] * 2) % MOD
            dp2_[i] = (dp2[i - a] + dp2[i]) % MOD
        else:
            dp1_[i] = (dp1[i] * 2) % MOD
            dp2_[i] = dp2[i]
    dp1, dp2 = dp1_, dp2_
ans = pow(3, N, MOD)
for i in range(sum_A + 1):
    if i * 2 >= sum_A:
        ans = (ans - dp1[i] * 3 + MOD * 3) % MOD
    if i * 2 == sum_A:
        ans = (ans + dp2[i] * 3) % MOD
print(ans)

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
sum_A = sum(A)
MOD = 998244353
dp1 = [0] * (sum_A + 1)
dp2 = [0] * (sum_A + 1)
dp1[0] = dp2[0] = 1
for a in A:
    for i in reversed(list(range(sum_A + 1))):
        if i - a >= 0:
            # R に塗れる場合
            dp1[i] = (dp1[i - a] + dp1[i] * 2) % MOD
            dp2[i] = (dp2[i - a] + dp2[i]) % MOD
        else:
            dp1[i] = (dp1[i] * 2) % MOD
            dp2[i] = dp2[i]
ans = pow(3, N, MOD)
for i in range(sum_A + 1):
    if i * 2 >= sum_A:
        ans = (ans - dp1[i] * 3 + MOD * 3) % MOD
    if i * 2 == sum_A:
        ans = (ans + dp2[i] * 3) % MOD
print(ans)

-    dp1_ = [0] * (sum_A + 1) -    dp2_ = [0] * (sum_A + 1) -    for i in range(sum_A + 1): +    for i in reversed(list(range(sum_A + 1))): -            dp1_[i] = (dp1[i - a] + dp1[i] * 2) % MOD -            dp2_[i] = (dp2[i - a] + dp2[i]) % MOD +            dp1[i] = (dp1[i - a] + dp1[i] * 2) % MOD +            dp2[i] = (dp2[i - a] + dp2[i]) % MOD -            dp1_[i] = (dp1[i] * 2) % MOD -            dp2_[i] = dp2[i] -    dp1, dp2 = dp1_, dp2_ +            dp1[i] = (dp1[i] * 2) % MOD +            dp2[i] = dp2[i]