Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

n = int(input())
a = [int(input()) for _ in range(n)]
modulo = 998244353

a.sort(reverse=True)
sol = 3 ** n % modulo
s = sum(a)
half_s = s / 2


dp = [Counter([0])]
for i, ai in enumerate(a):
    dp.append(dp[i] + dp[i])
    for key, item in dp[-2].items():
        dp[-1][key + ai] += dp[-2][key]
        # if dp[-1][key + ai] > modulo:
        #    dp[-1][key + ai] -= modulo

sol -= 3 * sum(item for key, item in dp[-1].items() if key >= half_s)

if s % 2 == 0:
    dp = [Counter([0])]
    for i, ai in enumerate(a):
        dp.append(dp[-1].copy())
        for key, item in dp[-2].items():
            new_key = key + ai
            if new_key <= int(half_s):
                dp[-1][new_key] += dp[-2][key]
                # if dp[-1][new_key] > modulo:
                #    dp[-1][new_key] -= modulo

    sol += 3 * dp[-1][half_s]
sol %= modulo

print(sol)
# print(dp[-1])


Fixed submission:
import numpy as np
from math import ceil

n = int(input())
a = [int(input()) for _ in range(n)]
modulo = 998244353

s = sum(a)

dp = np.zeros(s + 1, dtype=np.int)
dp[0] = 1
for ai in a:
    dp[ai:] = 2 * dp[ai:] + dp[:-ai]
    dp[:ai] = 2 * dp[:ai]
    dp %= modulo
sol = 3 ** n % modulo
sol -= 3 * dp[ceil(s / 2) :].sum()


if s % 2 == 0:
    dp = np.zeros(s + 1, dtype=np.int)
    dp[0] = 1
    for ai in a:
        dp[ai:] = dp[ai:] + dp[:-ai]
        dp %= modulo

    sol += 3 * dp[s // 2]

sol %= modulo

print(sol)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for _ in range(n)]
modulo = 998244353

a.sort(reverse=True)
sol = 3 ** n % modulo
s = sum(a)
half_s = s / 2

from collections import Counter
dp = [Counter([0])]
for i, ai in enumerate(a):
    dp.append(dp[i] + dp[i])
    for key, item in dp[-2].items():
        dp[-1][key + ai] += dp[-2][key]
        if dp[-1][key + ai] > modulo:
            dp[-1][key + ai]-=modulo

sol -= 3 * sum(item for key, item in dp[-1].items() if key >= half_s)

if s % 2 == 0:
    dp = [Counter([0])]
    for i, ai in enumerate(a):
        dp.append(dp[-1].copy())
        for key, item in dp[-2].items():
            new_key = key + ai
            if new_key <= int(half_s):
                dp[-1][new_key] += dp[-2][key]
                if dp[-1][new_key] > modulo:
                    dp[-1][new_key] -= modulo

    sol += 3 * dp[-1][half_s]
sol %= modulo

print(sol)

Fixed submission:
import numpy as np
from math import ceil

n = int(input())
a = [int(input()) for _ in range(n)]
modulo = 998244353

s = sum(a)

dp = np.zeros(s + 1, dtype=np.int)
dp[0] = 1
for ai in a:
    dp[ai:] = 2 * dp[ai:] + dp[:-ai]
    dp[:ai] = 2 * dp[:ai]
    dp %= modulo
sol = 3 ** n % modulo
sol -= 3 * dp[ceil(s / 2) :].sum()


if s % 2 == 0:
    dp = np.zeros(s + 1, dtype=np.int)
    dp[0] = 1
    for ai in a:
        dp[ai:] = dp[ai:] + dp[:-ai]
        dp %= modulo

    sol += 3 * dp[s // 2]

sol %= modulo

print(sol)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for _ in range(n)]
modulo = 998244353

sol = 3 ** n % modulo
s = sum(a)

from collections import Counter
dp = [Counter([0])]
for i, ai in enumerate(a):
    dp.append(dp[i] + dp[i])
    for key, item in dp[-2].items():
        dp[-1][key + ai] += dp[-2][key]


for key, item in dp[-1].items():
    if key >= s / 2:
        sol -= 3 * item

sol %= modulo

if s % 2 == 0:
    dp = [Counter([0])]
    for i, ai in enumerate(a):
        dp.append(dp[i].copy())
        for key, item in dp[-2].items():
            dp[-1][key + ai] += dp[-2][key]

    sol += 3*dp[-1][s //2]
    sol %= modulo

print(sol)

Fixed submission:
import numpy as np
from math import ceil

n = int(input())
a = [int(input()) for _ in range(n)]
modulo = 998244353

s = sum(a)

dp = np.zeros(s + 1, dtype=np.int)
dp[0] = 1
for ai in a:
    dp[ai:] = 2 * dp[ai:] + dp[:-ai]
    dp[:ai] = 2 * dp[:ai]
    dp %= modulo
sol = 3 ** n % modulo
sol -= 3 * dp[ceil(s / 2) :].sum()


if s % 2 == 0:
    dp = np.zeros(s + 1, dtype=np.int)
    dp[0] = 1
    for ai in a:
        dp[ai:] = dp[ai:] + dp[:-ai]
        dp %= modulo

    sol += 3 * dp[s // 2]

sol %= modulo

print(sol)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for _ in range(n)]
modulo = 998244353

s = sum(a)

dp = [[0] * (s + 1) for _ in range(n + 1)]
dp[0][0] = 1

cumsum = 0
for i in range(n):
    cumsum += a[i]
    for j in range(cumsum + 1):
        dp[i + 1][j] = dp[i][j] * 2
        if j - a[i] >= 0:
            dp[i + 1][j] += dp[i][j - a[i]]

        if dp[i + 1][j] > modulo:
            dp[i + 1][j] -= modulo
sol = 3 ** n - 3 * sum(dp[-1][int((s + 1) / 2) :])


if s % 2 == 0:
    dp = [[0] * (s + 1) for _ in range(n + 1)]
    dp[0][0] = 1
    cumsum = 0
    for i in range(n):
        cumsum += a[i]
        for j in range(cumsum + 1):
            dp[i + 1][j] = dp[i][j]
            if j - a[i] >= 0:
                dp[i + 1][j] += dp[i][j - a[i]]

            if dp[i + 1][j] > modulo:
                dp[i + 1][j] -= modulo

    sol += 3 * dp[-1][s // 2]
sol %= modulo

print(sol)



Fixed submission:
import numpy as np
from math import ceil

n = int(input())
a = [int(input()) for _ in range(n)]
modulo = 998244353

s = sum(a)

dp = np.zeros(s + 1, dtype=np.int)
dp[0] = 1
for ai in a:
    dp[ai:] = 2 * dp[ai:] + dp[:-ai]
    dp[:ai] = 2 * dp[:ai]
    dp %= modulo
sol = 3 ** n % modulo
sol -= 3 * dp[ceil(s / 2) :].sum()


if s % 2 == 0:
    dp = np.zeros(s + 1, dtype=np.int)
    dp[0] = 1
    for ai in a:
        dp[ai:] = dp[ai:] + dp[:-ai]
        dp %= modulo

    sol += 3 * dp[s // 2]

sol %= modulo

print(sol)

Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil

n = int(input())
a = [int(input()) for _ in range(n)]
s = sum(a)
modulo = 998244353

dp = [[0] * (s + 1) for _ in range(n + 1)]
dp[0][0] = 1

for i in range(n):
    for j in range(s + 1):
        dp[i + 1][j] = dp[i][j] * 2
        if j - a[i] >= 0:
            dp[i + 1][j] += dp[i][j - a[i]]

        if dp[i + 1][j] > modulo:
            dp[i + 1][j] -= modulo
sol = 3 ** n - 3 * sum(dp[-1][int((s + 1) / 2) :])


if s % 2 == 0:
    dp = [[0] * (s + 1) for _ in range(n + 1)]
    dp[0][0] = 1

    for i in range(n):
        for j in range(s + 1):
            dp[i + 1][j] = dp[i][j]
            if j - a[i] >= 0:
                dp[i + 1][j] += dp[i][j - a[i]]

            if dp[i + 1][j] > modulo:
                dp[i + 1][j] -= modulo

    sol += 3 * dp[-1][s // 2]
sol %= modulo

print(sol)



Fixed submission:
import numpy as np
from math import ceil

n = int(input())
a = [int(input()) for _ in range(n)]
modulo = 998244353

s = sum(a)

dp = np.zeros(s + 1, dtype=np.int)
dp[0] = 1
for ai in a:
    dp[ai:] = 2 * dp[ai:] + dp[:-ai]
    dp[:ai] = 2 * dp[:ai]
    dp %= modulo
sol = 3 ** n % modulo
sol -= 3 * dp[ceil(s / 2) :].sum()


if s % 2 == 0:
    dp = np.zeros(s + 1, dtype=np.int)
    dp[0] = 1
    for ai in a:
        dp[ai:] = dp[ai:] + dp[:-ai]
        dp %= modulo

    sol += 3 * dp[s // 2]

sol %= modulo

print(sol)